def test_create_all_invalid(self): with TemporaryDirectory() as root: hb_root = Path(root, 'hidebound') os.makedirs(hb_root) Spec001, Spec002, BadSpec = self.get_specifications() self.create_files(root) db = Database(root, hb_root, [Spec001, Spec002]) db.update() data = db.data data['asset_valid'] = False db.create() result = Path(hb_root, 'data') self.assertFalse(result.exists()) result = Path(hb_root, 'metadata', 'file') self.assertFalse(result.exists()) result = Path(hb_root, 'metadata', 'asset') self.assertFalse(result.exists())
def test_create_copy(self): with TemporaryDirectory() as root: hb_root = Path(root, 'hidebound') os.makedirs(hb_root) root = Path(root, 'projects').as_posix() os.makedirs(root) Spec001, Spec002, BadSpec = self.get_specifications() expected = self.create_files(root).filepath\ .apply(lambda x: x.as_posix()).tolist() expected = sorted(expected) db = Database(root, hb_root, [Spec001, Spec002], write_mode='copy') db.update() db.create() result = tools.directory_to_dataframe(root).filepath.tolist() result = sorted(result) self.assertEqual(result, expected)
def test_create_move(self): with TemporaryDirectory() as root: hb_root = Path(root, 'hidebound') os.makedirs(hb_root) root = Path(root, 'projects').as_posix() os.makedirs(root) self.create_files(root) Spec001, Spec002, BadSpec = self.get_specifications() db = Database(root, hb_root, [Spec001, Spec002], write_mode='move') db.update() data = db.data db.create() data = data[data.asset_valid] # assert that no valid asset files are found in their original result = data.filepath.apply( lambda x: os.path.exists(x)).unique().tolist() self.assertEqual(result, [False]) # ensure files are written result = Path(hb_root, 'data') result = tools.directory_to_dataframe(result) result = sorted(result.filename.tolist()) self.assertGreater(len(result), 0) expected = sorted(data.filename.tolist()) self.assertEqual(result, expected) # ensure file metadata is written result = len(os.listdir(Path(hb_root, 'metadata', 'file'))) self.assertGreater(result, 0) expected = data.filepath.nunique() self.assertEqual(result, expected) # ensure asset metadata is written result = len(os.listdir(Path(hb_root, 'metadata', 'asset'))) self.assertGreater(result, 0) expected = data.asset_path.nunique() self.assertEqual(result, expected)
def test_create(self): with TemporaryDirectory() as root: hb_root = Path(root, 'hidebound') os.makedirs(hb_root) Spec001, Spec002, BadSpec = self.get_specifications() self.create_files(root) db = Database(root, hb_root, [Spec001, Spec002]) # test data initiliazation error expected = 'Data not initialized. Please call update.' with self.assertRaisesRegexp(RuntimeError, expected): db.create() db.update() data = db.data db.create() data = data[data.asset_valid] # ensure files are written result = Path(hb_root, 'data') result = tools.directory_to_dataframe(result) result = sorted(result.filename.tolist()) self.assertGreater(len(result), 0) expected = sorted(data.filename.tolist()) self.assertEqual(result, expected) # ensure file metadata is written result = len(os.listdir(Path(hb_root, 'metadata', 'file'))) self.assertGreater(result, 0) expected = data.filepath.nunique() self.assertEqual(result, expected) # ensure asset metadata is written result = len(os.listdir(Path(hb_root, 'metadata', 'asset'))) self.assertGreater(result, 0) expected = data.asset_path.nunique() self.assertEqual(result, expected)