Best Python code snippet using assertpy_python
Layout.py
Source:Layout.py  
...65        return count66    def valid_big_hotel(self):67        loc = self.find_first_location('big_hotel')68        if loc != None:69            return (self.is_close_to(loc, 'recreational_area')70                    and not self.is_close_to(loc, 'cemetery')71                    and not self.is_close_to(loc, 'graveyard'))72        else:73            return True74    def valid_recreational_area(self):75        loc = self.find_first_location('recreational_area')76        if loc != None:77            return self.is_close_to(loc, 'lake')78        else:79            return True80    def valid_garbage_dump(self):81        return True82    def valid_housing_complex(self):83        loc = self.find_first_location('housing_complex')84        if loc != None:85            return (self.is_close_to(loc, 'recreational_area')86                    and not self.is_close_to(loc, 'cemetery')87                    and not self.is_close_to(loc, 'graveyard'))88        else:89            return True90    def update_building_location_options(self):91        return (92            self.update_garbage_dump()93            and self.update_recreational_area()94            and self.update_housing_complex()95            and self.update_big_hotel()96        )97    def update_garbage_dump(self):98        if self.find_first_location('garbage_dump') == None:99            return True100        possibilities = []101        for loc in self.next_locations_basic():102            if not(self.is_close_to(loc, 'housing_complex') or self.is_close_to(loc, 'big_hotel')):103                possibilities.append((loc))104        if len(possibilities) > 0:105            self.building_location_options['garbage_dump'] = possibilities106            return True107        else:108            return False109    def update_recreational_area(self):110        if self.find_first_location('recreational_area') == None:111            return True112        possibilities = []113        for loc in self.next_locations_basic():114            if self.is_close_to(loc, 'lake'):115                possibilities.append(loc)116        if len(possibilities) > 0:117            self.building_location_options['recreational_area'] = possibilities118            return True119        else:120            return False121    def update_housing_complex(self):122        if self.find_first_location('housing_complex') == None:123            return True124        possibilities = []125        for loc in self.next_locations_basic():126            if self.is_close_to(loc, 'recreational_area') and not self.is_close_to(loc, 'garbage_dump') and not self.is_close_to(loc, 'cemetery'):127                possibilities.append(loc)128        if len(possibilities) > 0:129            self.building_location_options['housing_complex']130            return True131        else:132            return False133    def update_big_hotel(self):134        if self.find_first_location('big_hotel') == None:135            return True136        possibilities = []137        for loc in self.next_locations_basic():138            if self.is_close_to(loc, 'recreational_area') and not self.is_close_to(loc, 'garbage_dump') and not self.is_close_to(loc, 'cemetery'):139                possibilities.append(loc)140        if len(possibilities) > 0:141            self.building_location_options['big_hotel'] = possibilities142            return True143        else:144            return False145    def get_next_locations(self, building):146        if self.forward_checking:147            return self.next_locations_forward_checking(building)148        else:149            return self.next_locations_basic()150    def next_locations_forward_checking(self, building):151        return self.building_location_options[building]152    def next_locations_basic(self):153        locations = []154        for i in range(3):155            for j in range(3):156                if self.grid[i][j] == None:157                    locations.append((i, j))158        return locations159    def find_first_location(self, target):160        for row in range(3):161            for col in range(3):162                if self.grid[row][col] == target:163                    return (row, col)164        return None165    def is_close_to(self, loc, target):166        for pair in [(-1, 0), (1, 0), (0, -1), (0, 1)]:167            x, y = loc[0] + pair[0], loc[1] + pair[1]168            if self.in_bounds(x, y) and self.grid[x][y] == target:169                return True170        return False171    def in_bounds(self, x, y):172        return (x >= 0 and x < 3 and y >= 0 and y < 3)173    def get_building_options(self):174        if self.forward_checking:175            return self.next_building_forward_checking()176        else:177            return self.next_buildings_basic()178    def next_building_forward_checking(self):179        options = [building for building in self.building_options]...test_confusion_matrix.py
Source:test_confusion_matrix.py  
...23    assert_that(cm.FN.shape[0]).is_equal_to(nsamples + 1)24    assert_that(cm.cutpoint(0.6)).is_equal_to(300)25    TOL = 1e-726    TPR = cm.TP / cm.P27    assert_that(TPR[0]).is_close_to(0.0, TOL)28    assert_that(TPR[460]).is_close_to(0.005, TOL)29    assert_that(TPR[-1]).is_close_to(0.006, TOL)30    tmp = cm.TP / (cm.TP + cm.FN)31    for i in range(cm.tpr.shape[0]):32        assert_that(TPR[i]).is_close_to(tmp[i], TOL)33    TNR = cm.TN / cm.N34    assert_that(TNR[0]).is_close_to(1.0, TOL)35    assert_that(TNR[460]).is_close_to(0.997806880130334, TOL)36    assert_that(TNR[-1]).is_close_to(0.9976188984272197, TOL)37    tmp = cm.TN / (cm.TN + cm.FP)38    for i in range(cm.tnr.shape[0]):39        assert_that(TNR[i]).is_close_to(tmp[i], TOL)40    with errstate(divide="ignore", invalid="ignore"):41        PPV = cm.TP / (cm.TP + cm.FP)42    assert_that(PPV[0]).is_close_to(nan, TOL)43    assert_that(PPV[460]).is_close_to(0.010869565217391304, TOL)44    assert_that(PPV[-1]).is_close_to(0.012, TOL)45    NPV = cm.TN / (cm.TN + cm.FN)46    assert_that(NPV[0]).is_close_to(0.9952030777053442, TOL)47    assert_that(NPV[460]).is_close_to(0.995216507136779, TOL)48    assert_that(NPV[-1]).is_close_to(0.9952203955435237, TOL)49    FNR = cm.FN / cm.P50    assert_that(FNR[0]).is_close_to(1.0, TOL)51    assert_that(FNR[460]).is_close_to(0.995, TOL)52    assert_that(FNR[-1]).is_close_to(0.994, TOL)53    tmp = cm.FN / (cm.FN + cm.TP)54    for i in range(cm.fnr.shape[0]):55        assert_that(FNR[i]).is_close_to(tmp[i], TOL)56    FPR = cm.FP / cm.N57    assert_that(FPR[0]).is_close_to(0.0, TOL)58    assert_that(FPR[460]).is_close_to(0.002193119869666019, TOL)59    assert_that(FPR[-1]).is_close_to(0.0023811015727802495, TOL)60    tmp = cm.FP / (cm.FP + cm.TN)61    for i in range(cm.fpr.shape[0]):62        assert_that(FPR[i]).is_close_to(tmp[i], TOL)63    with errstate(divide="ignore", invalid="ignore"):64        FDR = cm.FP / (cm.FP + cm.TP)65    assert_that(FDR[0]).is_close_to(nan, TOL)66    assert_that(FDR[460]).is_close_to(0.9891304347826086, TOL)67    assert_that(FDR[-1]).is_close_to(0.988, TOL)68    FOR = cm.FN / (cm.FN + cm.TN)69    assert_that(FOR[0]).is_close_to(0.004796922294655749, TOL)70    assert_that(FOR[460]).is_close_to(0.004783492863220949, TOL)71    assert_that(FOR[-1]).is_close_to(0.004779604456476268, TOL)72    ACC = (cm.TP + cm.TN) / (cm.P + cm.N)73    assert_that(ACC[0]).is_close_to(0.9952030777053442, TOL)74    assert_that(ACC[460]).is_close_to(0.9930444626727492, TOL)75    assert_that(ACC[-1]).is_close_to(0.9928621796255522, TOL)76    for i in range(len(cm.sensitivity)):77        assert_that(TPR[i]).is_close_to(cm.sensitivity[i], TOL)78        assert_that(TPR[i]).is_close_to(cm.recall[i], TOL)79        assert_that(TPR[i]).is_close_to(cm.tpr[i], TOL)80    for i in range(len(cm.specificity)):81        assert_that(TNR[i]).is_close_to(cm.specificity[i], TOL)82        assert_that(TNR[i]).is_close_to(cm.selectivity[i], TOL)83        assert_that(TNR[i]).is_close_to(cm.tnr[i], TOL)84    for i in range(len(cm.precision)):85        assert_that(PPV[i]).is_close_to(cm.precision[i], TOL)86        assert_that(PPV[i]).is_close_to(cm.ppv[i], TOL)87        assert_that(TNR[i]).is_close_to(cm.tnr[i], TOL)88    for i in range(len(cm.npv)):89        assert_that(NPV[i]).is_close_to(cm.npv[i], TOL)90    for i in range(len(cm.fnr)):91        assert_that(FNR[i]).is_close_to(cm.miss_rate[i], TOL)92        assert_that(FNR[i]).is_close_to(cm.fnr[i], TOL)93    for i in range(len(cm.fpr)):94        assert_that(FPR[i]).is_close_to(cm.fallout[i], TOL)95        assert_that(FPR[i]).is_close_to(cm.fpr[i], TOL)96    for i in range(len(cm.fdr)):97        assert_that(FDR[i]).is_close_to(cm.fdr[i], TOL)98    for i in range(len(cm.for_)):99        assert_that(FOR[i]).is_close_to(cm.for_[i], TOL)100    for i in range(len(cm.accuracy)):101        assert_that(ACC[i]).is_close_to(cm.accuracy[i], TOL)102def test_confusion_matrix_pr_curve():103    random = RandomState(8)104    ntrues = 1000105    nfalses = 207467106    true_samples = random.choice(ntrues + nfalses, ntrues, False)107    nsamples = 500108    samples = random.choice(ntrues + nfalses, nsamples, False)109    scores = random.randn(nsamples)110    idx = argsort(scores)111    cm = ConfusionMatrix(true_samples, nfalses, samples[idx])112    pr = cm.pr_curve113    assert_that(pr.recall[420]).is_close_to(0.005, TOL)114    assert_that(pr.precision[420]).is_close_to(0.011876484560570071, TOL)115    assert_that(pr.auc).is_close_to(4.98054484430107e-05, TOL)116def test_confusion_matrix_roc_curve():117    random = RandomState(8)118    ntrues = 1000119    nfalses = 207467120    true_samples = random.choice(ntrues + nfalses, ntrues, False)121    nsamples = 500122    samples = random.choice(ntrues + nfalses, nsamples, False)123    scores = random.randn(nsamples)124    idx = argsort(scores)125    cm = ConfusionMatrix(true_samples, nfalses, samples[idx])126    roc = cm.roc_curve127    assert_that(roc.fpr[420]).is_close_to(0.00200031812288215, TOL)128    assert_that(roc.tpr[420]).is_close_to(0.005, TOL)129    assert_that(roc.auc).is_close_to(4.762203145560528e-06, TOL)130def test_confusion_matrix_write_read(tmp_path: Path):131    random = RandomState(2)132    ntrues = 100133    nfalses = 100134    true_samples = random.choice(ntrues + nfalses, ntrues, False)135    nsamples = 100136    samples = random.choice(ntrues + nfalses, nsamples, False)137    scores = random.randn(nsamples)138    idx = argsort(scores)139    pr_auc = 0.22942490919917213140    roc_auc = 0.1277141    cm = ConfusionMatrix(true_samples, nfalses, samples[idx])142    assert_that(cm.pr_curve.auc).is_close_to(pr_auc, TOL)143    assert_that(cm.roc_curve.auc).is_close_to(roc_auc, TOL)144    cm.write_pickle(tmp_path / "cm.pkl")145    cm = ConfusionMatrix.read_pickle(tmp_path / "cm.pkl")146    assert_that(cm.pr_curve.auc).is_close_to(pr_auc, TOL)...test-application-steps.py
Source:test-application-steps.py  
...32    assert_that( counts ).contains_only( count )33    assert_that( incrmts ).contains_only( 1 )34    assert_that( incrids ).contains_only( 1 )35    36    assert_that( sum( sframes ) / len( sframes ) ).is_close_to( step, 2001 )37    assert_that( min( sframes ) ).is_close_to( step, 5001 )38    assert_that( max( sframes ) ).is_close_to( step, 5002 )39    40    assert_that( sum( rframes ) / len( rframes ) ).is_close_to( step, 2002 )41    #assert_that( min( rframes ) ).is_close_to( step, 10001 )42    #assert_that( max( rframes ) ).is_close_to( step, 10002 )43    44    meandrift = sum( drifts ) / len( drifts )45    assert_that( meandrift ).is_less_than( 100003 )46    assert_that( min( drifts ) ).is_close_to( meandrift, 20001 )47    assert_that( max( drifts ) ).is_close_to( meandrift, 20002 )...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!!
