def test_replace_dict_remove_key(self): from sample1 import someDict @replace('testfixtures.tests.sample1.someDict.key',not_there) def test_something(obj): self.failIf('key' in someDict) test_something() self.assertEqual(someDict.keys(), ['complex_key','key'])
def test_replace_dict_remove_key_not_there_not_strict(self): from sample1 import someDict @replace("testfixtures.tests.sample1.someDict.badkey", not_there, strict=False) def test_something(obj): self.failIf("badkey" in someDict) test_something() self.assertEqual(someDict.keys(), ["complex_key", "key"])
def test_replace_dict_not_there_empty_string(self): from sample1 import someDict @replace("testfixtures.tests.sample1.someDict.key2", "", strict=False) def test_something(): self.assertEqual(someDict["key2"], "") test_something() self.assertEqual(someDict.keys(), ["complex_key", "key"])
def test_replace_dict_remove_key_not_there(self): from sample1 import someDict @replace("testfixtures.tests.sample1.someDict.badkey", not_there) def test_something(obj): self.failIf("badkey" in someDict) # pragma: no cover with ShouldRaise(AttributeError("Original 'badkey' not found")): test_something() self.assertEqual(someDict.keys(), ["complex_key", "key"])
def test_replace_dict_not_there(self): from sample1 import someDict replacement = object() @replace('testfixtures.tests.sample1.someDict.key2',replacement,strict=False) def test_something(obj): self.failUnless(obj is replacement) self.failUnless(someDict['key2'] is replacement) test_something() self.assertEqual(someDict.keys(), ['complex_key','key'])