def test_molecule_get_structure(self): name = 'water' with App(argv=['molecule', 'get-structure', '--by-name', name]) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual( re.split(' +', capturer.get_text().split('\n')[-1]), ['water', 'pubchem.compound', '962', 'InChI=1S/H2O/h1H2']) namespace = 'chebi' id = '15377' with App(argv=[ 'molecule', 'get-structure', '--by-id', '--namespace', namespace, id ]) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual( re.split(' +', capturer.get_text().split('\n')[-1]), ['', 'chebi', '15377', 'InChI=1S/H2O/h1H2']) namespace = 'chebi' id = '0' with App(argv=[ 'molecule', 'get-structure', '--by-id', '--namespace', namespace, id ]) as app: with CaptureOutput(merged=False) as capturer: app.run() self.assertEqual(capturer.stderr.get_text(), 'Unable to find structure')
def test_migrate(self): with App(argv=['db', 'create']) as app: app.run() with App(argv=['db', 'migrate']) as app: app.run() self.assertTrue(os.path.isdir('migrations')) self.assertNotEqual(os.listdir('migrations'), [])
def test_taxonomy_get_distance_to_root(self): with App(argv=['taxonomy', 'get-distance-to-root', 'bacteria']) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual(float(capturer.get_text()), 2.) with App(argv=['taxonomy', 'get-distance-to-root', 'XXX']) as app: self.assertRaises(SystemExit, lambda: app.run())
def test_drop(self): with App(argv=['db', 'create']) as app: app.run() self.assertTrue(sqlalchemy_utils.functions.database_exists(self.url)) with App(argv=['db', 'drop']) as app: app.run() self.assertFalse(sqlalchemy_utils.functions.database_exists(self.url))
def test_taxonomy_get_parents(self): with App(argv=['taxonomy', 'get-parents', 'bacteria']) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual(capturer.get_text(), "root\ncellular organisms") with App(argv=['taxonomy', 'get-parents', 'XXX']) as app: self.assertRaises(SystemExit, lambda: app.run())
def test_taxonomy_get_distance_to_common_ancestor(self): with App(argv=[ 'taxonomy', 'get-distance-to-common-ancestor', 'Mycoplasma genitalium', 'Mycoplasma pneumoniae' ]) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual(float(capturer.get_text()), 1.) with App(argv=[ 'taxonomy', 'get-distance-to-common-ancestor', 'Mycoplasma genitalium', 'XXX' ]) as app: self.assertRaises(SystemExit, lambda: app.run())
def test_get_version(self): with CaptureOutput() as capture_output: with App(argv=['-v']) as app: with self.assertRaises(SystemExit): app.run() self.assertEqual(capture_output.get_text(), datanator.__version__) with CaptureOutput() as capture_output: with App(argv=['--version']) as app: with self.assertRaises(SystemExit): app.run() self.assertEqual(capture_output.get_text(), datanator.__version__)
def test_taxonomy_get_rank(self): with App(argv=['taxonomy', 'get-rank', '2097']) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual(capturer.get_text(), "species") with App( argv=['taxonomy', 'get-rank', 'Mycoplasma genitalium']) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual(capturer.get_text(), "species") with App(argv=['taxonomy', 'get-rank', 'Mycoplasma genitalium XXX' ]) as app: self.assertRaises(SystemExit, lambda: app.run())
def test_download_array_express(self): with App(argv=['download', '--path=' + self.dirname, 'array-express']) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertTrue( os.path.exists(self.dirname + '/ArrayExpress.sqlite'))
def test_download_uniprot(self): with App(argv=['download', '--path=' + self.dirname, 'uniprot']) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertTrue( os.path.exists(self.dirname + '/Uniprot.sqlite'))
def test_create_table_only(self): sqlalchemy_utils.functions.create_database(self.url) self.assertTrue(sqlalchemy_utils.functions.database_exists(self.url)) self.assertEqual(datanator.db.engine.table_names(), []) with App(argv=['db', 'create']) as app: app.run() self.assertNotEqual(datanator.db.engine.table_names(), [])
def test_build_ecmdb(self): with App(argv=[ 'build', '--path=' + self.dirname, '--max-entries=1', '--verbose=True', 'ecmdb' ]) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertTrue(os.path.exists(self.dirname + '/Ecmdb.sqlite'))
def test_upload_ref_seq(self): with App(argv=[ 'upload', 'reference-genome', os.path.join(path.dirname(__file__), 'data_source', 'test_mpn_sequence.gb'), '--db-path', self.dirname ]) as app: app.run() self.assertTrue( os.path.exists(os.path.join(self.dirname, 'Refseq.sqlite')))
def test_restore(self): with App(argv=['db', 'create']) as app: app.run() self.assertTrue(sqlalchemy_utils.functions.database_exists(self.url)) session = sqlalchemy.orm.sessionmaker(bind=datanator.db.engine)() query = session.query(datanator.core.models.Observation) self.assertEqual(query.count(), 0) session.close() with App(argv=[ 'db', 'restore', '--restore-schema', '--do-not-exit-on-error' ]) as app: # todo: remove --restore-schema and --do-not-exit-on-error after fixing Alembic issue with migrations app.run() session = sqlalchemy.orm.sessionmaker(bind=datanator.db.engine)() query = session.query(datanator.core.models.Observation) self.assertGreater(query.count(), 0) session.close()
def test_get_ec_number(self): dr1p = 'OCC1OC(CC1O)OP([O-])([O-])=O' dr5p = 'OC1CC(O)C(COP([O-])([O-])=O)O1' reaction = 'Deoxyribose 1-phosphate --> Deoxyribose-5-P' with App(argv=['reaction', 'get-ec-number', reaction]) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() print(re.split(' +', capturer.get_text().split('\n'))) self.assertEqual( re.split(' +', capturer.get_text().split('\n')[2]), ['5.4.2', '16.00']) reaction = '{} --> {}'.format(dr1p, dr5p) with App(argv=['reaction', 'get-ec-number', reaction]) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual( re.split(' +', capturer.get_text().split('\n')[2]), ['5.4.2', '16.00']) reaction = '{} > {}'.format(dr1p, dr5p) with App(argv=['reaction', 'get-ec-number', reaction]) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual(capturer.get_text(), 'The reaction is ill-formed') reaction = 'xxxxxxxxx --> Deoxyribose-5-P' with App(argv=['reaction', 'get-ec-number', reaction]) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertTrue(capturer.get_text().startswith( 'Unable to interpret participants:\n'))
def test(self): with App(argv=[]) as app: app.run() with App(argv=['upload']) as app: app.run() with App(argv=['build']) as app: app.run() with App(argv=['download']) as app: app.run() with App(argv=['taxonomy']) as app: app.run() with App(argv=['molecule']) as app: app.run() with App(argv=['reaction']) as app: app.run()
def test_GetDataController(self): input_filename = os.path.join(os.path.dirname(__file__), 'fixtures', 'five_reactions.xlsx') output_filename = os.path.join(self.dirname, 'output.xlsx') argv = [ 'get-data', input_filename, output_filename, '--max-taxon-dist', '8', '--taxon-dist-scale', '1.6', '--include-variants', '--temperature', '37', '--temperature-std', '1', '--ph', '7.5', '--ph-std', '0.3', ] with App(argv=argv) as app: app.run()
def test_GenerateTemplateController(self): filename = os.path.join(self.dirname, 'template.xlsx') with App(argv=['generate-template', filename]) as app: app.run() self.assertTrue(os.path.isfile(filename))
def test_molecule_convert_structure(self): with App(argv=['molecule', 'convert-structure', 'O', 'can']) as app: with CaptureOutput(termination_delay=0.1) as capturer: app.run() self.assertEqual(capturer.get_text(), 'O')