def test_get_preferences_arg(tmpdir, pvl_one_group): with open(tmpdir.join('IsisPrefrences'), 'w+') as pvl_file: pvl_file.write(pvl_one_group) pvl_file.flush() pvl_obj = util.get_isis_preferences(pvl_file.name) pvl_obj_from_dict = util.get_isis_preferences({**pvl_obj}) assert pvl_obj['Test']['t'] == 't1' assert pvl_obj == pvl_obj_from_dict
def test_get_prefrences_malformed_files(monkeypatch, tmpdir, filename): monkeypatch.setenv('ISISROOT', str(tmpdir)) monkeypatch.setenv('HOME', str(tmpdir)) tmpdir.mkdir('.Isis') with pytest.raises(pvl.decoder.ParseError): with open(tmpdir.join(filename), 'w+') as brokenpref: brokenpref.write('Totally not PVL') brokenpref.flush() util.get_isis_preferences() with pytest.raises(pvl.decoder.ParseError): util.get_isis_preferences(tmpdir.join(filename))
def test_get_prefernces_arg_isisroot(monkeypatch, tmpdir, pvl_one_group, pvl_two_group): monkeypatch.setenv('ISISROOT', str(tmpdir)) with open(tmpdir.join('IsisPreferences'), 'w+') as pvl_isisroot_file: with open(tmpdir.join('arg_prefs.pvl'), 'w+') as pvl_arg_file: pvl_arg_file.write(pvl_two_group) pvl_arg_file.flush() pvl_isisroot_file.write(pvl_one_group) pvl_isisroot_file.flush() pvl_obj = util.get_isis_preferences(pvl_arg_file.name) assert pvl_obj['Test']['t'] == 't2' assert pvl_obj['Data']['b'] == 'b2' assert pvl_obj['Data']['a'] == 'a2' assert pvl_obj['Data']['r'] == 'r2'
def test_get_prefernces_arg_isisroot_home(monkeypatch, tmpdir, pvl_one_group, pvl_two_group, pvl_three_group): tmpdir.mkdir('.Isis') monkeypatch.setenv('ISISROOT', str(tmpdir)) monkeypatch.setenv('HOME', str(tmpdir)) with open(tmpdir.join('arg_prefs.pvl'), 'w+') as pvl_arg_file: with open(tmpdir.join('.Isis', 'IsisPreferences'), 'w+') as pvl_home_file: with open(tmpdir.join('IsisPreferences'), 'w+') as pvl_isisroot_file: pvl_arg_file.write(pvl_one_group) pvl_arg_file.flush() pvl_home_file.write(pvl_three_group) pvl_home_file.flush() pvl_isisroot_file.write(pvl_two_group) pvl_isisroot_file.flush() pvl_obj = util.get_isis_preferences(pvl_arg_file.name) assert pvl_obj['Test']['t'] == 't1' assert pvl_obj['Data']['b'] == 'b3'