Best Python code snippet using pytest-django_python
test_cgetnonuis.py
Source:test_cgetnonuis.py  
1import unittest2import test_shared 3"""4This file tests the functionality of the c_getnonuis module. 5"""6import sys7sys.path.append( '..')8sys.path.append( '.')9from nose.plugins.attrib import attr10from srmcollider import collider11from srmcollider.precursor import Precursor12from test_shared import get_non_UIS_from_transitions, getnonuis13try:14    from srmcollider import c_getnonuis15except ImportError:16    print "=" * 75, """17Module c_getnonuis is not available. Please compile it if you want to use it.18""", "=" * 7519@attr('cpp')20class Test_cgetnonuis(unittest.TestCase):21    def setUp(self):22            self.transitions = test_shared.transitions_def123            self.collisions = test_shared.collisions_def124            self.pep1 = test_shared.peptide125            self.pep2 = test_shared.peptide226            self.transitions_12_between300_1500 = test_shared.transitions_12_between300_150027            self.pep1_yseries = test_shared.pep1_yseries28            self.pep1_bseries = test_shared.pep1_bseries29            tuples = []30            tuples.append(self.pep1)31            tuples.append(self.pep2)32            self.tuples = tuple( tuples)33            class Minimal: pass34            self.par = Minimal()35            self.par.q3_window = 4.036            self.par.ppm = False37            self.q3_high = 150038            self.q3_low = 30039            self.par.bions      =  True40            self.par.yions      =  True41            self.par.aions      =  False42            self.par.aMinusNH3  =  False43            self.par.bMinusH2O  =  False44            self.par.bMinusNH3  =  False45            self.par.bPlusH2O   =  False46            self.par.yMinusH2O  =  False47            self.par.yMinusNH3  =  False48            self.par.cions      =  False49            self.par.xions      =  False50            self.par.zions      =  False51            self.par.MMinusH2O      =  False52            self.par.MMinusNH3      =  False53    def test_getnonuis(self):54            q3window = 1.055            ppm = False56            #57            result = getnonuis(self.transitions, self.collisions, q3window, ppm)58            self.assertTrue( result[201] == [1,2] )59            self.assertTrue( result[202] == [1,3] )60            self.assertTrue( result[203] == [1,2,3] )61            self.assertEqual( result, test_shared.refcollperpep1)62            #Test 263            transitions = test_shared.transitions_def264            collisions = test_shared.collisions_def265            result = getnonuis(transitions, collisions, q3window, ppm)66            self.assertTrue( result[201] == [1,2,3] )67            self.assertTrue( result[202] == [2,3,4] )68    def test_get_non_uis1(self):69        for order in range(1,6):70            res = c_getnonuis.get_non_uis(test_shared.refcollperpep1, order)71            res = set( res.keys() )72            self.assertEqual( res, test_shared.refnonuis1[order] )73    def test_get_non_uis2(self):74        for order in range(1,6):75            res = c_getnonuis.get_non_uis(test_shared.refcollperpep2, order)76            res = set( res.keys() )77            self.assertEqual( res, test_shared.refnonuis2_sorted[order] )78    def test_calculate_transitions_regular(self):79            trans = c_getnonuis.calculate_transitions_ch( (self.pep1,), [1,2], 300, 1500)80            self.assertEqual( len(trans), 10)81            for calc, ref in zip(trans, self.transitions_12_between300_1500):82                self.assertTrue(abs(calc[0] - ref) < 1e-3)83    def test_calculate_transitions_modifcation(self):84            trans = c_getnonuis.calculate_transitions_ch( (self.pep2,), [1,2], 300, 1500)85            #TODO check86            self.assertTrue(abs(trans[0][0]) - 909.333 < 1e-3)87            self.assertTrue(abs(trans[1][0]) - 780.290 < 1e-3)88            self.assertTrue(abs(trans[2][0]) - 683.238 < 1e-3)89            self.assertTrue(abs(trans[3][0]) - 523.207 < 1e-3)90            self.assertTrue(abs(trans[4][0]) - 410.123 < 1e-3)91            self.assertTrue(abs(trans[5][0]) - 330.112 < 1e-3)92            self.assertTrue(abs(trans[6][0]) - 490.143 < 1e-3)93            self.assertTrue(abs(trans[7][0]) - 603.227 < 1e-3)94            self.assertTrue(abs(trans[8][0]) - 718.254 < 1e-3)95            self.assertTrue(abs(trans[9][0]) - 865.289 < 1e-3)96            self.assertTrue(abs(trans[10][0]) - 455.170 < 1e-3) 97            self.assertTrue(abs(trans[11][0]) - 390.649 < 1e-3)98            self.assertTrue(abs(trans[12][0]) - 342.122 < 1e-3)99            self.assertTrue(abs(trans[13][0]) - 302.117 < 1e-3)100            self.assertTrue(abs(trans[14][0]) - 359.630 < 1e-3)101            self.assertTrue(abs(trans[15][0]) - 433.148 < 1e-3)102    def test_calculate_transitions_ch_regular(self):103            trans = c_getnonuis.calculate_transitions_ch( (self.pep1,), [1,2], 300, 1500)104            self.assertEqual( len(trans), 10)105            for calc, ref in zip(trans, self.transitions_12_between300_1500):106                self.assertTrue(abs(calc[0] - ref) < 1e-3)107    def test_calculate_transitions_inner(self):108            mypep = self.pep1109            transitions = c_getnonuis.calculate_transitions_ch( (mypep,), [2] , 0, 5000)110            transitions = [t[0] for t in transitions]111            self.assertEqual( len(transitions), 12)112            self.assertEqual( len(transitions), 2*len(mypep[1]) - 2 )113            y_series = transitions[:len(mypep[1])-1]114            b_series = transitions[len(mypep[1])-1:]115            self.assertEqual( len(y_series), 6)116            self.assertEqual( len(b_series), 6)117            for calc, ref in zip(y_series, self.pep1_yseries):118                self.assertTrue(abs(calc - ref) < 1e-3)119            for calc, ref in zip(b_series, self.pep1_bseries):120                self.assertTrue(abs(calc - ref) < 1e-3)121    def test_calculate_calculate_collisions_per_peptide_debug1(self):122            """123            Debug test, if there is something wrong rather not use the big ones.124            Is contained in the big test125            """126            pep = test_shared.runpep1127            transitions = test_shared.runtransitions1128            par = self.par129            q3_high = self.q3_high130            q3_low = self.q3_low131            precursors = [  132                Precursor(q1=449.720582214, modified_sequence='SYVAWDR', transition_group=11498839L, q1_charge=2, isotopically_modified=0)133             ]134            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])135            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 136                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)137            self.assertEqual(collisions_per_peptide,138                             { 11498839: [3]} )139    def test_calculate_calculate_collisions_per_peptide_debug2(self):140            """141            Debug test, if there is something wrong rather not use the big ones.142            Is contained in the big test143            """144            pep = test_shared.runpep1145            transitions = test_shared.runtransitions1146            par = self.par147            q3_high = self.q3_high148            q3_low = self.q3_low149            precursors = [  150                Precursor(q1=450.577779927, modified_sequence='GPGPALAGEPAGSLR', transition_group=10682370L, q1_charge=3, isotopically_modified=0),151            ]152            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])153            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 154                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)155            self.assertEqual(collisions_per_peptide,156                             {10682370: [0, 1, 2, 7, 8, 9, 11],157                             })158    def test_calculate_calculate_collisions_per_peptide_debug1and2(self):159            """160            Debug test, if there is something wrong rather not use the big ones.161            Is contained in the big test162            """163            pep = test_shared.runpep1164            transitions = test_shared.runtransitions1165            par = self.par166            q3_high = self.q3_high167            q3_low = self.q3_low168            precursors = [  169                Precursor(q1=450.577779927, modified_sequence='GPGPALAGEPAGSLR', transition_group=10682370L, q1_charge=3, isotopically_modified=0),170                Precursor(q1=449.720582214, modified_sequence='SYVAWDR', transition_group=11498839L, q1_charge=2, isotopically_modified=0)171             ]172            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])173            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 174                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)175            self.assertEqual(collisions_per_peptide,176                             {10682370: [0, 1, 2, 7, 8, 9, 11],177                              11498839: [3]} )178    def test_calculate_calculate_collisions_per_peptide_1(self):179            pep = test_shared.runpep1180            transitions = test_shared.runtransitions1181            precursors = test_shared.runprecursors_obj1182            par = self.par183            q3_high = self.q3_high184            q3_low = self.q3_low185            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])186            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 187                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)188            self.assertEqual(collisions_per_peptide, test_shared.collpepresult1)189    def test_calculate_calculate_collisions_per_peptide_2(self):190            pep = test_shared.runpep2191            transitions = test_shared.runtransitions2192            precursors = test_shared.runprecursors_obj2193            par = self.par194            q3_high = self.q3_high195            q3_low = self.q3_low196            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])197            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 198                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)199            self.assertEqual(collisions_per_peptide, test_shared.collpepresult2)200    def test_calculate_calculate_collisions_per_peptide_other_ionseries_debug1(self):201            """202            Debug test, if there is something wrong rather not use the big ones.203            Is contained in the big test204            """205            pep = test_shared.runpep1206            transitions = test_shared.runtransitions1207            #precursors = test_shared.runprecursors1208            par = self.par209            q3_high = self.q3_high210            q3_low = self.q3_low211            precursors = [Precursor(modified_sequence='SYVAWDR',212                transition_group=11498839L, isotopically_modified=0, q1_charge=2)] 213            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])214            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 215                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)216            #217            self.assertEqual(collisions_per_peptide,218                             { 11498839: [3]} )219    def test_calculate_calculate_collisions_per_peptide_1_other(self):220            pep = test_shared.runpep1221            transitions = test_shared.runtransitions1222            precursors = test_shared.runprecursors_obj1223            par = self.par224            q3_high = self.q3_high225            q3_low = self.q3_low226            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])227            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 228                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)229            for key in collisions_per_peptide:230                self.assertEqual(collisions_per_peptide[key], test_shared.collpepresult1[key])231            self.assertEqual(len(collisions_per_peptide), len(test_shared.collpepresult1))232            self.assertEqual(collisions_per_peptide, test_shared.collpepresult1)233    def test_calculate_calculate_collisions_per_peptide_2_other(self):234            pep = test_shared.runpep2235            transitions = test_shared.runtransitions2236            precursors = test_shared.runprecursors_obj2237            par = self.par238            q3_high = self.q3_high239            q3_low = self.q3_low240            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])241            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 242                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)243            for key in collisions_per_peptide:244                self.assertEqual(collisions_per_peptide[key], test_shared.collpepresult2[key])245            self.assertEqual(len(collisions_per_peptide), len(test_shared.collpepresult2))246            self.assertEqual(collisions_per_peptide, test_shared.collpepresult2)247    def test_calculate_calculate_collisions_per_peptide_other_ionseries_debug_part1(self):248            """249            Debug test, if there is something wrong rather not use the big ones.250            Is contained in the big test251            """252            pep = test_shared.runpep1253            transitions = test_shared.runtransitions1254            #precursors = test_shared.runprecursors1255            par = self.par256            par.bions      =  True257            par.yions      =  True258            par.aions      =  True259            par.aMinusNH3  =  True260            par.bMinusH2O  =  False261            par.bMinusNH3  =  False262            par.bPlusH2O   =  False263            par.yMinusH2O  =  False264            par.yMinusNH3  =  False265            par.cions      =  False266            par.xions      =  True267            par.zions      =  True268            q3_high = self.q3_high269            q3_low = self.q3_low270            # there is a b3 350.17164  interfering with a y3 347.22949 close to transition 3271            # there is an a4 393.21384                      close to transition 8272            # there is an a4-NH3 393.21384 - 17 = 376.21384 close to transition 11273            # there is an x2 316.12575                      close to transition 9  274            # there is an z3 459.19925                      close to transition 2275            precursors = [Precursor(modified_sequence='SYVAWDR',276                transition_group=11498839L, isotopically_modified=0, q1_charge=2)] 277            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])278            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 279                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)280            #281            self.assertEqual(collisions_per_peptide,282                             { 11498839: [2, 3, 8, 9, 11]} )283    def test_calculate_calculate_collisions_per_peptide_other_ionseries_debug_part2(self):284            """285            Debug test, if there is something wrong rather not use the big ones.286            Is contained in the big test287            """288            pep = test_shared.runpep1289            transitions = test_shared.runtransitions1290            #precursors = test_shared.runprecursors1291            par = self.par292            par.bions      =  False #293            par.yions      =  False #294            par.aions      =  False #295            par.aMinusNH3  =  False #296            par.bMinusH2O  =  False297            par.bMinusNH3  =  False298            par.bPlusH2O   =  True299            par.yMinusH2O  =  True300            par.yMinusNH3  =  False301            par.cions      =  False302            par.xions      =  False #303            par.zions      =  False #304            par.MMinusH2O      =  False305            par.MMinusNH3      =  False306            q3_high = self.q3_high307            q3_low = self.q3_low308            precursors = [Precursor(modified_sequence='SYVAWDR',309                transition_group=11498839L, isotopically_modified=0, q1_charge=2)] 310            transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)])311            collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( 312                transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False)313            #314            self.assertEqual(collisions_per_peptide,315                             { 11498839: [1,2,4, 8, 9 ]} )316    def test_get_charged_mass(self):317            res = c_getnonuis.calculate_charged_mass( (0, 'VASHIPNLK', 1), 1)318            self.assertTrue( abs(res - 978.57368) < 1e-4)319            res = c_getnonuis.calculate_charged_mass( (0, 'VASHIPNLK', 1), 2)320            self.assertTrue( abs(res - 489.79078) < 1e-4)321            res = c_getnonuis.calculate_charged_mass( (0, 'VASHIPNLK', 1), 3)322            self.assertTrue( abs(res - 326.86314) < 1e-4)323            res = c_getnonuis.calculate_charged_mass( (0, 'VASHIPNLK', 1), 4)324            self.assertTrue( abs(res - 245.39932) < 1e-4)325    def test_get_charged_mass(self):326  327      pep = test_shared.runpep2328      transitions = test_shared.runtransitions2329      precursors = test_shared.runprecursors_obj2330      par = self.par331      q3_high = self.q3_high332      q3_low = self.q3_low333      precursors = [ (p.q1, p.modified_sequence, p.transition_group) for p in precursors]334      colldensity = c_getnonuis.calculate_density( 335        tuple(transitions), precursors, q3_low, q3_high, par.q3_window, par.ppm)336      self.assertEqual(colldensity, [1916, 1800, 2601, 3127, 4525, 4975, 3155, 3091, 2127, 3494, 4519, 5546, 4505, 4429, 5604])337@attr('cpp')338class Test_cgetnonuis_get_non_UIS_from_transitions(unittest.TestCase):339    """ Tests the c_getnonuis module over the collider.340    By calling collider.get_non_UIS_from_transitions, we test the function341        * c_getnonuis.get_non_uis342    in tandem.343    """344    def setUp(self):345        class Minimal: pass346        self.par = Minimal()347        self.par.q3_window = 4.0348        self.par.ppm = False349        self.MAX_UIS = 5350    def test_get_non_UIS_from_transitions1(self): 351            self.transitions = test_shared.transitions_def1352            self.collisions  = test_shared.collisions_def1353            newnon_uis = get_non_UIS_from_transitions(self.transitions, 354                self.collisions, self.par, self.MAX_UIS)355            newnon_uis = [set( newn.keys() ) for newn in newnon_uis]356            self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis1)357            self.assertEqual(newnon_uis, test_shared.refnonuis1)358    def test_get_non_UIS_from_transitions2(self): 359            self.transitions = test_shared.transitions_def2360            self.collisions  = test_shared.collisions_def2361            newnon_uis = get_non_UIS_from_transitions(self.transitions, 362                self.collisions, self.par, self.MAX_UIS)363            newnon_uis = [set( newn.keys() ) for newn in newnon_uis]364            self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis2)365            self.assertEqual(newnon_uis, test_shared.refnonuis2_sorted)366    def test_get_non_UIS_from_transitions2_unsorted(self): 367            #here we have the transitions in the wrong order368            #it should still work369            self.transitions = test_shared.transitions_def2_unsorted370            self.collisions  = test_shared.collisions_def2371            newnon_uis = get_non_UIS_from_transitions(self.transitions, 372                self.collisions, self.par, self.MAX_UIS)373            newnon_uis = [set( newn.keys() ) for newn in newnon_uis]374            self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis2)375            self.assertEqual(newnon_uis, test_shared.refnonuis2_unsorted)376    def test_get_non_UIS_from_transitions3(self): 377            self.transitions = test_shared.transitions_def3378            self.collisions  = test_shared.collisions_def3379            newnon_uis = get_non_UIS_from_transitions(self.transitions, 380                self.collisions, self.par, self.MAX_UIS)381            newnon_uis = [set( newn.keys() ) for newn in newnon_uis]382            self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis3)383            self.assertEqual(newnon_uis, test_shared.refnonuis3)384    def test_get_non_UIS_from_transitions4(self): 385            self.transitions = test_shared.transitions_def4386            self.collisions  = test_shared.collisions_def4387            newnon_uis = get_non_UIS_from_transitions(self.transitions, 388                self.collisions, self.par, self.MAX_UIS)389            newnon_uis = [set( newn.keys() ) for newn in newnon_uis]390            self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis4)391            self.assertEqual(newnon_uis, test_shared.refnonuis4)392@attr('cpp')393class Test_three_peptide_example(unittest.TestCase): 394    """395    The target is YYLLDYR with these transitions and numbers396      (842.4412197, 0), y6+397      (679.3778897, 1), y5+398      (566.2938297, 2), y4+399      (453.2097697, 3), y3+400      (440.2185450, 4), b3+401      (553.3026050, 5), b4+402      (668.3295450, 6), b5+403      (831.3928750, 7)  b6+ 404    The peptides GGLIVELGDK b5+ ion interferes with the targets b3+ ion which leads to 665: [4]405    The peptides NGTDGGLQVAIDAMR b9+ ion (842.4008) interferes with the targets y6+ ion406    and also the y11++ ion (565.8035) interferes with the targets y4+ ion which leads to 618: [0, 2].407    """408    def setUp(self):409      import sys410      self.acollider = collider.SRMcollider()411      self.aparamset = collider.testcase()412      self.EPSILON = 10**-5413      par = collider.SRM_parameters()414      par.q1_window = 25 / 2.0415      par.q3_window = 1 / 2.0416      par.ppm = False417      par.q3_low = 400418      par.q3_high = 1400419      par.q3_range = [par.q3_low, par.q3_high]420      par.set_default_vars()421      par.eval()422      self.real_parameters = par423      self.precursor = test_shared.ThreePeptideExample.precursor424      self.interfering_precursors = test_shared.ThreePeptideExample.interfering_precursors425      self.oldstyle_precursors = tuple([(p.q1, p.modified_sequence, p.transition_group, p.q1_charge, p.isotopically_modified) for p in self.interfering_precursors])426    def test_find_clashes_forall_other_series_by(self):427      """ Test how to calculate the transitions of the target428        nonunique = c_getnonuis._find_clashes_forall_other_series( 429            tuple(transitions), tuple(precursors), q3_low, q3_high, 430            par.q3_window, par.ppm, par, q1 - par.q1_window)431      """432      par = self.real_parameters433      q3_low, q3_high = self.real_parameters.get_q3range_transitions()434      precursor = self.precursor435      transitions = precursor.calculate_transitions(q3_low, q3_high)436    437      nonunique = c_getnonuis._find_clashes_forall_other_series( 438        tuple(transitions), self.interfering_precursors, par, q3_low, q3_high,439            par.q3_window, par.ppm, precursor.q1 - par.q1_window, False)440      self.assertEqual( len( nonunique ), 3)441      self.assertEqual( nonunique.keys(), [0,2,4] )442      self.assertTrue( abs(nonunique[0][0][0] - 842.4008) < self.EPSILON )443      self.assertTrue( abs(nonunique[0][0][1] - 506.584613) < self.EPSILON )444      self.assertEqual( nonunique[0][0][2], 0) # empty445      self.assertEqual( nonunique[0][0][3], 618) # peptide key446      self.assertEqual( nonunique[0][0][4], 'b')447      self.assertEqual( nonunique[0][0][5], 9)448      self.assertEqual( nonunique[0][0][6], 'NGTDGGLQVAIDAMR') # sequence449      self.assertEqual( nonunique[0][0][-1], 1) # charge450      self.assertTrue( abs(nonunique[2][0][0] - 565.8035) < self.EPSILON )451      self.assertEqual( nonunique[2][0][4], 'y')452      self.assertEqual( nonunique[2][0][5], 11)453      self.assertEqual( nonunique[2][0][6], 'NGTDGGLQVAIDAMR') # sequence454      self.assertEqual( nonunique[2][0][-1], 2) # charge455      self.assertTrue( abs(nonunique[4][0][0] - 440.287275) < self.EPSILON )456      self.assertTrue( abs(nonunique[4][0][1] - 500.787837374 ) < self.EPSILON )457      self.assertEqual( nonunique[4][0][2], 0) # empty458      self.assertEqual( nonunique[4][0][3], 665) # peptide key459      self.assertEqual( nonunique[4][0][4], 'b')460      self.assertEqual( nonunique[4][0][5], 5)461      self.assertEqual( nonunique[4][0][6], 'GGLIVELGDK') # sequence462      self.assertEqual( nonunique[4][0][-1], 1) # charge463    def test_find_clashes_forall_other_series(self):464      """ Test how to calculate the transitions of the target465        nonunique = c_getnonuis._find_clashes_forall_other_series( 466            tuple(transitions), tuple(precursors), q3_low, q3_high, 467            par.q3_window, par.ppm, par, q1 - par.q1_window)468      """469      par = self.real_parameters470      par.aions = True471      par.xions = True472      par.zions = True473      par.bions = False474      par.yions = False475      #par.bMinusNH3 = True476      #par.bMinusH2O = True477      #par.bPlusH2O = True478      par.q3_window = 4.5479      q3_low, q3_high = self.real_parameters.get_q3range_transitions()480      precursor = self.precursor481      transitions = precursor.calculate_transitions(q3_low, q3_high)482    483      nonunique = c_getnonuis._find_clashes_forall_other_series( 484        tuple(transitions), self.interfering_precursors, par, q3_low, q3_high,485            par.q3_window, par.ppm, precursor.q1 - par.q1_window, False)486      self.assertEqual( len( nonunique ), 4)487      self.assertEqual( nonunique.keys(), [3,4,5,6] )488      self.assertEqual( len( nonunique[3] ), 1)489      self.assertEqual( len( nonunique[4] ), 2)490      self.assertEqual( len( nonunique[5] ), 3)491      self.assertEqual( len( nonunique[6] ), 1)492      # we have one interference with 3493      self.assertTrue( abs(nonunique[3][0][0] - 456.756009652) < self.EPSILON )494      self.assertTrue( abs(nonunique[3][0][1] - 500.787837374) < self.EPSILON )495      self.assertEqual( nonunique[3][0][2], 0) # empty496      self.assertEqual( nonunique[3][0][3], 665) # peptide key497      self.assertEqual( nonunique[3][0][4], 'x')498      self.assertEqual( nonunique[3][0][5], 8)499      self.assertEqual( nonunique[3][0][6], 'GGLIVELGDK') # sequence500      self.assertEqual( nonunique[3][0][-1], 2) # charge501      # we have two interferences with 4502      self.assertTrue( abs(nonunique[4][0][0] - 443.22541272) < self.EPSILON )503      self.assertTrue( abs(nonunique[4][0][1] - 506.58461326) < self.EPSILON )504      self.assertEqual( nonunique[4][0][2], 0) # empty505      self.assertEqual( nonunique[4][0][3], 618) # peptide key506      self.assertEqual( nonunique[4][0][4], 'a')507      self.assertEqual( nonunique[4][0][5], 10)508      self.assertEqual( nonunique[4][0][6], 'NGTDGGLQVAIDAMR') # sequence509      self.assertEqual( nonunique[4][0][-1], 2) # charge510      self.assertTrue( abs(nonunique[4][1][0] - 443.7267378235) < self.EPSILON )511      self.assertTrue( abs(nonunique[4][1][1] - 506.58461326 ) < self.EPSILON )512      self.assertEqual( nonunique[4][1][2], 0) # empty513      self.assertEqual( nonunique[4][1][3], 618) # peptide key514      self.assertEqual( nonunique[4][1][4], 'z')515      self.assertEqual( nonunique[4][1][5], 8)516      self.assertEqual( nonunique[4][1][6], 'NGTDGGLQVAIDAMR') # sequence517      self.assertEqual( nonunique[4][1][-1], 2) # charge518      # we have three interferences with 5519      self.assertTrue( abs(nonunique[5][0][0] - 557.280912722) < self.EPSILON )520      self.assertEqual( nonunique[5][0][4], 'a')521      self.assertEqual( nonunique[5][0][5], 12)522      self.assertEqual( nonunique[5][0][6], 'NGTDGGLQVAIDAMR') # sequence523      self.assertEqual( nonunique[5][0][-1], 2) # charge524      self.assertTrue( abs(nonunique[5][1][0] - 550.28240465) < self.EPSILON )525      self.assertEqual( nonunique[5][1][4], 'x')526      self.assertEqual( nonunique[5][1][5], 10)527      self.assertEqual( nonunique[5][1][6], 'NGTDGGLQVAIDAMR') # sequence528      self.assertEqual( nonunique[5][1][-1], 2) # charge529      self.assertTrue( abs(nonunique[5][2][0] - 557.2902278235) < self.EPSILON )530      self.assertEqual( nonunique[5][2][4], 'z')531      self.assertEqual( nonunique[5][2][5], 11)532      self.assertEqual( nonunique[5][2][6], 'NGTDGGLQVAIDAMR') # sequence533      self.assertEqual( nonunique[5][2][-1], 2) # charge534      # we have one interference with 6535      self.assertTrue( abs(nonunique[6][0][0] - 665.327537823 ) < self.EPSILON )536      self.assertEqual( nonunique[6][0][2], 0) # empty537      self.assertEqual( nonunique[6][0][3], 618) # peptide key538      self.assertEqual( nonunique[6][0][4], 'z')539      self.assertEqual( nonunique[6][0][5], 13)540      self.assertEqual( nonunique[6][0][6], 'NGTDGGLQVAIDAMR') # sequence541      self.assertEqual( nonunique[6][0][-1], 2) # charge542if __name__ == '__main__':...test_loader.py
Source:test_loader.py  
1import unittest2import tempfile3import os4from data import loader5class LoaderTestCase(unittest.TestCase):6    def setUp(self):7        self.data_filenames = [8                os.path.join(os.path.dirname(__file__), "../../test_shared/fixtures/loan_data_a.csv"),9                os.path.join(os.path.dirname(__file__), "../../test_shared/fixtures/loan_data_b.csv"),10                os.path.join(os.path.dirname(__file__), "../../test_shared/fixtures/loan_data_c.csv"),11                os.path.join(os.path.dirname(__file__), "../../test_shared/fixtures/loan_data_large.csv")12            ]13    def test_loans_from_csv_raw(self):14        loans = loader.loans_from_csv_raw(self.data_filenames[0])15        self.assertEqual(len(loans), 6)16        first_loan = loans[0]17        last_loan = loans[5]18        self.assertEqual(first_loan["id"], '1077501')19        self.assertEqual(first_loan["home_ownership"], "RENT")20        self.assertEqual(last_loan["id"], '1075269')21        self.assertEqual(last_loan["policy_code"], '1')22    def test_loans_from_csv(self):23        loans = loader.loans_from_csv(self.data_filenames[0])24        self.assertEqual(len(loans), 6)25        first_loan = loans[0]26        last_loan = loans[5]27        self.assertEqual(first_loan["id"], 1077501)28        self.assertEqual(first_loan["home_ownership"], "RENT")29        self.assertEqual(last_loan["id"], 1075269)30        self.assertEqual(last_loan["policy_code"], 1)31    def test_loan_iter_from_csv(self):32        count = 033        for loan in loader.loan_iter_from_csv(self.data_filenames[0]):34            count +=135        self.assertEqual(count, 6)36    def test_loan_iter_from_csv_large(self):37        count = 038        for loan in loader.loan_iter_from_csv(self.data_filenames[3]):39            count += 140        self.assertEqual(count, 42535)41if __name__ == "__main__":...test_return_by_ref.py
Source:test_return_by_ref.py  
1import return_by_ref2from return_by_ref import Matrix, RowMatrix, Vector3import numpy as np4def test_shared(mat):5  m_ref = mat.ref()6  m_ref.fill(0)7  m_copy = mat.copy()8  assert np.array_equal(m_ref,m_copy)9  m_const_ref = mat.const_ref()10  assert np.array_equal(m_const_ref,m_copy)11  assert np.array_equal(m_const_ref,m_ref)12  m_ref.fill(1)13  assert not np.array_equal(m_ref,m_copy)14  assert np.array_equal(m_const_ref,m_ref)15  try:16    m_const_ref.fill(2)17    assert False18  except:19    assert True20def test_not_shared(mat):21  m_ref = mat.ref()22  m_ref.fill(100.)23  m_copy = mat.copy()24  assert not np.array_equal(m_ref,m_copy)25  m_const_ref = mat.const_ref()26  assert np.array_equal(m_const_ref,m_copy)27  assert not np.array_equal(m_const_ref,m_ref)28  m_ref.fill(10.)29  assert not np.array_equal(m_ref,m_copy)30  assert not np.array_equal(m_const_ref,m_ref)31  try:32    m_const_ref.fill(2)33    assert True34  except:35    assert False36rows = 1037cols = 3038mat = Matrix(rows,cols)39row_mat = RowMatrix(rows,cols)40vec = Vector(rows,1)41test_shared(mat)42test_shared(row_mat)43test_shared(vec)44return_by_ref.sharedMemory(False)45test_not_shared(mat)46test_not_shared(row_mat)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
