def test__determine_residues_to_mutate_to(self): # arrange globaloptions_lines = ['#\n', 'RESIDUES: All;\n'] expected_residues = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y'] # act residues = Main._determine_residues_to_mutate_to(globaloptions_lines) # assert self.assertListEqual(expected_residues, residues) # arrange globaloptions_lines = ['#\n', 'RESIDUES: ACDEFGHI;\n'] expected_residues = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I'] # act residues = Main._determine_residues_to_mutate_to(globaloptions_lines) # assert self.assertListEqual(expected_residues, residues) # arrange globaloptions_lines = ['#\n', 'RESIDUES: AXZ;\n'] expected_residues = ['A'] # act residues = Main._determine_residues_to_mutate_to(globaloptions_lines) # assert self.assertListEqual(expected_residues, residues)
def _main_test_init(self, args, hammer): # allocate port port = TestConfig.get_next_listener_port() # create main, the target of the test test_name = "%s %s" % (hammer, args) main_args = ['-l', TestConfig.TEST_LISTENER_ADDR, '-N', test_name, '-p', port] if isinstance(args, basestring): main_args.extend(['-m', args]) # for backward compatibility else: main_args.extend(args) self.main = Main(main_args) # collect classes of observed audit results self.actual_results = [] self.orig_main__handle_result = self.main.handle_result def main__handle_result(res): self.orig_main__handle_result(res) if isinstance(res, ClientConnectionAuditResult): self.actual_results.append(res) else: pass # ignore events print res self.main.handle_result = main__handle_result # create a client hammering the listener self.hammer = hammer if self.hammer != None: self.hammer.init_tcp((TestConfig.TEST_LISTENER_ADDR, port), self.main.auditor_set.len())
def test__read_global_options(self): # arrange path_globoptions_file = TPLS.MC_TESTS_CONFIG_GLOBAL_OPTIONS.value + '/global_options.txt' expected_global_options = ['######## NUMBER OF PDBs TO ANALYSE ##############################################' '#################################\n', '#\n', '## All means all PDBs in the ' 'specified source directory\n', '#\n', 'PDBs: 4;\n', '#\n', '######## NUMBER OF ' 'FASTA FILES TO ANALYSE #########################################################' '###############\n', '#\n', '## All means all FASTA files in specified source ' 'directory\n', '#\n', 'FASTAs: 10;\n', '#\n', '######## OPERATIONS YOU WANT TO ' 'RUN ############################################################################' '##\n', '#\n', '## MUTATE_FASTA = generate FASTA files of every possible point ' 'mutant for a given FASTA file.\n', '## AGADIR = run Agadirwrapper. The Options.txt' ' file specifies which of Agadirwrapper algorithms to perform.\n', '## FOLDX_REPAIR' ' = repair pdb with FoldX repair algorithm\n', '## FOLDX_BUILDMODEL = mutate ' 'sequence, remodel and determine DDG of mutated pdb with FoldX BuildModel ' 'algorithm\n', '## FOLDX_STABILITY = determine DDG of pdb with FoldX Stability ' 'algorithm\n', '## FOLDX_ANALYSECOMPLEX = determine DDG of pdb with FoldX ' 'Stability algorithm\n', '#\n', 'MUTATE_FASTA: TRUE\n', 'AGADIR: FALSE\n', 'FOLDX_REPAIR: FALSE\n', 'FOLDX_BUILDMODEL: FALSE\n', 'FOLDX_STABILITY: FALSE\n', 'FOLDX_ANALYSECOMPLEX: FALSE\n', '#\n', '######## AMINO ACIDS YOU WANT TO MUTATE ' 'TO ########################################################################\n', '#\n', '## All means all 20 amino acids. Otherwise each amino acid in FASTA format,' ' e.g. "ACDEFGHIKLMNOP;"\n', '#\n', 'RESIDUES: All;'] # act global_options = Main._read_global_options(path_globoptions_file) # assert self.assertEqual(expected_global_options, global_options)
def createObject(name, unitPrice, quantity): mainFlag = False sideFlag = False drinkFlag = False for ele in system.mainList: if ele.name == name: mainFlag = True main = Main(name, unitPrice, quantity) return main
def test_dummy(self): ''' This test establishes a bunch of plain TCP connections against dummy auditor. The dummy auditor just acknowledges the fact of connection happening. ''' # these variables will be updated from a hook function invoked from main self.got_result_start = 0 self.got_result = 0 self.got_result_end = 0 self.got_bulk_result = 0 self.nstray = 0 # the hook function def main__handle_result(res): ''' This function overrides main.handle_result() and updates our counters ''' if isinstance(res, ClientAuditStartEvent): self.got_result_start = self.got_result_start + 1 elif isinstance(res, ClientAuditEndEvent): self.got_result_end = self.got_result_end + 1 elif isinstance(res, ClientConnectionAuditResult): self.got_result = self.got_result + 1 elif isinstance(res, ClientAuditResult): self.got_bulk_result = self.got_bulk_result + 1 else: self.nstray = self.nstray + 1 # allocate port port = get_next_listener_port() # create a client hammering our test listener self.hammer = TCPHammer() # create main, the target of the test self.main = Main(['-m', 'dummy', '-l', TEST_LISTENER_ADDR, '-p', port]) self.main.handle_result = main__handle_result # tell the hammer how many attempts to make exactly self.hammer.init_tcp((TEST_LISTENER_ADDR, port), self.main.auditor_set.len()) # start server and client self.main.start() self.hammer.start() self.main.join(timeout=5) self.hammer.stop() self.main.stop() # make sure we have received expected number of results self.assertEquals(self.got_result_start, 1) self.assertEquals(self.got_result, self.main.auditor_set.len()) self.assertEquals(self.got_result_end, 1) self.assertEquals(self.got_bulk_result, 1) self.assertEquals(self.nstray, 0)
def test__build_filelist_for_analysis_2(self): # arrange globaloptions_lines = ['#\n', 'FASTAs: 4;\n', '#'] PDBs_or_FASTAs = 'FASTAs' # path_repo = TPLS. expected_fasta_list = ['1_A.fasta', '1_B.fasta', '2_A.fasta', '3_A.fasta'] # act fasta_list = Main._build_filelist_for_analysis(globaloptions_lines, PDBs_or_FASTAs, path_repo) # assert self.assertNotEqual('', fasta_list) self.assertListEqual(expected_fasta_list, fasta_list)
def test__build_filelist_for_analysis_1(self): # arrange globaloptions_lines = ['#\n', 'PDBs: 4;\n', '#'] PDBs_or_FASTAs = 'PDBs' path_input = TPLS.MC_TESTS_INPUT.value expected_pdb_list = ['RepairPDB_1.pdb', 'RepairPDB_2.pdb', 'RepairPDB_3.pdb', 'RepairPDB_4.pdb'] # act pdb_list = Main._build_filelist_for_analysis(globaloptions_lines, PDBs_or_FASTAs, path_input) # assert self.assertNotEqual('', pdb_list) self.assertListEqual(expected_pdb_list, pdb_list)
def test__determine_which_operations_to_perform(self): # arrange globaloptions_lines = ['## FOLDX_ANALYSECOMPLEX = determine DDG of pdb with FoldX Stability algorithm\n', '#\n', 'MUTATE_FASTA: TRUE\n', 'AGADIR: FALSE\n', 'FOLDX_REPAIR: FALSE\n', 'FOLDX_BUILDMODEL: FALSE\n', 'FOLDX_STABILITY: FALSE\n', 'FOLDX_ANALYSECOMPLEX: FALSE\n', '#\n'] expected_operations = {'do_mutate_fasta': True, 'do_agadir': False, 'do_foldx_repair': False, 'do_foldx_buildmodel': False, 'do_foldx_stability': False, 'do_foldx_analysecomplex': False} # act operations = Main._determine_which_operations_to_perform(globaloptions_lines) # assert self.assertNotEqual({}, operations) self.assertDictEqual(expected_operations, operations)
def test_recursive_segmentation(): IMAGE_PATH = '../images/3.jpg' main = Main(IMAGE_PATH) main.sauvola_threshold() region = np.array([[1, 0, 1, 0], [0, 1, 1, 1], [0, 1, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1], [1, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]]) h_vertical = [2, 3, 2, 0, 0, 4, 2, 0, 0, 0, 4, 2, 3, 1] h_vertical_b_level = [1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1] h_vertical_rle = [1, 3, 0, 2, 1, 2, 0, 3, 1, 4] h_vertical_black = [3, 2, 4] h_vertical_white = [2, 3] h_horizontal = [7, 4, 6, 6] h_horizontal_b_level = [1, 1, 1, 1] h_horizontal_rle = [1, 4] h_horizontal_black = [4] h_horizontal_white = [] features = main.recursive_segmentation(region) assert features[0] == h_vertical assert features[1] == h_vertical_b_level assert features[2] == h_vertical_rle assert features[3] == h_vertical_black assert features[4] == h_vertical_white assert features[5] == h_horizontal assert features[6] == h_horizontal_b_level assert features[7] == h_horizontal_rle assert features[8] == h_horizontal_black assert features[9] == h_horizontal_white
specific_fxmutants = ['AA101A'] # specific_fxmutants = [] """ Get the fasta files you want to run mutate_fasta or agadir on. """ path_fastafiles = [] # path_input_fastas_dir = Paths.INPUT_MUTS_MULTIFASTAS_29611_1000 + '/1...250/' # path_fastafiles = sorted(glob.glob(path_input_fastas_dir + '/**/*.fasta', recursive=True)) # path_fastafiles = sorted(glob.glob(path_input_fastas_dir + '/*.fasta')) # if not path_fastafiles: # raise ValueError('No fasta files to process. Check paths are correct and check files are where you expect.') """ Kick off the program(s) via the constructor or Main class. """ main = Main(operations, use_multithread, Paths.INPUT, Paths.OUTPUT, path_pdbfiles, path_fastafiles, specific_fxmutants, AA.LIST_ALL_20_AA.value) """ After computation completed, DELETE config files no longer needed. """ # if operations['do_foldx_buildmodel']: # fx = FoldX() # path_output_bm_pdb_fxmutant_dirs = [] # for path_pdbfile in path_pdbfiles: # pdbname = os.path.basename(path_pdbfile).split('.')[0] # for specific_fxmutant in specific_fxmutants: # path_output_bm_pdb_fxmutant_dirs.append(os.path.join(Paths.OUTPUT_BM, pdbname, specific_fxmutant)) # if not specific_fxmutants: # path_output_bm_pdb_fxmutant_dirs = glob.glob(os.path.join(Paths.OUTPUT_BM, pdbname, '*')) # for path_output_bm_pdb_fxmutant_dir in path_output_bm_pdb_fxmutant_dirs: # if fx.BuildModel(Cond.INCELL_MAML_FX.value).has_already_generated_dif_bm_fxoutfile(path_output_bm_pdb_fxmutant_dir):
dir_3dots = str(startnum) + Str.DOTS3.value + str(endnum) path_input_fastas_3dots_dir = os.path.join( Paths.INPUT_MUTS_MULTIFASTAS_29611_1000, dir_3dots) path_fastafiles = sorted( glob.glob(path_input_fastas_3dots_dir + '/**/*.fasta', recursive=True)) if not path_fastafiles: raise ValueError( 'No fasta files to process. Check paths are correct and check files are where you expect.' ) """ Kick off the program(s) via the constructor or Main class. """ main = Main(operations, use_multithread, Paths.INPUT, Paths.OUTPUT, path_pdbfiles, path_fastafiles, AA.LIST_ALL_20_AA.value, write_to_csv_dumpfile_after_each_mutant=False) if i == 0: break startnum += 1000 endnum += 1000 # pydevd.stoptrace() import natsort import time import multiprocessing as mp from src.enums.Conditions import Cond from src.tools.GeneralUtilityMethods import GUM
def test_return_1(self): obj = Main() self.assertEqual(obj.return_one(),1)
import os.path from src.Main import Main from config.Config import APKAnalyserConfig AAConfig = APKAnalyserConfig print AAConfig.banner AAConfig.RootDir = os.path.dirname(os.path.abspath(__file__)) AAConfig.OutputDir = os.path.join(AAConfig.RootDir, 'output') Main = Main()
from src.Main import Main Main().initialize()
class TestMainSSL(unittest.TestCase): ''' Unittests for SSL. ''' logger = logging.getLogger('TestMainSSL') def test_bad_client1(self): ''' Plain TCP client causes unexpected UNEXPECTED_EOF instead of UNKNOWN_CA ''' self._main_test( [ '--user-cn', TEST_USER_CN, '--user-ca-cert', TEST_USER_CA_CERT_FILE, '--user-ca-key', TEST_USER_CA_KEY_FILE ], TCPHammer(), [ ExpectedSSLClientConnectionAuditResult((DEFAULT_CN, SELFSIGNED), '127.0.0.1', UNEXPECTED_EOF), ExpectedSSLClientConnectionAuditResult((TEST_USER_CN, SELFSIGNED), '127.0.0.1', UNEXPECTED_EOF), ExpectedSSLClientConnectionAuditResult((DEFAULT_CN, TEST_USER_CA_CN), '127.0.0.1', UNEXPECTED_EOF), ExpectedSSLClientConnectionAuditResult((TEST_USER_CN, TEST_USER_CA_CN), '127.0.0.1', UNEXPECTED_EOF) ]) # def test_bad_client2(self): # ''' Plain TCP client causes unexpected UNEXPECTED_EOF instead of UNKNOWN_CA ''' # self._main_test( # [ # '--user-cert', TEST_USER_CERT_FILE, # '--user-key', TEST_USER_KEY_FILE, # '--no-user-cert-sign' # ], # TCPHammer(), # [ # ExpectedSSLClientConnectionAuditResult((TEST_USER_CERT_CN, None), '127.0.0.1', UNEXPECTED_EOF), # ExpectedSSLClientConnectionAuditResult((DEFAULT_CN, SELFSIGNED), '127.0.0.1', UNEXPECTED_EOF), # ]) def test_notverifying_client(self): ''' A client which fails to verify the chain of trust reports no error ''' self._main_test( [ '--user-cn', TEST_USER_CN, '--server', TEST_SERVER ], NotVerifyingSSLHammer(), [ ExpectedSSLClientConnectionAuditResult((DEFAULT_CN, SELFSIGNED), '127.0.0.1', CONNECTED), ExpectedSSLClientConnectionAuditResult((TEST_USER_CN, SELFSIGNED), '127.0.0.1', CONNECTED), ExpectedSSLClientConnectionAuditResult((TEST_SERVER_CN, SELFSIGNED), '127.0.0.1', CONNECTED) ]) def test_verifying_client(self): ''' A client which properly verifies the certificate reports UNKNOWN_CA ''' self._main_test( [ '--user-cn', TEST_USER_CN, '--server', TEST_SERVER ], VerifyingSSLHammer(TEST_USER_CN), [ ExpectedSSLClientConnectionAuditResult((DEFAULT_CN, SELFSIGNED), '127.0.0.1', UNKNOWN_CA), ExpectedSSLClientConnectionAuditResult((TEST_USER_CN, SELFSIGNED), '127.0.0.1', UNKNOWN_CA), ExpectedSSLClientConnectionAuditResult((TEST_SERVER_CN, SELFSIGNED), '127.0.0.1', UNKNOWN_CA) ]) # ------------------------------------------------------------------------------------ def setUp(self): self.main = None def tearDown(self): if self.main != None: self.main.stop() def _main_test(self, args, hammer, expected_results): ''' This is a main worker function. It allocates external resources and launches threads, to make sure they are freed this function was to be called exactly once per test method, to allow tearDown() method to cleanup properly. ''' self._main_test_init(args, hammer) self._main_test_do(expected_results) def _main_test_init(self, args, hammer): # allocate port port = TestConfig.get_next_listener_port() # create main, the target of the test test_name = "%s %s" % (hammer, args) main_args = ['-l', TestConfig.TEST_LISTENER_ADDR, '-N', test_name, '-p', port] if isinstance(args, basestring): main_args.extend(['-m', args]) # for backward compatibility else: main_args.extend(args) self.main = Main(main_args) # collect classes of observed audit results self.actual_results = [] self.orig_main__handle_result = self.main.handle_result def main__handle_result(res): self.orig_main__handle_result(res) if isinstance(res, ClientConnectionAuditResult): self.actual_results.append(res) else: pass # ignore events print res self.main.handle_result = main__handle_result # create a client hammering the listener self.hammer = hammer if self.hammer != None: self.hammer.init_tcp((TestConfig.TEST_LISTENER_ADDR, port), self.main.auditor_set.len()) def _main_test_do(self, expected_results): # run the server self.main.start() # start the hammer if any if self.hammer != None: self.hammer.start() # wait for main to finish its job try: self.main.join(timeout=TestConfig.TEST_MAIN_JOIN_TIMEOUT) # on timeout throws exception, which we let propagate after we shut the hammer and the main thread finally: # stop the hammer if any if self.hammer != None: self.hammer.stop() # stop the server self.main.stop() # check if the actual results match expected ones if len(expected_results) != len(self.actual_results): mismatch = True print "! length mismatch len(er)=%d, len(ar)=%d" % (len(expected_results), len(self.actual_results)) for er in expected_results: print "er=%s" % er for ar in self.actual_results: print "ar=%s" % ar else: mismatch = False for i in range(len(expected_results)): er = expected_results[i] ar = self.actual_results[i] if not er.matches(ar): print "! mismatch\n\ter=%s\n\tar=%s" % (er, ar) mismatch = True self.assertFalse(mismatch)
def __init__(self, main, mainBun, mainBunNo, mainPatty, mainPattyNo, mainPrice, ingredients=[], ingredientsPrice=0, sides=[], drinks=[], sidePrice=0, drinkPrice=0, status='Not ready'): self._main = main self._mainBun = mainBun self._mainBunNo = mainBunNo self._mainPatty = mainPatty self._mainPattyNo = mainPattyNo self._mainPrice = mainPrice self._ingredients = ingredients self._ingredientsPrice = ingredientsPrice self._sides = sides self._drinks = drinks self._sidePrice = sidePrice self._drinkPrice = drinkPrice self._orderID = random.randint(1, 10) self._status = status self._obj_inventory = Inventory() self._obj_main = Main() if main == 'burger': mainBunList = self._obj_main.bun_type mainQuant = Inventory.mainQuant[mainBunList.index(mainBun)] print( f'Checking inventory... {mainQuant} {mainBun} {main} in stock') print(f'{mainBun} {mainBunNo} buns ordered') else: mainBunList = self._obj_main.bun_type mainQuant = self._obj_inventory.mainQuant[ 2 + mainBunList.index(mainBun)] print(f'Checking inventory... {mainQuant} {mainBun} in stock') print(f'{mainBunNo} buns ordered') pattyList = self._obj_main.patty_type pattyQuant = self._obj_inventory.mainQuant[4 + pattyList.index(mainPatty)] print( f'Checking inventory... {pattyQuant} kg of {mainPatty} patties in sotck' ) print(f'{mainPattyNo} {mainPatty} ordered') if any(ingredients) is True: for i in ingredients: ingredientList = self._obj_inventory.ingredient ingredientQuant = self._obj_inventory.ingredientQuant[ ingredientList.index(i)] print(f'Checking inventory... {ingredientQuant} {i} in stock') if any(sides) is True: for s in sides: sideSplit = s.split(' ') if len(sideSplit) > 1: sideList = self._obj_inventory.side sideOrder = float(sideSplit[0]) sideName = sideSplit[-1] sideQuant = self._obj_inventory.sideQuant[sideList.index( sideName)] if sideName == 'fries': print( f'Checking inventory... {sideQuant} kg of {sideName} in stock' ) print(f'(sideOrder) of {sideName} ordered') else: print( f'Checking inventory... {sideQuant} of {sideName} in stock' ) print(f'{sideOrder} {sideName} ordered') else: print( f'Checking inventory... {sideQuant} of {sideSplit} in stock' ) if any(drinks) is True: for d in drinks: drinkList = self._obj_inventory.side drinkSplit = d.split(' ') drinkName = drinkSplit[-1] drinkType = drinkSplit[1] drinkQuant = self._obj_inventory.sideQuant[drinkList.index( drinkName)] print( f'Checking inventory... {drinkQuant} {drinkType}s of {drinkName} in stock' ) print(f'Here is your order ID: {self._orderID}') print( f'Total cost = ${mainPrice+sidePrice+drinkPrice+ingredientsPrice}')
def order_system(): system = OrderSystem() #read user f = open('user.txt', 'r') lines = f.readlines() for user in lines: up = user.split() r_username = up[0] r_password = up[1] #create user customer = Customer(r_username, r_username + "@gmail.com", r_username, r_password, []) system.add_customer(customer) f.close() #inventory #self, name, quantity, unitprice f2 = open('ingre.txt', 'r') lines = f2.readlines() for line in lines: content = line.split() i_name = content[0] i_quantity = int(content[1]) i_unit = content[2] i_unitPrice = content[3] ingre = Ingredient(i_name, int(i_quantity), i_unit, int(i_unitPrice)) system.add_ingre(ingre) f2.close() #create main menu bur1I1 = Ingredient('Burger', 1, 'Units', 1) burger1 = Main( 'Muffin Burger', 3, 0, ) burger1.add_ingre(bur1I1) burger2 = Main('Sesame Burger', 3, 0) bur2I1 = Ingredient('Burger', 1, 'Units', 1) burger2.add_ingre(bur2I1) wrap1 = Main('Muffin Wrap', 4, 0) wr1I1 = Ingredient('Wrap', 2, 'Units', 1) wrap1.add_ingre(wr1I1) wrap2 = Main('Sesame Wrap', 4, 0) wr2I1 = Ingredient('Wrap', 2, 'Units', 1) wrap2.add_ingre(wr2I1) #create side menu #self, name, unit, quantity, unitPrice) Side1 = Side('3 pack nuggets', 'pack', 0, 6) S1I1 = Ingredient('Nugget', 3, 'Pieces', 2) Side1.add_ingre(S1I1) Side2 = Side('6 pack nuggets', 'pack', 0, 12) S2I1 = Ingredient('Nugget', 6, 'Pieces', 2) Side2.add_ingre(S2I1) Side3 = Side('0.2 kg small fries', 'kg', 0, 2) S3I1 = Ingredient('Fries', 0.2, 'kg', 1) Side3.add_ingre(S3I1) Side4 = Side('0.4 kg medium fries', 'kg', 0, 4) S4I1 = Ingredient('Fries', 0.4, 'kg', 1) Side4.add_ingre(S4I1) Side5 = Side('0.6 kg large fries', 'kg', 0, 6) S5I1 = Ingredient('Fries', 0.6, 'kg', 1) Side5.add_ingre(S5I1) print(system.customerList) system.add_main(burger1) system.add_main(burger2) system.add_main(wrap1) system.add_main(wrap2) system.add_main(Side1) system.add_main(Side2) system.add_main(Side3) system.add_main(Side4) system.add_main(Side5) return system