def test_pickling_db(self): cube = Cube(plateifu=self.plateifu) self.assertEqual(cube.data_origin, 'db') with self.assertRaises(MarvinError) as ee: cube.save() self.assertIn('objects with data_origin=\'db\' cannot be saved.', str(ee.exception))
def test_pickling_db(self, galaxy, temp_scratch): cube = Cube(plateifu=galaxy.plateifu) assert cube.data_origin == 'db' file = temp_scratch.join('test_cube_db.mpf') with pytest.raises(MarvinError) as cm: cube.save(str(file)) assert 'objects with data_origin=\'db\' cannot be saved.' in str( cm.value)
def test_pickling_api(self, temp_scratch, galaxy): cube = Cube(plateifu=galaxy.plateifu, mode='remote') assert cube.data_origin == 'api' assert isinstance(cube, Cube) assert cube.data is None test_path = temp_scratch.join('test_cube_api.mpf') cube.save(str(test_path)) assert test_path.check() is True cube = None assert cube is None cube_restored = Cube.restore(str(test_path)) assert cube_restored.data_origin == 'api' assert isinstance(cube_restored, Cube) assert cube_restored.data is None
def test_pickling_file(self, temp_scratch, galaxy): cube = Cube(filename=galaxy.cubepath) assert cube.data_origin == 'file' assert isinstance(cube, Cube) assert cube.data is not None assert not os.path.isfile(galaxy.cubepath[0:-7] + 'mpf') cube_file = temp_scratch.join('test_cube.mpf') cube.save(str(cube_file)) assert cube_file.check() is True assert cube.data is not None cube = None assert cube is None cube_restored = Cube.restore(str(cube_file)) assert cube_restored.data_origin == 'file' assert isinstance(cube_restored, Cube) assert cube_restored.data is not None
def test_pickling_file_custom_path(self): cube = Cube(filename=self.filename) test_path = '~/test.mpf' path = cube.save(path=test_path) self._files_created.append(path) self.assertTrue(os.path.exists(path)) self.assertEqual(path, os.path.realpath(os.path.expanduser(test_path))) cube_restored = Cube.restore(path, delete=True) self.assertEqual(cube_restored.data_origin, 'file') self.assertIsInstance(cube_restored, Cube) self.assertIsNotNone(cube_restored.data) self.assertFalse(os.path.exists(path))
def test_pickling_file_custom_path(self, temp_scratch, galaxy): cube = Cube(filename=galaxy.cubepath) assert cube.data_origin == 'file' assert isinstance(cube, Cube) assert cube.data is not None test_path = temp_scratch.join('cubepickle').join('test_cube.mpf') assert test_path.check(file=1) is False path = cube.save(path=str(test_path)) assert test_path.check(file=1) is True assert path == os.path.realpath(os.path.expanduser(str(test_path))) cube_restored = Cube.restore(str(test_path), delete=True) assert cube_restored.data_origin == 'file' assert isinstance(cube_restored, Cube) assert cube_restored.data is not None assert not os.path.exists(path)
def test_pickling_api(self): cube = Cube(plateifu=self.plateifu, mode='remote') self.assertEqual(cube.data_origin, 'api') self.assertIsInstance(cube, Cube) self.assertIsNone(cube.data) path = cube.save() self._files_created.append(path) self.assertTrue(os.path.exists(path)) self.assertEqual(os.path.realpath(path), os.path.realpath(self.filename[0:-7] + 'mpf')) cube = None self.assertIsNone(cube) cube_restored = Cube.restore(path) self.assertEqual(cube_restored.data_origin, 'api') self.assertIsInstance(cube_restored, Cube) self.assertIsNone(cube_restored.data) self.assertEqual(cube_restored.header['VERSDRP3'], 'v1_5_0')
def test_pickling_file(self): cube = Cube(filename=self.filename) self.assertEqual(cube.data_origin, 'file') self.assertIsInstance(cube, Cube) self.assertIsNotNone(cube.data) path = cube.save() self._files_created.append(path) self.assertTrue(os.path.exists(path)) self.assertEqual(os.path.realpath(path), os.path.realpath(self.filename[0:-7] + 'mpf')) self.assertIsNotNone(cube.data) cube = None self.assertIsNone(cube) cube_restored = Cube.restore(path) self.assertEqual(cube_restored.data_origin, 'file') self.assertIsInstance(cube_restored, Cube) self.assertIsNotNone(cube_restored.data)