How to use test_result_json method in tox

Best Python code snippet using tox_python

test_first_test.py

Source:test_first_test.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2################################################################################3# MacSyFinder - Detection of macromolecular systems in protein datasets #4# using systems modelling and similarity search. #5# Authors: Sophie Abby, Bertrand Néron #6# Copyright © 2014 Institut Pasteur, Paris. #7# See the COPYRIGHT file for details #8# #9# MacsyFinder is distributed under the terms of the GNU General Public License #10# (GPLv3). See the COPYING file for details. #11################################################################################12import shutil13import tempfile14import os15from subprocess import Popen16import json17from tests import MacsyTest18from macsypy.utils import which19class Test(MacsyTest):20 def setUp(self):21 if 'MACSY_HOME' in os.environ:22 self.macsy_home = os.environ['MACSY_HOME']23 self.local_install = True24 else:25 self.local_install = False26 self.macsy_home = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..' '..')))27 self.tmp_dir = tempfile.gettempdir()28 def tearDown(self):29 try:30 shutil.rmtree(self.out_dir)31 except:32 pass33 def test_basic_run(self):34 """35 test if returncode of macsyfinder is 0 and36 test each element of the json37 macsyfinder is launched to search T9SS T3SS T4SS_typeI systems38 with test_aesu.fa sequence db in gembase format39 """40 self.out_dir = os.path.join(self.tmp_dir, 'macsyfinder_test_basic_run')41 os.makedirs(self.out_dir)42 macsy_bin = os.path.join(self.macsy_home, 'bin', 'macsyfinder') if self.local_install else which('macsyfinder')43 command = "{bin} --def={def_dir} --profile-dir={profiles} --out-dir={out_dir} --sequence-db={seq_db} --db-type=gembase {systems}".format(44 bin=macsy_bin,45 out_dir=self.out_dir,46 def_dir=os.path.join(self._data_dir, 'data_set_1', 'def'),47 profiles=os.path.join(self._data_dir, 'data_set_1', 'profiles'),48 seq_db=os.path.join(self._data_dir, 'base', 'test_aesu.fa'),49 systems="T9SS T3SS T4SS_typeI",50 )51 if not bin:52 raise RuntimeError('macsyfinder not found, macsyfinder must be either in your path or MACSY_HOME must be defined')53 # I redirect stdout and stderr in dev null I don't want them on screen54 # I cannot redirect them in output directory as --out-dir expect a non existing directory or an empty one55 # but Popen need to have a file as argument of stdout/err56 # I need to prepend the command by setsid because macsyfinder use killpg with group_id to terminated all57 # threads and subprocess when an error occurred in one hmmsearch. It's work fine but when58 # macsyfinder is launched by the tests.py srcipt the kill group kill also the tests.py script59 # so we must run macsyfinder in a new process group60 try:61 macsy_process = Popen("setsid " + command,62 shell=True,63 stdin=None,64 stdout=open(os.devnull, 'w'),65 stderr=open(os.devnull, 'w'),66 close_fds=False67 )68 except Exception as err:69 msg = "macsyfinder execution failed: command = {0} : {1}".format(command, err)70 print71 print msg72 raise err73 macsy_process.wait()74 self.assertEqual(macsy_process.returncode, 0,75 "macsyfinder finished with non zero exit code: {0} command launched=\n{1}".format(76 macsy_process.returncode,77 command))78 expected_result_path = os.path.join(self._data_dir, 'data_set_1', 'basic_run_results',79 'results.macsyfinder.json')80 with open(expected_result_path) as expected_result_file:81 expected_result_json = json.load(expected_result_file)82 test_result_path = os.path.join(self.out_dir, 'results.macsyfinder.json')83 with open(test_result_path) as test_result_file:84 test_result_json = json.load(test_result_file)85 # it should have only one occurrence of T9SS86 self.assertEqual(len(test_result_json), 1,87 "different type of systems expected: 1 retrieved: {0}".format(len(test_result_json)))88 expected_result_json = expected_result_json[0]89 test_result_json = test_result_json[0]90 self.assertEqual(expected_result_json['name'],91 test_result_json['name'],92 "type of system name expected: {0} retrieved: {1}".format(expected_result_json['name'],93 test_result_json['name']))94 self.assertEqual(expected_result_json['occurrence_number'],95 test_result_json['occurrence_number'],96 "occurrence number expected {0} retrieved: {1}".format(expected_result_json['occurrence_number'],97 test_result_json['occurrence_number']))98 self.assertDictEqual(expected_result_json['replicon'],99 test_result_json['replicon'],100 "replicon expected {0} retrieved: {1}".format(expected_result_json['occurrence_number'],101 test_result_json['occurrence_number']))102 self.assertEqual(expected_result_json['id'],103 test_result_json['id'],104 "system occurrence id expected {0} retrieved: {1}".format(expected_result_json['id'],105 test_result_json['id']))106 self.assertDictEqual(expected_result_json['summary']['mandatory'],107 test_result_json['summary']['mandatory'],108 "mandatory genes expected {0} retrieved: {1}".format(expected_result_json['summary']['mandatory'],109 test_result_json['summary']['mandatory']))110 self.assertDictEqual(expected_result_json['summary']['accessory'],111 test_result_json['summary']['accessory'],112 "accessory genes expected {0} retrieved: {1}".format(expected_result_json['summary']['accessory'],113 test_result_json['summary']['accessory']))114 self.assertDictEqual(expected_result_json['summary']['forbidden'],115 test_result_json['summary']['forbidden'],116 "forbidden genes expected {0} retrieved: {1}".format(expected_result_json['summary']['forbidden'],117 test_result_json['summary']['forbidden']))118 self.assertListEqual(expected_result_json['genes'], test_result_json['genes'],119 "genes expected {0} retrieved: {1}".format(expected_result_json['genes'],...

