def test_restore_parse_fail(self): path = 'test_file' with open(path, 'w') as f: f.write('test contents') with mock.patch('json.loads') as l: l.side_effect = Exception('test error') with self.assertRaises(DownstreamError) as ex: restore(path) self.assertEqual( str(ex.exception), 'Couldn\'t parse \'{0}\': test error' .format(path)) os.remove(path)
def test_restore_parse_fail(self): path = 'test_file' with open(path, 'w') as f: f.write('test contents') with mock.patch('json.loads') as l: l.side_effect = Exception('test error') with self.assertRaises(DownstreamError) as ex: restore(path) self.assertEqual( str(ex.exception), 'Couldn\'t parse \'{0}\': test error'.format(path)) os.remove(path)
def test_save_restore_parity(self): d = {'key': 'value'} path = 'test_file' save(path, d) r = restore(path) self.assertEqual(d, r) os.remove(path)
def test_save_directory_creation(self): d = {'key': 'value'} dir = 'testdir' path = os.path.join(dir, 'file') save(path, d) self.assertTrue(os.path.isdir(dir)) self.assertTrue(os.path.exists(path)) r = restore(path) self.assertEqual(d, r) os.remove(path) os.rmdir(dir)
def test_restore_path_doesnt_exist(self): path = 'nonexistentpath' state = restore(path) self.assertEqual(state, dict())