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_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 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_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_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")