def test_download_textfile_raise_error_if_newline(self, mockrequest): with self.assertRaises(kgerrors.KEGGInvalidFileContent): kgapi.download_textfile( url="http://rest.kegg.jp/returninvalidtext", filename="textfile_testing", force_download=True)
def test_keggapi_list_wantdescrTrue(self, mocked_orgcodes, mockrequestget): itemlist, descriptionlist = kgapi.keggapi_list("hsa", want_descriptions=True) test_genes = set(["testgene1", "testgene2"]) test_descriptions = set(["testdescription1", "testdescription2"]) self.assertEqual(set(itemlist), set(test_genes)) self.assertEqual(set(descriptionlist), set(test_descriptions))
def test_download_textfile_file_exists(self, mocker): filepath = kgapi.DOWNLOAD_DIR.joinpath("textfile-testing") text = "surprise_mofo" try: os.remove(filepath) except FileNotFoundError: pass filepath.write_text(text) self.assertEqual( kgapi.download_textfile("http://rest.kegg.jp/list/hsa", "textfile-testing"), text)
def test_download_textfile_file_doesnt_exist(self, mockedget): text = "testgene1\ttestdescription1\ntestgene2\ttestdescription2" self.assertEqual( kgapi.download_textfile("http://rest.kegg.jp/list/hsa", "textfile_testing", force_download=True), text)
def test_download_json_file_doesnt_exist(self, mockrequestsget): data = kgapi.download_json("http://rest.kegg.jp/get/br:br08301/json", "json_testing") self.assertEqual(data, {"key1": "value1"})
def test_keggapi_info_returns_dict(self, mockrequest): response_dict = kgapi.keggapi_info("hsa", return_format="dict") expected_dict = {"hsa": ["descr_hsa"]} self.assertEqual(response_dict, expected_dict)
def test_keggapi_info_returns_str(self, mockrequest): response_str = kgapi.keggapi_info("hsa", return_format="str") self.assertEqual(response_str, "hsa descr_hsa")
def setUp(self): kgapi.delete_cached_files(verbose=False)