def test_parse_malformed(self): for json_repr in ( 123, 'bogus', (1, 2, 3), {}, {'steps': (1, 2, 3)}, {'steps': (('InvalidAction', 'path'),)}, {'steps': (('CreateDirectory', 'path', 'path2'),)}, ): with self.subTest(json_repr=json_repr): with self.assertRaises(ValueError): RenamePlan.from_json_representation(json_repr)
def test_parse_basic(self): reconstructed_plan = RenamePlan.from_json_representation(self.RENAME_PLAN_EXAMPLE.json_representation()) self.assertEqual( reconstructed_plan.test_repr(), ( ('CreateDirectory', '/base/dest_dir'), ('MoveFile', '/base/src_dir/file1', '/base/dest_dir/file2'), ('DeleteEmptyDirectory', '/base/src_dir'), ) )
def test_parse_empty(self): reconstructed_plan = RenamePlan.from_json_representation({ 'steps': [], }) self.assertEqual(reconstructed_plan.test_repr(), ())
def _test_load_plan(self, path): return RenamePlan.load_from_file(self.resolve_test_path(path))
def load_rename_plan_backup(): try: return RenamePlan.load_from_file(get_rename_plan_backup_filename()) except Exception: raise CannotLoadRenamePlanBackupError() from None