Last active
December 11, 2015 23:58
-
-
Save goodwillcoding/4680679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --------------------------------------------------------------------------- # | |
class Foo(object): | |
# ....................................................................... # | |
def get_string(self): | |
return "hello" | |
# ....................................................................... # | |
def reverse_string(self, str_=self.get_string()): | |
return str_[::-1] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --------------------------------------------------------------------------- # | |
class Foo(object): | |
# ....................................................................... # | |
def get_string(self): | |
return "hello" | |
# ....................................................................... # | |
def reverse_string(self, str_=None): | |
if str_ is None: | |
str_ = self.get_string() | |
return str_[::-1] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --------------------------------------------------------------------------- # | |
class Foo(object): | |
# ....................................................................... # | |
def get_string(self): | |
return "hello" | |
# ....................................................................... # | |
@staticmethod | |
def reverse_string(self, str_): | |
return str_[::-1] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Sample Test Cases More Injections | |
""" | |
from unittest import TestCase | |
# --------------------------------------------------------------------------- # | |
class Foo(object): | |
# ....................................................................... # | |
def get_string(self): | |
return "hello" | |
# ....................................................................... # | |
def reverse_string(self): | |
str_ = self.get_string() | |
return str_[::-1] | |
# --------------------------------------------------------------------------- # | |
class TestFoo_get_string(TestCase): | |
# ....................................................................... # | |
def _callFUT(self, *args, **kwargs): | |
return Foo.get_string.im_func(*args, **kwargs) | |
# ....................................................................... # | |
def test_get_string(self): | |
dummy_self = object() | |
desired_output = 'hello' | |
self.assertEqual(self._callFUT(dummy_self), desired_output) | |
# --------------------------------------------------------------------------- # | |
class TestFoo_reverse_string(TestCase): | |
# ....................................................................... # | |
def _callFUT(self, *args, **kwargs): | |
return Foo.reverse_string.im_func(*args, **kwargs) | |
# ....................................................................... # | |
def test_reverse_string(self): | |
class DummySelf(object): | |
def get_string(self): | |
# this is "test_string" in reverse | |
return 'gnirts_tset' | |
dummy_self = DummySelf() | |
desired_output = 'test_string' | |
self.assertEqual(self._callFUT(dummy_self), desired_output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment