def test_from_archive_path(self): # delete any existing unpacked directory fs.rm(tests.data_path("tiny", "corpus")) c = corpus.Corpus.from_json( {"path": tests.data_path("tiny", "corpus.tar.bz2")}) self.assertEqual(TINY_HASH, c.hash)
def test_1kv9_from_mr_model(): args = [] args += ["--hklin", data_path("1kv9_data.mtz")] args += ["--seqin", data_path("1kv9_sequence.fasta")] args += ["--mr-model", data_path("1kv9_model.pdb")] args += ["--cycles", "1"] _test_pipeline(args)
def test_1kv9(): mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) fsigf = DataItem(mtz, "FP,SIGFP") freer = DataItem(mtz, "FREE") structure = read_structure(data_path("1kv9_model.pdb")) sheetbend = Sheetbend(fsigf, freer, structure) assert ModelStats(structure) == ModelStats(sheetbend.structure)
def test_1kv9(): contents = AsuContents(data_path("1kv9_sequence.fasta")) mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) fsigf = DataItem(mtz, "FP,SIGFP") freer = DataItem(mtz, "FREE") phases = DataItem(mtz, "HL") parrot = Parrot(contents, fsigf, freer, phases) assert parrot.abcd.nreflections == mtz.nreflections assert parrot.fphi.nreflections == mtz.nreflections
def test_1kv9_prune(): structure = read_structure(data_path("1kv9_model.pdb")) stats_in = ModelStats(structure) mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) fsigf = DataItem(mtz, "FP,SIGFP") freer = DataItem(mtz, "FREE") refmac = Refmac(structure, fsigf, freer, cycles=1) prune = Prune(structure, refmac.fphi_best, refmac.fphi_diff) stats_out = ModelStats(prune.structure) assert stats_out.residues < stats_in.residues
def test_1kv9_fix_side_chains(): structure = read_structure(data_path("1kv9_model.pdb")) stats_in = ModelStats(structure) mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) fsigf = DataItem(mtz, "FP,SIGFP") freer = DataItem(mtz, "FREE") refmac = Refmac(structure, fsigf, freer, cycles=1) sidechains = FixSideChains(structure, refmac.fphi_best, refmac.fphi_diff) stats_out = ModelStats(sidechains.structure) assert stats_out.residues == stats_in.residues
def test_1kv9(): structure = read_structure(data_path("1kv9_model.pdb")) mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) fsigf = DataItem(mtz, "FP,SIGFP") freer = DataItem(mtz, "FREE") refmac = Refmac(structure, fsigf, freer, cycles=1) assert refmac.fsigf.nreflections == mtz.nreflections assert refmac.abcd.nreflections == mtz.nreflections assert refmac.fphi_best.nreflections == mtz.nreflections assert refmac.fphi_diff.nreflections == mtz.nreflections assert refmac.fphi_calc.nreflections == mtz.nreflections assert refmac.rwork_change < 0
def test_1kv9(): contents = AsuContents(data_path("1kv9_sequence.fasta")) mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) fsigf = DataItem(mtz, "FP,SIGFP") freer = DataItem(mtz, "FREE") phases = DataItem(mtz, "HL") buccaneer = Buccaneer(contents=contents, fsigf=fsigf, freer=freer, phases=phases, cycles=1) stats = ModelStats(buccaneer.structure) assert stats.residues > 0
def test_hewl(): mtz = gemmi.read_mtz_file(data_path("hewl_data.mtz")) fsigf = DataItem(mtz, "F_New,SIGF_New") fphi = DataItem(mtz, "FWT,PHWT") comit = Comit(fsigf, fphi) assert comit.abcd.nreflections == mtz.nreflections assert comit.fphi.nreflections == mtz.nreflections
def test_combine_data_items(): mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) fsigf = DataItem(mtz, "FP,SIGFP") freer = DataItem(mtz, "FREE") combined = _combine_data_items([fsigf, freer]) assert combined.column_labels() == ["H", "K", "L", "FP", "SIGFP", "FREE"] assert mtz.nreflections == combined.nreflections
def test_build_jats(self): "check building JATS XML content from a DOCX file" docx_file = "DIGEST 99999.docx" expected_content = read_fixture("jats_content_99999.txt").decode( "utf-8") jats_content = jats.build_jats(data_path(docx_file)) self.assertEqual(jats_content, expected_content)
def test_build_docx(self, test_data): "check building a DOCX from a DOCX file" file_name = test_data.get("file_name") output_dir = test_data.get("output_dir") digest = build_digest(data_path(file_name)) output_file_name = output.docx_file_name(digest) expected_fixture = fixture_file(test_data.get("expected_docx_file")) # build now full_file_name = os.path.join(output_dir, output_file_name) docx_file = output.build_docx(data_path(file_name), full_file_name) # assert assertions self.assertEqual(docx_file, os.path.join(output_dir, output_file_name)) # parse and compare the content of the built docx and the fixture docx output_content = parse_content( os.path.join(output_dir, output_file_name)) expected_content = parse_content(expected_fixture) self.assertEqual(output_content, expected_content)
def test_path_escape(self): c = cache.Cache("__test_path_escape__") # create file tests.write_file(tests.data_path("tmp", "file.txt", exists=False), "Hello, world!") # sanity check self.assertEqual(tests.read_file(tests.data_path("tmp", "file.txt")), "Hello, world!") # insert file into cache key = 'this key/path needs: escaping!.?' c[key] = tests.data_path("tmp", "file.txt") # check file contents self.assertEqual(tests.read_file(c[key]), "Hello, world!") c.empty()
def test_remove(self): c = cache.Cache("__test_remove__") # create file tests.write_file(tests.data_path("tmp", "file.txt", exists=False), "Hello, world!") # sanity check self.assertEqual(tests.read_file(tests.data_path("tmp", "file.txt")), "Hello, world!") # insert file into cache c['foobar'] = tests.data_path("tmp", "file.txt") # remove from cache del c['foobar'] self.assertFalse(c['foobar']) c.empty()
def test_1kv9_dataitem_init_types(): mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) item = DataItem(mtz, "FP,SIGFP") # str assert item.label() == "FP,SIGFP" item = DataItem(mtz, mtz.columns[4:6]) # gemmi.MtzColumns assert item.label() == "FP,SIGFP" item = DataItem(mtz, [mtz.columns[4], mtz.columns[5]]) # List[gemmi.Mtz.Column] assert item.label() == "FP,SIGFP"
def test_build_medium_content(self): "test building from a DOCX file and converting to Medium content" docx_file = "DIGEST 99999.docx" expected_medium_content = read_fixture("medium_content_99999.py") # build the digest object medium_content = medium_post.build_medium_content( data_path(docx_file), "tmp", self.digest_config) # test assertions self.assertEqual(medium_content, expected_medium_content)
def test_invalid_columns_for_mtz_with_multiple_datasets(columns): mtz = gemmi.read_mtz_file(data_path("hewl_data.mtz")) mtz.add_dataset("Old") mtz.add_column("HLA", "A") mtz.add_column("HLB", "A") mtz.add_column("HLC", "A") mtz.add_column("HLD", "A") with pytest.raises(ValueError): DataItem(mtz, columns)
def test_1kv9_polymer_from_sequence_file(): path = data_path("1kv9_sequence.fasta") polymers = list(Polymer.from_sequence_file(path)) assert len(polymers) == 1 assert polymers[0].label == "A" assert polymers[0].copies == 1 assert polymers[0].polymer_type == PolymerType.PROTEIN assert len(polymers[0].sequence) == 668 assert polymers[0].sequence[:5] == "AGVDE" assert polymers[0].sequence[-5:] == "HKAAP"
def test_valid_columns_for_mtz_with_multiple_datasets(columns): mtz = gemmi.read_mtz_file(data_path("hewl_data.mtz")) mtz.add_dataset("Old") mtz.add_column("HLA", "A") mtz.add_column("HLB", "A") mtz.add_column("HLC", "A") mtz.add_column("HLD", "A") abcd = DataItem(mtz, columns) assert abcd.types == "AAAA" assert len(abcd.columns) == 7
def test_hewl_polymer_from_sequence_file(): path = data_path("hewl_sequence.fasta") polymers = list(Polymer.from_sequence_file(path)) assert len(polymers) == 1 assert polymers[0].label == "hewl" assert polymers[0].copies == 1 assert polymers[0].polymer_type == PolymerType.PROTEIN assert len(polymers[0].sequence) == 129 assert polymers[0].sequence[:5] == "KVFGR" assert polymers[0].sequence[-5:] == "RGCRL"
def preprocess_pair(basename, preprocessor=preprocess.preprocess): gs_path = tests.data_path(os.path.join('cl', str(basename) + '.gs'), exists=not UPDATE_GS_FILES) tin_path = tests.data_path(os.path.join('cl', str(basename) + '.cl')) # Run preprocess tin = tests.data_str(tin_path) tout = preprocessor(tin) if UPDATE_GS_FILES: gs = tout with open(gs_path, 'w') as outfile: outfile.write(gs) print("\n-> updated gold standard file '{}' ..." .format(gs_path), file=sys.stderr, end=' ') else: gs = tests.data_str(gs_path) return (gs, tout)
def test_build_medium_content_with_jats(self): "test building from a zip file and converting to Medium content" docx_file = "DIGEST 99999.zip" jats_file = fixture_file("elife-99999-v0.xml") expected_medium_content = read_fixture("medium_content_jats_99999.py") # build the digest object medium_content = medium_post.build_medium_content( data_path(docx_file), "tmp", self.digest_config, jats_file) # test assertions self.assertEqual(medium_content, expected_medium_content)
def test_1kv9(): structure = read_structure(data_path("1kv9_model.pdb")) stats_in = ModelStats(structure) mtz = gemmi.read_mtz_file(data_path("1kv9_data.mtz")) fsigf = DataItem(mtz, "FP,SIGFP") freer = DataItem(mtz, "FREE") refmac = Refmac(structure, fsigf, freer, cycles=1) findwaters = FindWaters(structure, refmac.fphi_best) stats_out = ModelStats(findwaters.structure) assert stats_out.residues == stats_in.residues assert stats_out.waters > stats_in.waters assert stats_out.dummy_atoms == stats_in.dummy_atoms findwaters = FindWaters(structure, refmac.fphi_best, dummy=True) stats_out = ModelStats(findwaters.structure) assert stats_out.residues == stats_in.residues assert stats_out.waters == stats_in.waters assert stats_out.dummy_atoms > stats_in.dummy_atoms
def test_model_stats(): path = data_path("1kv9_model.pdb") structure = read_structure(path) stats = ModelStats(structure) assert stats.residues == 651 assert stats.sequenced_residues == 651 assert stats.fragments == 12 # TODO: Check using Coot assert stats.longest_fragment == 214 assert stats.waters == 0 assert stats.dummy_atoms == 0
def test_set_and_get(self): c = cache.Cache("__test_set_and_get__") # create file tests.write_file(tests.data_path("tmp", "file.txt", exists=False), "Hello, world!") # sanity check self.assertEqual(tests.read_file(tests.data_path("tmp", "file.txt")), "Hello, world!") # insert file into cache c['foobar'] = tests.data_path("tmp", "file.txt") # file must be in cache self.assertTrue(fs.isfile(fs.path(c.path, "foobar"))) # file must have been moved self.assertFalse(fs.isfile(tests.data_path("file.txt", exists=False))) # check file contents self.assertTrue(tests.read_file(c['foobar']), "Hello, world!") c.empty()
def preprocess_pair(basename, preprocessor=preprocess.preprocess): gs_path = tests.data_path(os.path.join('cl', str(basename) + '.gs'), exists=not UPDATE_GS_FILES) tin_path = tests.data_path(os.path.join('cl', str(basename) + '.cl')) # Run preprocess tin = tests.data_str(tin_path) tout = preprocessor(tin) if UPDATE_GS_FILES: gs = tout with open(gs_path, 'w') as outfile: outfile.write(gs) print("\n-> updated gold standard file '{}' ...".format(gs_path), file=sys.stderr, end=' ') else: gs = tests.data_str(gs_path) return (gs, tout)
def test_build_medium_content_with_jats_and_image(self): "test building from a DOCX file and converting to Medium content" docx_file = "DIGEST 99999.docx" jats_file = fixture_file("elife-99999-v0.xml") image_file_name = "IMAGE 99999.jpeg" expected_medium_content = read_fixture("medium_content_jats_99999.py") # build the digest object medium_content = medium_post.build_medium_content( data_path(docx_file), "tmp", self.digest_config, jats_file, image_file_name) # test assertions self.assertEqual(medium_content, expected_medium_content)
def get_test_model(): return model.from_json({ "corpus": { "path": tests.data_path("tiny", "corpus"), }, "architecture": { "rnn_size": 8, "num_layers": 2, }, "train_opts": { "epochs": 2 } })
def test_profile_zip(self, zip_file, expected_docx, expected_image): "test parsing of zip file to find the docx and image file names" docx, image = profile_zip(data_path(zip_file)) docx_file_name = zip_output_name(docx.filename, "") image_file_name = zip_output_name(image.filename, "") self.assertEqual( docx_file_name, expected_docx, "file_name {file_name}, expected {expected}, got {output}".format( file_name=zip_file, expected=expected_docx, output=docx), ) self.assertEqual( image_file_name, expected_image, 'file_name {file_name}, expected {expected}, got {output}"'.format( file_name=zip_file, expected=expected_image, output=image), )
def test_build_to_html(self): "test building from a DOCX file and converting to HTML" docx_file = "DIGEST 99999.docx" expected_title = u"Fishing for errors in the tests" expected_summary = read_fixture("html_content_99999_summary.txt").decode( "utf-8" ) expected_text_1 = read_fixture("html_content_99999_text_1.txt").decode("utf-8") expected_text_2 = read_fixture("html_content_99999_text_2.txt").decode("utf-8") expected_text_3 = read_fixture("html_content_99999_text_3.txt").decode("utf-8") # build the digest object digest = build.build_digest(data_path(docx_file)) # test assertions self.assertEqual(html.string_to_html(digest.title), expected_title) self.assertEqual(html.string_to_html(digest.summary), expected_summary) self.assertEqual(html.string_to_html(digest.text[0]), expected_text_1) self.assertEqual(html.string_to_html(digest.text[1]), expected_text_2) self.assertEqual(html.string_to_html(digest.text[2]), expected_text_3)
def test_unzip_zip(self): "test parsing of zip file to find the docx and image file names" zip_file = "DIGEST 35774.zip" temp_dir = "tmp" docx, image = unzip_zip(data_path(zip_file), "tmp") expected_docx = os.path.join(temp_dir, "Bayés_35774.docx") expected_image = os.path.join(temp_dir, "bayes.jpg") self.assertEqual( docx, expected_docx, "expected {expected}, got {output}".format(expected=expected_docx, output=docx), ) self.assertEqual( image, expected_image, "expected {expected}, got {output}".format(expected=expected_image, output=docx), )