def test_adsorbate_basic(self): """Basic creation tests.""" with pytest.raises(pygaps.ParameterError): ads = pygaps.Adsorbate() ads = pygaps.Adsorbate('Test') assert ads == 'Test' assert ads == 'test' assert repr(ads) == 'Test' assert str(ads) == 'Test' assert ads + '2' == 'Test2' assert 'i' + ads == 'iTest' assert hash(ads) == hash('Test')
def test_adsorbate_basic(self): """Basic creation tests.""" ads = pygaps.Adsorbate('Test') assert ads == 'Test' assert ads == 'test' ads = pygaps.Adsorbate('Test', alias=['test2']) assert ads == 'test2' assert repr(ads) == 'Test' assert str(ads) == 'Test' assert hash(ads) == hash('Test') assert ads + '2' == 'Test2' assert 'i' + ads == 'iTest'
def test_adsorbate_alias(self): """Aliasing tests.""" ads = pygaps.Adsorbate(name='Test', alias=['Test2']) assert ads == 'TEST' assert ads == 'test2' assert ads == 'Test2' assert all([ True if alias in ads.alias else False for alias in ['test', 'test2'] ]) ads = pygaps.Adsorbate(name='Test', alias='Test2') assert ads == 'TEST' assert ads == 'test2' assert ads == 'Test2'
def basic_adsorbate(adsorbate_data): """ Creates an material from model data """ adsorbate = pygaps.Adsorbate(**adsorbate_data) return adsorbate
def test_adsorbate_miss_named_props(self, calculated, error): temp = 77.355 ads = pygaps.Adsorbate(name='n', formula='C2') with warnings.catch_warnings(): warnings.simplefilter("ignore") with pytest.raises(error): ads.molar_mass(calculated) with pytest.raises(error): ads.saturation_pressure(temp, calculate=calculated) with pytest.raises(error): ads.surface_tension(temp, calculate=calculated) with pytest.raises(error): ads.liquid_density(temp, calculate=calculated) with pytest.raises(error): ads.gas_density(temp, calculate=calculated) with pytest.raises(error): ads.enthalpy_liquefaction(temp, calculate=calculated)
def db_create(pth, verbose=False): """ Create the entire database. Parameters ---------- pth : str Path where the database is created. """ for pragma in PRAGMAS: db_execute_general(pragma, pth, verbose=verbose) # Get json files try: import importlib.resources as pkg_resources except ImportError: # Try backported to PY<37 `importlib_resources`. import importlib_resources as pkg_resources # Get and upload adsorbate property types ads_props_json = pkg_resources.read_text( 'pygaps.data', 'adsorbate_props.json' ) ads_props = json.loads(ads_props_json) for ap_type in ads_props: pgsqlite.adsorbate_property_type_to_db( ap_type, db_path=pth, verbose=verbose ) # Get and upload adsorbates ads_json = pkg_resources.read_text('pygaps.data', 'adsorbates.json') adsorbates = json.loads(ads_json) for ads in adsorbates: pgsqlite.adsorbate_to_db( pygaps.Adsorbate(**ads), db_path=pth, verbose=verbose ) # Upload standard isotherm types pgsqlite.isotherm_type_to_db({'type': 'isotherm'}, db_path=pth) pgsqlite.isotherm_type_to_db({'type': 'pointisotherm'}, db_path=pth) pgsqlite.isotherm_type_to_db({'type': 'modelisotherm'}, db_path=pth)
def test_adsorbates(self, db_file, adsorbate_data, basic_adsorbate): """Test functions related to adsorbate table, then inserts a test adsorbate.""" # Upload test pgsqlite.adsorbate_to_db(basic_adsorbate, db_path=db_file) # Upload blank test pgsqlite.adsorbate_to_db(pygaps.Adsorbate('blank'), db_path=db_file) # Unique test with pytest.raises(ParsingError): pgsqlite.adsorbate_to_db(basic_adsorbate, db_path=db_file) # Get test assert basic_adsorbate in pgsqlite.adsorbates_from_db(db_path=db_file) # Overwrite upload basic_adsorbate.properties['formula'] = "newform" pgsqlite.adsorbate_to_db(basic_adsorbate, db_path=db_file, overwrite=True) got_adsorbate = next( ads for ads in pgsqlite.adsorbates_from_db(db_path=db_file) if ads.name == basic_adsorbate.name) assert got_adsorbate.formula == basic_adsorbate.formula # Delete test pgsqlite.adsorbate_delete_db(basic_adsorbate, db_path=db_file) # Delete string test pgsqlite.adsorbate_delete_db('blank', db_path=db_file) # Delete fail test with pytest.raises(ParsingError): pgsqlite.adsorbate_delete_db(basic_adsorbate, db_path=db_file) # Final upload pgsqlite.adsorbate_to_db(basic_adsorbate, db_path=db_file)
def basic_adsorbate(adsorbate_data): """Create a basic adsorbate from model data.""" return pygaps.Adsorbate(**adsorbate_data)