def test_read_aid_no_regex_with_prefix(self): t1 = AtomsCollection("t1", "./tests/store") fn1 = "../homer/ni.p454.out" prefix = "Test" a5 = t1._read_aid(fn1, None, prefix) assert a5 == "test_ni.p454.out" shutil.rmtree("./tests/store")
def test_read_aid(self): t1 = AtomsCollection("t1", "./tests/store") rxid = r'ni.p(?P<gbid>\d+).out' import re c_rxid = re.compile(rxid) fn1 = "../homer/ni.p454.out" a1 = t1._read_aid(fn1, c_rxid) assert a1 == "454" shutil.rmtree("./tests/store")
def test_get(self): my_col = AtomsCollection("A", "./tests/results") result = "Random test result" desc = "test" aid = "12" my_col.store.store(result, desc, aid, arg_a=1, arg_b=2) ret_val3 = my_col.get(desc, aid, arg_a=1, arg_b=2) assert ret_val3 == result shutil.rmtree("./tests/results")
def test_read_aid_with_prefix(self): t1 = AtomsCollection("t1", "./tests/store") rxid = r'ni.p(?P<gbid>\d+).out' import re c_rxid = re.compile(rxid) fn1 = "../homer/ni.p454.out" prefix = "Pre" a2 = t1._read_aid(fn1, c_rxid, prefix) assert a2 == "pre_454" shutil.rmtree("./tests/store")
def test_read_single_file(self): t1 = AtomsCollection("Test_1", "./tests/store") # read single file t1.read("./tests/test_data/ni.p455.out", 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") assert 1 == len(t1) shutil.rmtree("./tests/store")
def _initialize_collection_and_read(aids): '''initialize collection and read specified atoms files''' my_col = AtomsCollection("Test", "tests/results") data_path = 'tests/test_data/ni.p{0:s}.out' for aid in aids: my_col.read(data_path.format(aid), 28, 'lammps-dump-text', rxid=r'ni.p(?P<aid>\d+).out') return my_col
def test_read_empty_list(self): t1 = AtomsCollection("Test_1", "./tests/store") # empty list t1.read([], 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") assert 0 == len(t1) shutil.rmtree("./tests/store")
def test_read_empty_dir_with_file(self): t1 = AtomsCollection("Test_1", "./tests/store") # empty directory / directory and file t1.read(["./tests/test_data/ni.p456.out", "./tests/test_data/empty"], 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") assert 1 == len(t1) shutil.rmtree("./tests/store")
def test_read_directory(self): t1 = AtomsCollection("Test_1", "./tests/store") # read directory t1.read("./tests/test_data/sub1/", 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") assert 2 == len(t1) shutil.rmtree("./tests/store")
def test_aids(self): t1 = AtomsCollection("Test_1", "./tests/test_paths") t1.read( ["./tests/test_data/ni.p454.out", "./tests/test_data/ni.p453.out"], 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out') aid_list = t1.aids() assert type(aid_list) is list assert int(aid_list[0]) == int("453") assert len(aid_list) is 2
def test_read_list(self): t1 = AtomsCollection("Test_1", "./tests/store") # list of input files t1.read( ["./tests/test_data/ni.p454.out", "./tests/test_data/ni.p453.out"], 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") assert 2 == len(t1) assert "test_454" == list(t1)[0] shutil.rmtree("./tests/store")
def test_read_list_with_atomic_num_list(self): t1 = AtomsCollection("Test_1", "./tests/store") # list of input files with atomic num list (corresponding to one file) t1.read( ["./tests/test_data/ni.p454.out", "./tests/test_data/ni.p453.out"], [28, 28], "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") assert 2 == len(t1) assert "test_454" == list(t1)[0] shutil.rmtree("./tests/store")
def test_read_aid_invalid_regex(self): t1 = AtomsCollection("t1", "./tests/store") fn1 = "../homer/ni.p454.out" prefix = "Test" output2 = io.StringIO() sys.stdout = output2 import re c_rxid3 = re.compile(r'ni.p(P<gbid>\d+).out') a6 = t1._read_aid(fn1, c_rxid3, prefix) assert "Regex found no pattern. Resolving to filename as aid.\n" == output2.getvalue( ) assert a6 == "test_ni.p454.out" shutil.rmtree("./tests/store")
def test_read_nonexistent_directory(self): # non-existent directory t1 = AtomsCollection("Test_1", "./tests/store") output = io.StringIO() sys.stdout = output t1.read("definitely_wrong", 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") assert "Invalid file path, definitely_wrong was not read.\n" == output.getvalue( ) shutil.rmtree("./tests/store")
def test_get_no_aid(self): my_col = AtomsCollection("A", "./tests/results") result = "Random test result" desc = "test" aid = "12" aid2 = "13" my_col["12"] = "test" my_col["13"] = "test2" my_col.store.store(result, desc, aid, arg_a=1, arg_b=2) my_col.store.store(result, desc, aid2, arg_a=1, arg_b=2) ret_val3 = my_col.get(desc, arg_a=1, arg_b=2) assert type(ret_val3) is dict assert len(ret_val3) is 2 shutil.rmtree("./tests/results")
def test_generate_file_name_with_collection(self): my_col = AtomsCollection("A", ".") f = my_col.store._generate_file_name("ler", 'U', collection=my_col, eps=0.025, rcut=5.0, nmax=9, lmax=9, metric="euclidean", n_trees=10, search_k=-1) assert f == "ler__U___collection_a___eps_0.025___lmax_9___metric_euclidean___n_trees_10___nmax_9___rcut_5.0___search_k_-1.pkl"
def test_read_ASE_read_error(self): t1 = AtomsCollection("Test_1", "./tests/store") # ASE io.read() cannot automatically determine filetype self.assertRaises(StopIteration, AtomsCollection.read, t1, "./tests/test_data/ni.p457.out", 28, rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") # missing parameter self.assertRaises(StopIteration, AtomsCollection.read, t1, "./tests/test_data/ni.p456.out", "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") shutil.rmtree("./tests/store")
def test_read_repeat_file(self): # will not read previously read file t1 = AtomsCollection("Test_1", "./tests/store") t1.read("./tests/test_data/ni.p456.out", 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") t1.read("./tests/test_data/ni.p456.out", 28, "lammps-dump-text", rxid=r'ni.p(?P<gbid>\d+).out', prefix="TEST") assert 1 == len(t1) shutil.rmtree("./tests/store")
def test_read_aid_no_regex(self): t1 = AtomsCollection("t1", "./tests/store") fn1 = "../homer/ni.p454.out" a4 = t1._read_aid(fn1, None) assert a4 == "ni.p454.out" shutil.rmtree("./tests/store")