Full Screen

Full Screen

transform_tests.py

Source:transform_tests.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import json3import unittest4from www.api.transform import ESResultTransformer5class TestCPDStringMethods(unittest.TestCase):6 """7 Test class for the ESResultTransformer class. The static methods are called on a representative8 dataset. The four static methods are called and a basic smoke test is run on the results.9 The datasets were extracted from a debugging screen query, results were pruned down to one entry10 and results were manually validated.11 """12 test_result_json = """{"took":5,"timed_out":false,"_shards":{"total":10,"successful":10,"failed":0},"hits":{"total":3173,"max_score":1.0,"hits":[{"_index":"human_ppi_current","_type":"human_ppi","_id":"AV7tgtgwsEC71Kh3t5_-","_score":1.0,"_source":{"interaction_participants": "TRIO_HUMAN,BLMH_HUMAN", "source_databases": "PhosphoPOINT,Spike,IntAct,HPRD,MINT,Biogrid", "interaction_publications": "16169070", "interaction_confidence": "0.82"}}]}}"""13 test_hit_json = """{"_index":"human_ppi_current","_type":"human_ppi","_id":"AV7tgtgwsEC71Kh3t5_-","_score":1.0,"_source":{"interaction_participants": "TRIO_HUMAN,BLMH_HUMAN", "source_databases": "PhosphoPOINT,Spike,IntAct,HPRD,MINT,Biogrid", "interaction_publications": "16169070", "interaction_confidence": "0.82"}}"""14 i_hit = 015 def test_CPD_parse_confidence(self):16 test_data = json.loads(self.test_result_json)17 test_hit = json.loads(self.test_hit_json)18 result_data = ESResultTransformer.parse_confidence(test_data, self.i_hit, test_hit)19 self.assertEqual(result_data['hits']['hits'][0]['_source'][ESResultTransformer.PpiFields.CONF], .82)20 def test_CPD_parse_participants(self):21 test_data = json.loads(self.test_result_json)22 test_hit = json.loads(self.test_hit_json)23 result_data = ESResultTransformer.parse_participants(test_data, self.i_hit, test_hit)24 self.assertEqual(len(result_data['hits']['hits'][0]['_source'][ESResultTransformer.PpiFields.PART]), 2)25 def test_CPD_parse_publications(self):26 test_data = json.loads(self.test_result_json)27 test_hit = json.loads(self.test_hit_json)28 result_data = ESResultTransformer.parse_publications(test_data, self.i_hit, test_hit)29 self.assertEqual(result_data['hits']['hits'][0]['_source'][ESResultTransformer.PpiFields.PUBS][0], 16169070)30 def test_CPD_parse_databases(self):31 test_data = json.loads(self.test_result_json)32 test_hit = json.loads(self.test_hit_json)33 result_data = ESResultTransformer.parse_databases(test_data, self.i_hit, test_hit)34 self.assertEqual(len(result_data['hits']['hits'][0]['_source'][ESResultTransformer.PpiFields.DBS]), 6)35if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful