Skip to content

Instantly share code, notes, and snippets.

@goodwillcoding
Created January 31, 2013 15:40
Show Gist options
  • Save goodwillcoding/4683782 to your computer and use it in GitHub Desktop.
Save goodwillcoding/4683782 to your computer and use it in GitHub Desktop.
# -*- 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