Best Python code snippet using localstack_python
test_formation.py
Source:test_formation.py
...12class TestCreation(unittest.TestCase):13 def test_creation_empty(self):14 assert creator([]) == []15 def test_creation_single(self):16 created = creator([create_cluster(3, 8, 71, 76, 'a')])17 print(created)18 assert len(created) == 119 assert created[0].location == FeatureLocation(3, 76)20 assert created[0].kind == CandidateCluster.kinds.SINGLE21 def test_creation_neighbours(self):22 cluster = create_cluster(3, 8, 71, 76, 'a')23 extra_cluster = create_cluster(50, 100, 120, 170, 'b')24 created = creator([cluster, extra_cluster])25 print(created)26 assert len(created) == 327 expected_location = FeatureLocation(cluster.location.start,28 extra_cluster.location.end)29 assert created[0].kind == CandidateCluster.kinds.NEIGHBOURING and created[0].location == expected_location30 assert created[1].kind == CandidateCluster.kinds.SINGLE and created[1].location == cluster.location31 assert created[2].kind == CandidateCluster.kinds.SINGLE and created[2].location == extra_cluster.location32 def test_creation_coreoverlap(self):33 cluster = create_cluster(3, 8, 71, 76, 'a')34 extra_cluster = create_cluster(50, 60, 120, 170, 'b')35 # create a CDS within both clusters that has a product from only one cluster36 cds = create_cds(60, 65, ["a"])37 cluster.add_cds(cds)38 extra_cluster.add_cds(cds)39 created = creator([cluster, extra_cluster])40 print(created)41 assert len(created) == 142 candidate_cluster = created[0]43 assert candidate_cluster.kind == CandidateCluster.kinds.INTERLEAVED44 assert candidate_cluster.location == FeatureLocation(3, 170)45 def test_creation_hybrid(self):46 cluster = create_cluster(3, 8, 71, 76, 'a')47 hybrid_cluster = create_cluster(50, 60, 120, 170, 'b')48 # insert the cds that will cause the hybrid call49 cds_ab = create_cds(60, 65, ["a", "b"])50 cluster.add_cds(cds_ab)51 hybrid_cluster.add_cds(cds_ab)52 created = creator([cluster, hybrid_cluster])53 print(created)54 assert len(created) == 155 candidate_cluster = created[0]56 assert candidate_cluster.kind == CandidateCluster.kinds.CHEMICAL_HYBRID57 assert candidate_cluster.location == FeatureLocation(3, 170)58 def test_creation_mixed(self):59 cluster = create_cluster(3, 8, 71, 76, 'a')60 hybrid_cluster = create_cluster(50, 60, 120, 170, 'b')61 overlap_cluster = create_cluster(80, 90, 130, 180, 'o')62 neighbour_cluster = create_cluster(50, 210, 260, 270, 'a')63 isolated_cluster = create_cluster(450, 500, 550, 600, 'alone')64 # insert the cds that will cause the hybrid call65 cds_ab = create_cds(60, 65, ["a", "b"])66 cluster.add_cds(cds_ab)67 hybrid_cluster.add_cds(cds_ab)68 created = creator([cluster, hybrid_cluster, overlap_cluster, neighbour_cluster, isolated_cluster])69 print(created)70 assert len(created) == 571 assert created[0].location == FeatureLocation(3, 270)72 assert created[0].kind == CandidateCluster.kinds.NEIGHBOURING73 assert created[0].protoclusters == (cluster, neighbour_cluster, hybrid_cluster, overlap_cluster)74 assert created[1].location == FeatureLocation(3, 180)75 assert created[1].kind == CandidateCluster.kinds.INTERLEAVED76 assert created[1].protoclusters == (cluster, hybrid_cluster, overlap_cluster)77 assert created[2].location == FeatureLocation(3, 170)78 assert created[2].kind == CandidateCluster.kinds.CHEMICAL_HYBRID79 assert created[2].protoclusters == (cluster, hybrid_cluster)80 assert created[3].location == FeatureLocation(50, 270)81 assert created[3].kind == CandidateCluster.kinds.SINGLE82 assert created[3].protoclusters == (neighbour_cluster,)83 assert created[4].location == FeatureLocation(450, 600)84 assert created[4].kind == CandidateCluster.kinds.SINGLE85 assert created[4].protoclusters == (isolated_cluster,)86 def test_hybrid_interactions(self):87 cluster = create_cluster(3, 8, 171, 176, "a")88 hybrid = create_cluster(3, 8, 50, 55, "b")89 contained = create_cluster(80, 90, 100, 110, "c") # will form part of hybrid90 hybrid_cds = create_cds(8, 50, ["a", "b"])91 cluster.add_cds(hybrid_cds)92 hybrid.add_cds(hybrid_cds)93 for overlapping in [create_cluster(120, 130, 200, 250, "d"),94 create_cluster(60, 70, 200, 250, "d")]:95 created = creator([cluster, hybrid, contained, overlapping])96 assert len(created) == 297 assert created[0].location == FeatureLocation(3, 250)98 assert created[0].kind == CandidateCluster.kinds.INTERLEAVED99 assert created[0].protoclusters == tuple(sorted([cluster, hybrid, contained, overlapping]))100 assert created[1].location == FeatureLocation(3, 176)101 assert created[1].kind == CandidateCluster.kinds.CHEMICAL_HYBRID102 assert created[1].protoclusters == (cluster, hybrid, contained)103 def test_interleaving(self):104 # these first two hybrid clumps should be interleaved105 first_hybrid_clusters = [create_cluster(30, 60, 120, 150, "a"),106 create_cluster(60, 90, 150, 180, "b")]107 cds = create_cds(90, 120, ["a", "b"])108 for cluster in first_hybrid_clusters:109 cluster.add_cds(cds)110 second_hybrid_clusters = [create_cluster(90, 120, 250, 280, "c"),111 create_cluster(190, 220, 280, 310, "d")]112 cds = create_cds(220, 250, ["c", "d"])113 for cluster in second_hybrid_clusters:114 cluster.add_cds(cds)115 # this non-hybrid should also be included in the interleaved116 single = create_cluster(230, 250, 410, 430, "e")117 # this hybrid should not118 standalone = [create_cluster(1000, 1100, 1400, 1500, "f"),119 create_cluster(1100, 1200, 1500, 1600, "g")]120 cds = create_cds(1300, 1400, ["f", "g"])121 for cluster in standalone:122 cluster.add_cds(cds)123 created = creator(first_hybrid_clusters + second_hybrid_clusters + [single] + standalone)124 assert len(created) == 4125 assert created[0].location == FeatureLocation(30, 430)126 assert created[0].core_location == FeatureLocation(60, 410)127 assert created[0].kind == CandidateCluster.kinds.INTERLEAVED128 assert created[0].protoclusters == tuple(first_hybrid_clusters + second_hybrid_clusters + [single])129 assert created[1].location == FeatureLocation(30, 180)130 assert created[1].protoclusters == tuple(first_hybrid_clusters)131 assert created[2].location == FeatureLocation(90, 310)132 assert created[2].protoclusters == tuple(second_hybrid_clusters)133 for cand in created[1:3]:134 assert cand.kind == CandidateCluster.kinds.CHEMICAL_HYBRID135 assert created[3].location == FeatureLocation(1000, 1600)136 assert created[3].kind == CandidateCluster.kinds.CHEMICAL_HYBRID137 def test_interleaving_order(self):138 clusters = [create_cluster(1000, 1100, 1400, 1500, "a"),139 create_cluster(1050, 2000, 3000, 4000, "b"), # sorts second due to neighbouring140 create_cluster(1100, 1200, 1500, 1600, "c")]141 assert sorted(clusters) == clusters142 created = creator(clusters)143 assert len(created) == 3144 assert created[0].kind == CandidateCluster.kinds.NEIGHBOURING145 assert created[0].location == FeatureLocation(1000, 4000)146 assert created[1].kind == CandidateCluster.kinds.INTERLEAVED147 assert created[1].location == FeatureLocation(1000, 1600)148 assert created[2].kind == CandidateCluster.kinds.SINGLE149 assert created[2].location == FeatureLocation(1050, 4000)150 def test_contained_neighbours(self):151 big = create_cluster(0, 100, 130, 230, "a")152 small = create_cluster(10, 20, 30, 40, "b")153 created = creator([big, small])154 assert len(created) == 2155 assert created[0].kind == CandidateCluster.kinds.NEIGHBOURING156 assert created[0].location == big.location157 assert created[1].kind == CandidateCluster.kinds.SINGLE158 assert created[1].location == small.location159 def test_multiple_contained_in_hybrid(self):160 clusters = [161 create_cluster(142916, 162916, 191227, 209850, "a"), # covers whole region162 create_cluster(142916, 162916, 169708, 189708, "b"), # causes chem hybrid163 create_cluster(154261, 174261, 175881, 195881, "c"), # interleaved164 create_cluster(160464, 180464, 183155, 203155, "d"), # interleaved165 ]166 cds = create_cds(162916, 169708, ["a", "b"])167 clusters[0].add_cds(cds)168 clusters[1].add_cds(cds)169 created = creator(clusters)170 assert len(created) == 1171 assert created[0].kind == CandidateCluster.kinds.CHEMICAL_HYBRID...
test_cluster_prediction.py
Source:test_cluster_prediction.py
...19 irrelevant = rule_parser.DetectionRule("irrelevant", 10, 10, DummyConditions())20 self.rules_by_name = {rule.name: rule for rule in [superior, inferior, irrelevant]}21 def remove(self, clusters):22 return cluster_prediction.remove_redundant_clusters(clusters, self.rules_by_name)23 def create_cluster(self, rule_name, start, end):24 rule = self.rules_by_name[rule_name]25 core = FeatureLocation(start, end)26 surrounds = FeatureLocation(max(0, start - rule.extent), end + rule.extent)27 return Cluster(core, surrounds, tool="testing", cutoff=rule.cutoff,28 neighbourhood_range=rule.extent, product=rule_name,29 detection_rule="rule text")30 def test_alone(self):31 clusters = [self.create_cluster("inferior", 101, 110)]32 assert clusters == self.remove(clusters)33 def test_non_overlap(self):34 clusters = [self.create_cluster("inferior", 101, 110),35 self.create_cluster("superior", 200, 210)]36 assert clusters == self.remove(clusters)37 def test_not_relevant_equal(self):38 clusters = [self.create_cluster("inferior", 101, 110),39 self.create_cluster("irrelevant", 101, 110)]40 assert clusters == self.remove(clusters)41 def test_not_relevant_contained(self):42 clusters = [self.create_cluster("inferior", 105, 108),43 self.create_cluster("irrelevant", 101, 110)]44 assert clusters == self.remove(clusters)45 def test_not_relevant_larger(self):46 clusters = [self.create_cluster("inferior", 101, 110),47 self.create_cluster("irrelevant", 105, 108)]48 assert clusters == self.remove(clusters)49 def test_contained(self):50 clusters = [self.create_cluster("inferior", 110, 210),51 self.create_cluster("superior", 101, 310)]52 assert self.remove(clusters) == [clusters[1]]53 def test_equal(self):54 clusters = [self.create_cluster("inferior", 101, 110),55 self.create_cluster("superior", 101, 110)]56 assert self.remove(clusters) == [clusters[1]]57 def test_larger(self):58 clusters = [self.create_cluster("inferior", 101, 110),59 self.create_cluster("superior", 102, 109)]60 print("testing clusters:", clusters)61 assert self.remove(clusters) == clusters62 def test_extents_dont_matter(self):63 extent = self.rules_by_name["superior"].extent64 for new_extent in [extent - 10, extent + 10]:65 self.rules_by_name["inferior"].extent = new_extent66 self.test_larger()67 self.test_equal()68 self.test_contained()69 def test_cutoffs_dont_matter(self):70 cutoff = self.rules_by_name["superior"].cutoff71 for new_cutoff in [cutoff - 10, cutoff + 10]:72 self.rules_by_name["inferior"].cutoff = new_cutoff73 self.test_larger()...
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!!