def test_cache_ignore(self, *args): self.assertEqual( utils.getattr_from_file(self.fname, 'c'), 47, ) utils.get_file_contents.return_value = "c = 48" self.assertEqual( utils.getattr_from_file(self.fname, 'c', cache=False), 48, ) self.assertEqual(utils.get_file_contents.call_count, 2)
def test_import(self): with open(join(self.tmpdir, self.fname), 'w') as f: f.write("c = 47") self.assertEqual( utils.getattr_from_file(self.fname, 'c', cache=False), 47, ) return with open(join(self.tmpdir, self.fname), 'w') as f: f.write("c = 48") self.assertEqual( utils.getattr_from_file(self.fname, 'c'), 48)
def test_default(self): with open(join(self.tmpdir, self.fname), 'w') as f: f.write("") with self.assertRaises(KeyError): utils.getattr_from_file(self.fname, 'c') self.assertEqual( utils.getattr_from_file(self.fname, 'c', default=None), None, ) self.assertEqual( utils.getattr_from_file(self.fname, 'c', default=49), 49, )
def test_cache_disabled(self, *args): utils.getattr_from_file(self.fname, 'c', cache=False) utils.getattr_from_file(self.fname, 'c') self.assertEqual(utils.get_file_contents.call_count, 2)
def test_cache_enabled(self, *args): utils.getattr_from_file(self.fname, 'c') utils.getattr_from_file(self.fname, 'c') utils.get_file_contents.assert_called_once_with(self.fname)