Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_config_port(self) -> None:
storage = DataStorage(self.test_dir + 'PynPoint_database.hdf5')
with pytest.raises(ValueError) as error:
ConfigPort('images', storage)
assert str(error.value) == 'The tag name of the central configuration should be ' \
'\'config\'.'
port = ConfigPort('config', None)
with pytest.warns(UserWarning) as warning:
check_error = port._check_error_cases()
assert len(warning) == 1
assert warning[0].message.args[0] == 'ConfigPort can not load data unless a database is ' \
'connected.'
def test_create_storage_with_wrong_location(self) -> None:
file_in = '/test/test.hdf5'
with pytest.raises(AssertionError):
DataStorage(file_in)
def setup(self) -> None:
self.limit = 1e-10
self.storage = DataStorage(os.path.dirname(__file__) + '/PynPoint_database.hdf5')
def test_open_close_connection(self) -> None:
storage = DataStorage(self.test_data)
storage.open_connection()
assert storage.m_open is True
storage.open_connection()
assert storage.m_open is True
storage.close_connection()
assert storage.m_open is False
storage.close_connection()
assert storage.m_open is False
os.remove(self.test_data)
def test_create_storage_without_existing_database(self) -> None:
storage = DataStorage(self.test_data)
storage.open_connection()
storage.m_data_bank['data'] = [0, 1, 2, 5, 7]
assert storage.m_data_bank['data'][2] == 2
assert list(storage.m_data_bank.keys()) == ['data', ]
storage.close_connection()
os.remove(self.test_data)
def test_create_storage_with_existing_database(self) -> None:
np.random.seed(1)
images = np.random.normal(loc=0, scale=2e-4, size=(10, 100, 100))
with h5py.File(self.test_data, 'w') as hdf_file:
hdf_file.create_dataset('images', data=images)
storage = DataStorage(self.test_data)
storage.open_connection()
data = storage.m_data_bank['images']
assert data[0, 0, 0] == pytest.approx(0.00032486907273264834, rel=self.limit, abs=0.)
assert np.mean(data) == pytest.approx(1.0506056979365338e-06, rel=self.limit, abs=0.)
os.remove(self.test_data)
def setup(self) -> None:
file_in = os.path.dirname(__file__) + '/PynPoint_database.hdf5'
self.storage = DataStorage(file_in)
def test_get_config_attribute(self) -> None:
create_config(self.test_dir+'PynPoint_config.ini')
Pypeline(self.test_dir, self.test_dir, self.test_dir)
storage = DataStorage(self.test_dir + 'PynPoint_database.hdf5')
port = ConfigPort('config', None)
with pytest.warns(UserWarning) as warning:
attribute = port.get_attribute('CPU')
assert len(warning) == 1
assert warning[0].message.args[0] == 'ConfigPort can not load data unless a database is ' \
'connected.'
assert attribute is None
port = ConfigPort('config', storage)
attribute = port.get_attribute('CPU')
assert attribute == 1
except URLError:
latest_version = None
if latest_version is not None and pynpoint.__version__ != latest_version:
print(f'A new version ({latest_version}) is available!\n')
print('Want to stay informed about updates, bug fixes, and new features?')
print('Please consider using the \'Watch\' button on the Github page:')
print('https://github.com/PynPoint/PynPoint\n')
self._m_working_place = working_place_in
self._m_input_place = input_place_in
self._m_output_place = output_place_in
self._m_modules = collections.OrderedDict()
self.m_data_storage = DataStorage(os.path.join(working_place_in, 'PynPoint_database.hdf5'))
print(f'Database: {self.m_data_storage._m_location}')
self._config_init()