How to use satisfies method in tox

Best Python code snippet using tox_python

spec_semantics.py

Source:spec_semantics.py Github

copy

Full Screen

...23 right = target_factory(argument_spec, False)24 except Exception:25 right = parse_anonymous_spec(argument_spec, left.name)26 return right27def check_satisfies(target_spec, argument_spec, target_concrete=False):28 left = target_factory(target_spec, target_concrete)29 right = argument_factory(argument_spec, left)30 # Satisfies is one-directional.31 assert left.satisfies(right)32 if argument_spec:33 assert left.satisfies(argument_spec)34 # If left satisfies right, then we should be able to constrain35 # right by left. Reverse is not always true.36 right.copy().constrain(left)37def check_unsatisfiable(target_spec, argument_spec, target_concrete=False):38 left = target_factory(target_spec, target_concrete)39 right = argument_factory(argument_spec, left)40 assert not left.satisfies(right)41 assert not left.satisfies(argument_spec)42 with pytest.raises(UnsatisfiableSpecError):43 right.copy().constrain(left)44def check_constrain(expected, spec, constraint):45 exp = Spec(expected)46 spec = Spec(spec)47 constraint = Spec(constraint)48 spec.constrain(constraint)49 assert exp == spec50def check_constrain_changed(spec, constraint):51 spec = Spec(spec)52 assert spec.constrain(constraint)53def check_constrain_not_changed(spec, constraint):54 spec = Spec(spec)55 assert not spec.constrain(constraint)56def check_invalid_constraint(spec, constraint):57 spec = Spec(spec)58 constraint = Spec(constraint)59 with pytest.raises(UnsatisfiableSpecError):60 spec.constrain(constraint)61@pytest.mark.usefixtures('config', 'mock_packages')62class TestSpecSematics(object):63 """This tests satisfies(), constrain() and other semantic operations64 on specs.65 """66 def test_satisfies(self):67 check_satisfies('libelf@0.8.13', '@0:1')68 check_satisfies('libdwarf^libelf@0.8.13', '^libelf@0:1')69 def test_empty_satisfies(self):70 # Basic satisfaction71 check_satisfies('libelf', '')72 check_satisfies('libdwarf', '')73 check_satisfies('%intel', '')74 check_satisfies('^mpi', '')75 check_satisfies('+debug', '')76 check_satisfies('@3:', '')77 # Concrete (strict) satisfaction78 check_satisfies('libelf', '', True)79 check_satisfies('libdwarf', '', True)80 check_satisfies('%intel', '', True)81 check_satisfies('^mpi', '', True)82 # TODO: Variants can't be called concrete while anonymous83 # check_satisfies('+debug', '', True)84 check_satisfies('@3:', '', True)85 # Reverse (non-strict) satisfaction86 check_satisfies('', 'libelf')87 check_satisfies('', 'libdwarf')88 check_satisfies('', '%intel')89 check_satisfies('', '^mpi')90 # TODO: Variant matching is auto-strict91 # we should rethink this92 # check_satisfies('', '+debug')93 check_satisfies('', '@3:')94 def test_satisfies_namespace(self):95 check_satisfies('builtin.mpich', 'mpich')96 check_satisfies('builtin.mock.mpich', 'mpich')97 # TODO: only works for deps now, but shouldn't we allow for root spec?98 # check_satisfies('builtin.mock.mpich', 'mpi')99 check_satisfies('builtin.mock.mpich', 'builtin.mock.mpich')100 check_unsatisfiable('builtin.mock.mpich', 'builtin.mpich')101 def test_satisfies_namespaced_dep(self):102 """Ensure spec from same or unspecified namespace satisfies namespace103 constraint."""104 check_satisfies('mpileaks ^builtin.mock.mpich', '^mpich')105 check_satisfies('mpileaks ^builtin.mock.mpich', '^mpi')106 check_satisfies(107 'mpileaks ^builtin.mock.mpich', '^builtin.mock.mpich')108 check_unsatisfiable(109 'mpileaks ^builtin.mock.mpich', '^builtin.mpich')110 def test_satisfies_compiler(self):111 check_satisfies('foo%gcc', '%gcc')112 check_satisfies('foo%intel', '%intel')113 check_unsatisfiable('foo%intel', '%gcc')114 check_unsatisfiable('foo%intel', '%pgi')115 def test_satisfies_compiler_version(self):116 check_satisfies('foo%gcc', '%gcc@4.7.2')117 check_satisfies('foo%intel', '%intel@4.7.2')118 check_satisfies('foo%pgi@4.5', '%pgi@4.4:4.6')119 check_satisfies('foo@2.0%pgi@4.5', '@1:3%pgi@4.4:4.6')120 check_unsatisfiable('foo%pgi@4.3', '%pgi@4.4:4.6')121 check_unsatisfiable('foo@4.0%pgi', '@1:3%pgi')122 check_unsatisfiable('foo@4.0%pgi@4.5', '@1:3%pgi@4.4:4.6')123 check_satisfies('foo %gcc@4.7.3', '%gcc@4.7')124 check_unsatisfiable('foo %gcc@4.7', '%gcc@4.7.3')125 def test_satisfies_architecture(self):126 check_satisfies(127 'foo platform=test',128 'platform=test')129 check_satisfies(130 'foo platform=linux',131 'platform=linux')132 check_satisfies(133 'foo platform=test',134 'platform=test target=frontend')135 check_satisfies(136 'foo platform=test',137 'platform=test os=frontend target=frontend')138 check_satisfies(139 'foo platform=test os=frontend target=frontend',140 'platform=test')141 check_unsatisfiable(142 'foo platform=linux',143 'platform=test os=redhat6 target=x86_32')144 check_unsatisfiable(145 'foo os=redhat6',146 'platform=test os=debian6 target=x86_64')147 check_unsatisfiable(148 'foo target=x86_64',149 'platform=test os=redhat6 target=x86_32')150 check_satisfies(151 'foo arch=test-None-None',152 'platform=test')153 check_satisfies(154 'foo arch=test-None-frontend',155 'platform=test target=frontend')156 check_satisfies(157 'foo arch=test-frontend-frontend',158 'platform=test os=frontend target=frontend')159 check_satisfies(160 'foo arch=test-frontend-frontend',161 'platform=test')162 check_unsatisfiable(163 'foo arch=test-frontend-frontend',164 'platform=test os=frontend target=backend')165 check_satisfies(166 'foo platform=test target=frontend os=frontend',167 'platform=test target=frontend os=frontend')168 check_satisfies(169 'foo platform=test target=backend os=backend',170 'platform=test target=backend os=backend')171 check_satisfies(172 'foo platform=test target=default_target os=default_os',173 'platform=test os=default_os')174 check_unsatisfiable(175 'foo platform=test target=x86_32 os=redhat6',176 'platform=linux target=x86_32 os=redhat6')177 def test_satisfies_dependencies(self):178 check_satisfies('mpileaks^mpich', '^mpich')179 check_satisfies('mpileaks^zmpi', '^zmpi')180 check_unsatisfiable('mpileaks^mpich', '^zmpi')181 check_unsatisfiable('mpileaks^zmpi', '^mpich')182 def test_satisfies_dependency_versions(self):183 check_satisfies('mpileaks^mpich@2.0', '^mpich@1:3')184 check_unsatisfiable('mpileaks^mpich@1.2', '^mpich@2.0')185 check_satisfies(186 'mpileaks^mpich@2.0^callpath@1.5', '^mpich@1:3^callpath@1.4:1.6')187 check_unsatisfiable(188 'mpileaks^mpich@4.0^callpath@1.5', '^mpich@1:3^callpath@1.4:1.6')189 check_unsatisfiable(190 'mpileaks^mpich@2.0^callpath@1.7', '^mpich@1:3^callpath@1.4:1.6')191 check_unsatisfiable(192 'mpileaks^mpich@4.0^callpath@1.7', '^mpich@1:3^callpath@1.4:1.6')193 def test_satisfies_virtual_dependencies(self):194 check_satisfies('mpileaks^mpi', '^mpi')195 check_satisfies('mpileaks^mpi', '^mpich')196 check_satisfies('mpileaks^mpi', '^zmpi')197 check_unsatisfiable('mpileaks^mpich', '^zmpi')198 def test_satisfies_virtual_dependency_versions(self):199 check_satisfies('mpileaks^mpi@1.5', '^mpi@1.2:1.6')200 check_unsatisfiable('mpileaks^mpi@3', '^mpi@1.2:1.6')201 check_satisfies('mpileaks^mpi@2:', '^mpich')202 check_satisfies('mpileaks^mpi@2:', '^mpich@3.0.4')203 check_satisfies('mpileaks^mpi@2:', '^mpich2@1.4')204 check_satisfies('mpileaks^mpi@1:', '^mpich2')205 check_satisfies('mpileaks^mpi@2:', '^mpich2')206 check_unsatisfiable('mpileaks^mpi@3:', '^mpich2@1.4')207 check_unsatisfiable('mpileaks^mpi@3:', '^mpich2')208 check_unsatisfiable('mpileaks^mpi@3:', '^mpich@1.0')209 def test_satisfies_matching_variant(self):210 check_satisfies('mpich+foo', 'mpich+foo')211 check_satisfies('mpich~foo', 'mpich~foo')212 check_satisfies('mpich foo=1', 'mpich foo=1')213 # confirm that synonymous syntax works correctly214 check_satisfies('mpich+foo', 'mpich foo=True')215 check_satisfies('mpich foo=true', 'mpich+foo')216 check_satisfies('mpich~foo', 'mpich foo=FALSE')217 check_satisfies('mpich foo=False', 'mpich~foo')218 def test_satisfies_multi_value_variant(self):219 # Check quoting220 check_satisfies('multivalue_variant foo="bar,baz"',221 'multivalue_variant foo="bar,baz"')222 check_satisfies('multivalue_variant foo=bar,baz',223 'multivalue_variant foo=bar,baz')224 check_satisfies('multivalue_variant foo="bar,baz"',225 'multivalue_variant foo=bar,baz')226 # A more constrained spec satisfies a less constrained one227 check_satisfies('multivalue_variant foo="bar,baz"',228 'multivalue_variant foo="bar"')229 check_satisfies('multivalue_variant foo="bar,baz"',230 'multivalue_variant foo="baz"')231 check_satisfies('multivalue_variant foo="bar,baz,barbaz"',232 'multivalue_variant foo="bar,baz"')233 check_satisfies('multivalue_variant foo="bar,baz"',234 'foo="bar,baz"')235 check_satisfies('multivalue_variant foo="bar,baz"',236 'foo="bar"')237 def test_satisfies_single_valued_variant(self):238 """Tests that the case reported in239 https://github.com/spack/spack/pull/2386#issuecomment-282147639240 is handled correctly.241 """242 a = Spec('a foobar=bar')243 a.concretize()244 assert a.satisfies('foobar=bar')245 # Assert that an autospec generated from a literal246 # gives the right result for a single valued variant247 assert 'foobar=bar' in a248 assert 'foobar=baz' not in a249 assert 'foobar=fee' not in a250 # ... and for a multi valued variant251 assert 'foo=bar' in a252 # Check that conditional dependencies are treated correctly253 assert '^b' in a254 def test_unsatisfied_single_valued_variant(self):255 a = Spec('a foobar=baz')256 a.concretize()257 assert '^b' not in a258 mv = Spec('multivalue_variant')259 mv.concretize()260 assert 'a@1.0' not in mv261 def test_indirect_unsatisfied_single_valued_variant(self):262 spec = Spec('singlevalue-variant-dependent')263 spec.concretize()264 assert 'a@1.0' not in spec265 def test_unsatisfiable_multi_value_variant(self):266 # Semantics for a multi-valued variant is different267 # Depending on whether the spec is concrete or not268 a = target_factory(269 'multivalue_variant foo="bar"', target_concrete=True270 )271 spec_str = 'multivalue_variant foo="bar,baz"'272 b = Spec(spec_str)273 assert not a.satisfies(b)274 assert not a.satisfies(spec_str)275 # A concrete spec cannot be constrained further276 with pytest.raises(UnsatisfiableSpecError):277 a.constrain(b)278 a = Spec('multivalue_variant foo="bar"')279 spec_str = 'multivalue_variant foo="bar,baz"'280 b = Spec(spec_str)281 # The specs are abstract and they **could** be constrained282 assert a.satisfies(b)283 assert a.satisfies(spec_str)284 # An abstract spec can instead be constrained285 assert a.constrain(b)286 a = target_factory(287 'multivalue_variant foo="bar,baz"', target_concrete=True288 )289 spec_str = 'multivalue_variant foo="bar,baz,quux"'290 b = Spec(spec_str)291 assert not a.satisfies(b)292 assert not a.satisfies(spec_str)293 # A concrete spec cannot be constrained further294 with pytest.raises(UnsatisfiableSpecError):295 a.constrain(b)296 a = Spec('multivalue_variant foo="bar,baz"')297 spec_str = 'multivalue_variant foo="bar,baz,quux"'298 b = Spec(spec_str)299 # The specs are abstract and they **could** be constrained300 assert a.satisfies(b)301 assert a.satisfies(spec_str)302 # An abstract spec can instead be constrained303 assert a.constrain(b)304 # ...but will fail during concretization if there are305 # values in the variant that are not allowed306 with pytest.raises(InvalidVariantValueError):307 a.concretize()308 # This time we'll try to set a single-valued variant309 a = Spec('multivalue_variant fee="bar"')310 spec_str = 'multivalue_variant fee="baz"'311 b = Spec(spec_str)312 # The specs are abstract and they **could** be constrained,313 # as before concretization I don't know which type of variant314 # I have (if it is not a BV)315 assert a.satisfies(b)316 assert a.satisfies(spec_str)317 # A variant cannot be parsed as single-valued until we try to318 # concretize. This means that we can constrain the variant above319 assert a.constrain(b)320 # ...but will fail during concretization if there are321 # multiple values set322 with pytest.raises(MultipleValuesInExclusiveVariantError):323 a.concretize()324 def test_unsatisfiable_variant_types(self):325 # These should fail due to incompatible types326 # FIXME: these needs to be checked as the new relaxed327 # FIXME: semantic makes them fail (constrain does not raise)328 # check_unsatisfiable('multivalue_variant +foo',329 # 'multivalue_variant foo="bar"')330 # check_unsatisfiable('multivalue_variant ~foo',331 # 'multivalue_variant foo="bar"')332 check_unsatisfiable(333 target_spec='multivalue_variant foo="bar"',334 argument_spec='multivalue_variant +foo',335 target_concrete=True336 )337 check_unsatisfiable(338 target_spec='multivalue_variant foo="bar"',339 argument_spec='multivalue_variant ~foo',340 target_concrete=True341 )342 def test_satisfies_unconstrained_variant(self):343 # only asked for mpich, no constraints. Either will do.344 check_satisfies('mpich+foo', 'mpich')345 check_satisfies('mpich~foo', 'mpich')346 check_satisfies('mpich foo=1', 'mpich')347 def test_unsatisfiable_variants(self):348 # This case is different depending on whether the specs are concrete.349 # 'mpich' is not concrete:350 check_satisfies('mpich', 'mpich+foo', False)351 check_satisfies('mpich', 'mpich~foo', False)352 check_satisfies('mpich', 'mpich foo=1', False)353 # 'mpich' is concrete:354 check_unsatisfiable('mpich', 'mpich+foo', True)355 check_unsatisfiable('mpich', 'mpich~foo', True)356 check_unsatisfiable('mpich', 'mpich foo=1', True)357 def test_unsatisfiable_variant_mismatch(self):358 # No matchi in specs359 check_unsatisfiable('mpich~foo', 'mpich+foo')360 check_unsatisfiable('mpich+foo', 'mpich~foo')361 check_unsatisfiable('mpich foo=True', 'mpich foo=False')362 def test_satisfies_matching_compiler_flag(self):363 check_satisfies('mpich cppflags="-O3"', 'mpich cppflags="-O3"')364 check_satisfies(365 'mpich cppflags="-O3 -Wall"', 'mpich cppflags="-O3 -Wall"'366 )367 def test_satisfies_unconstrained_compiler_flag(self):368 # only asked for mpich, no constraints. Any will do.369 check_satisfies('mpich cppflags="-O3"', 'mpich')370 def test_unsatisfiable_compiler_flag(self):371 # This case is different depending on whether the specs are concrete.372 # 'mpich' is not concrete:373 check_satisfies('mpich', 'mpich cppflags="-O3"', False)374 # 'mpich' is concrete:375 check_unsatisfiable('mpich', 'mpich cppflags="-O3"', True)376 def test_copy_satisfies_transitive(self):377 spec = Spec('dttop')378 spec.concretize()379 copy = spec.copy()380 for s in spec.traverse():381 assert s.satisfies(copy[s.name])382 assert copy[s.name].satisfies(s)383 def test_unsatisfiable_compiler_flag_mismatch(self):384 # No matchi in specs385 check_unsatisfiable(386 'mpich cppflags="-O3"', 'mpich cppflags="-O2"')387 def test_satisfies_virtual(self):388 # Don't use check_satisfies: it checks constrain() too, and389 # you can't constrain a non-virtual by a virtual.390 assert Spec('mpich').satisfies(Spec('mpi'))391 assert Spec('mpich2').satisfies(Spec('mpi'))392 assert Spec('zmpi').satisfies(Spec('mpi'))393 def test_satisfies_virtual_dep_with_virtual_constraint(self):394 """Ensure we can satisfy virtual constraints when there are multiple395 vdep providers in the specs."""396 assert Spec('netlib-lapack ^openblas').satisfies(397 'netlib-lapack ^openblas'398 )399 assert not Spec('netlib-lapack ^netlib-blas').satisfies(400 'netlib-lapack ^openblas'401 )402 assert not Spec('netlib-lapack ^openblas').satisfies(403 'netlib-lapack ^netlib-blas'404 )405 assert Spec('netlib-lapack ^netlib-blas').satisfies(406 'netlib-lapack ^netlib-blas'407 )408 def test_satisfies_same_spec_with_different_hash(self):409 """Ensure that concrete specs are matched *exactly* by hash."""410 s1 = Spec('mpileaks').concretized()411 s2 = s1.copy()412 assert s1.satisfies(s2)413 assert s2.satisfies(s1)414 # Simulate specs that were installed before and after a change to415 # Spack's hashing algorithm. This just reverses s2's hash.416 s2._hash = s1.dag_hash()[-1::-1]417 assert not s1.satisfies(s2)418 assert not s2.satisfies(s1)419 # ========================================================================420 # Indexing specs421 # ========================================================================422 def test_self_index(self):423 s = Spec('callpath')424 assert s['callpath'] == s425 def test_dep_index(self):426 s = Spec('callpath')427 s.normalize()428 assert s['callpath'] == s429 assert type(s['dyninst']) == Spec430 assert type(s['libdwarf']) == Spec431 assert type(s['libelf']) == Spec432 assert type(s['mpi']) == Spec...

Full Screen

Full Screen

test_filterable.py

Source:test_filterable.py Github

copy

Full Screen

...12class TestFilterable(BaseTestCase):13 def test_error_raised_when_invalid_filter_name_received(self):14 """Ensure an error is raised when an invalid filter name is provided."""15 with self.assertRaises(exceptions.InvalidInputException):16 FilterableSubclass().satisfies(invalid_filter_name=None)17 def test_error_raised_when_non_existent_attribute_name_received(self):18 """Ensure an error is raised when a non-existent attribute name is used in the filter name."""19 with self.assertRaises(AttributeError):20 FilterableSubclass().satisfies(boogaloo__is_a_dance=True)21 def test_error_raised_when_valid_but_non_existent_filter_name_received(self):22 """Ensure an error is raised when a valid but non-existent filter name is received."""23 with self.assertRaises(exceptions.InvalidInputException):24 FilterableSubclass(age=23).satisfies(age__is_secret=True)25 def test_error_raised_when_attribute_type_has_no_filters_defined(self):26 """Ensure an error is raised when a filter for an attribute whose type doesn't have any filters defined is27 received.28 """29 with self.assertRaises(exceptions.InvalidInputException):30 FilterableSubclass(age=lambda: None).satisfies(age__equals=True)31 def test_error_raised_if_more_than_one_filter_is_provided(self):32 """Test that an error is raised if more than one filter is provided to the satisfies method."""33 with self.assertRaises(ValueError):34 FilterableSubclass(age=23).satisfies(age__equals=23, age__equals__gt=20)35 def test_equals_filter_shortcut(self):36 """Test that the shortcut for simple equals filters works (e.g. `a=7` instead of `a__equals=7`)."""37 self.assertTrue(FilterableSubclass(age=23).satisfies(age=23))38 self.assertFalse(FilterableSubclass(age=23).satisfies(age=32))39 def test_equals_filter_shortcut_with_nested_attributes(self):40 """Test that the shortcut for simple equals filters works for nested attributes e.g. `a__b=7` instead of41 `a__b__equals=7`.42 """43 inner_mock = FilterableSubclass(b=3)44 outer_mock = FilterableSubclass(a=inner_mock)45 filterable_thing = FilterableSubclass(name=outer_mock)46 self.assertTrue(filterable_thing.satisfies(name__a__b=3))47 def test_bool_filters(self):48 """Test that the boolean filters work as expected."""49 filterable_thing = FilterableSubclass(is_alive=True)50 self.assertTrue(filterable_thing.satisfies(is_alive__is=True))51 self.assertFalse(filterable_thing.satisfies(is_alive__is=False))52 self.assertTrue(filterable_thing.satisfies(is_alive__is_not=False))53 self.assertFalse(filterable_thing.satisfies(is_alive__is_not=True))54 self.assertTrue(filterable_thing.satisfies(is_alive__equals=True))55 self.assertFalse(filterable_thing.satisfies(is_alive__equals=False))56 self.assertTrue(filterable_thing.satisfies(is_alive__not_equals=False))57 self.assertFalse(filterable_thing.satisfies(is_alive__not_equals=True))58 def test_str_filters(self):59 """Test that the string filters work as expected."""60 filterable_thing = FilterableSubclass(name="Michael")61 self.assertTrue(filterable_thing.satisfies(name__icontains="m"))62 self.assertFalse(filterable_thing.satisfies(name__icontains="d"))63 self.assertTrue(filterable_thing.satisfies(name__not_icontains="d"))64 self.assertFalse(filterable_thing.satisfies(name__not_icontains="m"))65 self.assertTrue(filterable_thing.satisfies(name__contains="M"))66 self.assertFalse(filterable_thing.satisfies(name__contains="d"))67 self.assertTrue(filterable_thing.satisfies(name__ends_with="l"))68 self.assertFalse(filterable_thing.satisfies(name__ends_with="M"))69 self.assertTrue(filterable_thing.satisfies(name__not_ends_with="M"))70 self.assertFalse(filterable_thing.satisfies(name__not_ends_with="l"))71 self.assertTrue(filterable_thing.satisfies(name__starts_with="M"))72 self.assertFalse(filterable_thing.satisfies(name__starts_with="l"))73 self.assertTrue(filterable_thing.satisfies(name__not_starts_with="l"))74 self.assertFalse(filterable_thing.satisfies(name__not_starts_with="M"))75 self.assertTrue(filterable_thing.satisfies(name__equals="Michael"))76 self.assertFalse(filterable_thing.satisfies(name__equals="Clive"))77 self.assertTrue(filterable_thing.satisfies(name__not_equals="Clive"))78 self.assertFalse(filterable_thing.satisfies(name__not_equals="Michael"))79 self.assertTrue(filterable_thing.satisfies(name__iequals="michael"))80 self.assertFalse(filterable_thing.satisfies(name__iequals="James"))81 self.assertTrue(filterable_thing.satisfies(name__not_iequals="James"))82 self.assertFalse(filterable_thing.satisfies(name__not_iequals="michael"))83 self.assertTrue(filterable_thing.satisfies(name__is="Michael"))84 self.assertFalse(filterable_thing.satisfies(name__is="Clive"))85 self.assertTrue(filterable_thing.satisfies(name__is_not="Clive"))86 self.assertFalse(filterable_thing.satisfies(name__is_not="Michael"))87 self.assertTrue(filterable_thing.satisfies(name__lt="Noel"))88 self.assertFalse(filterable_thing.satisfies(name__lt="Harry"))89 self.assertTrue(filterable_thing.satisfies(name__lte="Michael"))90 self.assertFalse(filterable_thing.satisfies(name__lte="Harry"))91 self.assertTrue(filterable_thing.satisfies(name__gt="Clive"))92 self.assertFalse(filterable_thing.satisfies(name__gt="Noel"))93 self.assertTrue(filterable_thing.satisfies(name__gte="Michael"))94 self.assertFalse(filterable_thing.satisfies(name__gte="Noel"))95 self.assertTrue(filterable_thing.satisfies(name__in_range=("Amy", "Zoe")))96 self.assertFalse(filterable_thing.satisfies(name__in_range=("Noel", "Peter")))97 self.assertTrue(filterable_thing.satisfies(name__not_in_range=("Noel", "Peter")))98 self.assertFalse(filterable_thing.satisfies(name__not_in_range=("Amy", "Zoe")))99 def test_none_filters(self):100 """Test that the None filters work as expected."""101 filterable_thing = FilterableSubclass(owner=None)102 self.assertTrue(filterable_thing.satisfies(owner__is=None))103 self.assertFalse(filterable_thing.satisfies(owner__is=True))104 self.assertTrue(filterable_thing.satisfies(owner__is_not=True))105 self.assertFalse(filterable_thing.satisfies(owner__is_not=None))106 self.assertTrue(filterable_thing.satisfies(owner__equals=None))107 self.assertFalse(filterable_thing.satisfies(owner__equals=True))108 self.assertTrue(filterable_thing.satisfies(owner__not_equals=True))109 self.assertFalse(filterable_thing.satisfies(owner__not_equals=None))110 def test_number_filters_with_integers_and_floats(self):111 """Test that the number filters work as expected for integers and floats."""112 for age in (5, 5.2):113 filterable_thing = FilterableSubclass(age=age)114 self.assertTrue(filterable_thing.satisfies(age__equals=age))115 self.assertFalse(filterable_thing.satisfies(age__equals=63))116 self.assertTrue(filterable_thing.satisfies(age__not_equals=63))117 self.assertFalse(filterable_thing.satisfies(age__not_equals=age))118 self.assertTrue(filterable_thing.satisfies(age__lt=6))119 self.assertFalse(filterable_thing.satisfies(age__lt=0))120 self.assertTrue(filterable_thing.satisfies(age__lte=age))121 self.assertFalse(filterable_thing.satisfies(age__lte=0))122 self.assertTrue(filterable_thing.satisfies(age__gt=4))123 self.assertFalse(filterable_thing.satisfies(age__gt=63))124 self.assertTrue(filterable_thing.satisfies(age__gte=age))125 self.assertFalse(filterable_thing.satisfies(age__gte=63))126 self.assertTrue(filterable_thing.satisfies(age__is=age))127 self.assertFalse(filterable_thing.satisfies(age__is=63))128 self.assertTrue(filterable_thing.satisfies(age__is_not=63))129 self.assertFalse(filterable_thing.satisfies(age__is_not=age))130 self.assertTrue(filterable_thing.satisfies(age__in_range=(0, 10)))131 self.assertFalse(filterable_thing.satisfies(age__in_range=(0, 3)))132 self.assertTrue(filterable_thing.satisfies(age__not_in_range=(0, 3)))133 self.assertFalse(filterable_thing.satisfies(age__not_in_range=(0, 10)))134 def test_iterable_filters(self):135 """Test that the iterable filters work as expected with lists, sets, and tuples."""136 for iterable in ([1, 2, 3], {1, 2, 3}, (1, 2, 3)):137 filterable_thing = FilterableSubclass(iterable=iterable)138 self.assertTrue(filterable_thing.satisfies(iterable__contains=1))139 self.assertFalse(filterable_thing.satisfies(iterable__contains=5))140 self.assertTrue(filterable_thing.satisfies(iterable__not_contains=5))141 self.assertFalse(filterable_thing.satisfies(iterable__not_contains=1))142 self.assertTrue(filterable_thing.satisfies(iterable__is=iterable))143 self.assertFalse(filterable_thing.satisfies(iterable__is=None))144 self.assertTrue(filterable_thing.satisfies(iterable__is_not=None))145 self.assertFalse(filterable_thing.satisfies(iterable__is_not=iterable))146 def test_label_set_filters(self):147 """Test the filters for Labelset."""148 filterable_thing = FilterableSubclass(iterable=LabelSet({"fred", "charlie"}))149 self.assertTrue(filterable_thing.satisfies(iterable__any_label_contains="a"))150 self.assertFalse(filterable_thing.satisfies(iterable__any_label_contains="z"))151 self.assertTrue(filterable_thing.satisfies(iterable__not_any_label_contains="z"))152 self.assertFalse(filterable_thing.satisfies(iterable__not_any_label_contains="a"))153 self.assertTrue(filterable_thing.satisfies(iterable__any_label_starts_with="f"))154 self.assertFalse(filterable_thing.satisfies(iterable__any_label_starts_with="e"))155 self.assertTrue(filterable_thing.satisfies(iterable__any_label_ends_with="e"))156 self.assertFalse(filterable_thing.satisfies(iterable__any_label_ends_with="i"))157 self.assertTrue(filterable_thing.satisfies(iterable__not_any_label_starts_with="e"))158 self.assertFalse(filterable_thing.satisfies(iterable__not_any_label_starts_with="f"))159 self.assertTrue(filterable_thing.satisfies(iterable__not_any_label_ends_with="i"))160 self.assertFalse(filterable_thing.satisfies(iterable__not_any_label_ends_with="e"))161 def test_datetime_filters(self):162 """Test that datetime filters work as expected."""163 my_datetime = datetime(2000, 1, 1)164 filterable_thing = FilterableSubclass(timestamp=my_datetime)165 self.assertTrue(filterable_thing.satisfies(timestamp__equals=my_datetime))166 self.assertFalse(filterable_thing.satisfies(timestamp__equals=datetime(2, 2, 2)))167 self.assertTrue(filterable_thing.satisfies(timestamp__not_equals=datetime(2, 2, 2)))168 self.assertFalse(filterable_thing.satisfies(timestamp__not_equals=my_datetime))169 self.assertTrue(filterable_thing.satisfies(timestamp__is=my_datetime))170 self.assertFalse(filterable_thing.satisfies(timestamp__is=datetime(2, 2, 2)))171 self.assertTrue(filterable_thing.satisfies(timestamp__is_not=datetime(2, 2, 2)))172 self.assertFalse(filterable_thing.satisfies(timestamp__is_not=my_datetime))173 self.assertTrue(filterable_thing.satisfies(timestamp__gt=datetime(1900, 1, 2)))174 self.assertFalse(filterable_thing.satisfies(timestamp__gt=datetime(3000, 1, 2)))175 self.assertTrue(filterable_thing.satisfies(timestamp__gte=my_datetime))176 self.assertFalse(filterable_thing.satisfies(timestamp__gte=datetime(3000, 1, 2)))177 self.assertTrue(filterable_thing.satisfies(timestamp__lt=datetime(3000, 1, 2)))178 self.assertFalse(filterable_thing.satisfies(timestamp__lt=datetime(1990, 1, 2)))179 self.assertTrue(filterable_thing.satisfies(timestamp__lte=my_datetime))180 self.assertFalse(filterable_thing.satisfies(timestamp__lte=datetime(1900, 1, 2)))181 self.assertTrue(filterable_thing.satisfies(timestamp__in_range=(datetime(1900, 1, 2), datetime(3000, 1, 2))))182 self.assertFalse(filterable_thing.satisfies(timestamp__in_range=(datetime(2100, 1, 2), datetime(3000, 1, 2))))183 self.assertTrue(184 filterable_thing.satisfies(timestamp__not_in_range=(datetime(2100, 1, 2), datetime(3000, 1, 2)))185 )186 self.assertFalse(187 filterable_thing.satisfies(timestamp__not_in_range=(datetime(1900, 1, 2), datetime(3000, 1, 2)))188 )189 self.assertTrue(filterable_thing.satisfies(timestamp__year_equals=2000))190 self.assertFalse(filterable_thing.satisfies(timestamp__year_equals=3000))191 self.assertTrue(filterable_thing.satisfies(timestamp__year_in={2000, 3000, 4000}))192 self.assertFalse(filterable_thing.satisfies(timestamp__year_in={3000, 4000}))193 self.assertTrue(filterable_thing.satisfies(timestamp__month_equals=1))194 self.assertFalse(filterable_thing.satisfies(timestamp__month_equals=9))195 self.assertTrue(filterable_thing.satisfies(timestamp__month_in={1, 2, 3}))196 self.assertFalse(filterable_thing.satisfies(timestamp__month_in={2, 3}))197 self.assertTrue(filterable_thing.satisfies(timestamp__day_equals=1))198 self.assertFalse(filterable_thing.satisfies(timestamp__day_equals=2))199 self.assertTrue(filterable_thing.satisfies(timestamp__day_in={1, 2, 3}))200 self.assertFalse(filterable_thing.satisfies(timestamp__day_in={2, 3}))201 self.assertTrue(filterable_thing.satisfies(timestamp__weekday_equals=5))202 self.assertFalse(filterable_thing.satisfies(timestamp__weekday_equals=3))203 self.assertTrue(filterable_thing.satisfies(timestamp__weekday_in={5, 6, 7}))204 self.assertFalse(filterable_thing.satisfies(timestamp__weekday_in={6, 7}))205 self.assertTrue(filterable_thing.satisfies(timestamp__iso_weekday_equals=6))206 self.assertFalse(filterable_thing.satisfies(timestamp__iso_weekday_equals=4))207 self.assertTrue(filterable_thing.satisfies(timestamp__iso_weekday_in={5, 6, 7}))208 self.assertFalse(filterable_thing.satisfies(timestamp__iso_weekday_in={7, 8}))209 self.assertTrue(filterable_thing.satisfies(timestamp__time_equals=time(0, 0, 0)))210 self.assertFalse(filterable_thing.satisfies(timestamp__time_equals=time(1, 2, 3)))211 self.assertTrue(filterable_thing.satisfies(timestamp__hour_equals=0))212 self.assertFalse(filterable_thing.satisfies(timestamp__hour_equals=1))213 self.assertTrue(filterable_thing.satisfies(timestamp__hour_in={0, 1, 2}))214 self.assertFalse(filterable_thing.satisfies(timestamp__hour_in={1, 2}))215 self.assertTrue(filterable_thing.satisfies(timestamp__minute_equals=0))216 self.assertFalse(filterable_thing.satisfies(timestamp__minute_equals=1))217 self.assertTrue(filterable_thing.satisfies(timestamp__minute_in={0, 1, 2}))218 self.assertFalse(filterable_thing.satisfies(timestamp__minute_in={1, 2}))219 self.assertTrue(filterable_thing.satisfies(timestamp__second_equals=0))220 self.assertFalse(filterable_thing.satisfies(timestamp__second_equals=1))221 self.assertTrue(filterable_thing.satisfies(timestamp__second_in={0, 1, 2}))222 self.assertFalse(filterable_thing.satisfies(timestamp__second_in={1, 2}))223 self.assertTrue(filterable_thing.satisfies(timestamp__in_date_range=(date(1000, 1, 4), date(3000, 7, 10))))224 self.assertFalse(filterable_thing.satisfies(timestamp__in_date_range=(date(2000, 1, 4), date(3000, 7, 10))))225 self.assertTrue(filterable_thing.satisfies(timestamp__in_time_range=(time(0, 0, 0), time(13, 2, 22))))226 self.assertFalse(filterable_thing.satisfies(timestamp__in_time_range=(time(0, 0, 1), time(13, 2, 22))))227 def test_filtering_different_attributes_on_same_instance(self):228 """Ensure all filterable attributes on an instance can be checked for filter satisfaction."""229 filterable_thing = FilterableSubclass(name="Fred", is_alive=True, iterable={1, 2, 3}, age=5.2, owner=None)230 self.assertTrue(filterable_thing.satisfies(name__icontains="f"))231 self.assertTrue(filterable_thing.satisfies(name__not_icontains="j"))232 self.assertFalse(filterable_thing.satisfies(is_alive__is=False))233 self.assertTrue(filterable_thing.satisfies(iterable__contains=3))234 self.assertTrue(filterable_thing.satisfies(age__equals=5.2))235 self.assertTrue(filterable_thing.satisfies(age__not_equals=5))236 self.assertTrue(filterable_thing.satisfies(owner__is=None))237 def test_filtering_with_nested_attributes(self):238 """Test that Filterable subclasses can be checked for satisfaction of a filter of nested attributes."""239 inner_mock = Mock(b=3)240 outer_mock = Mock(a=inner_mock)241 filterable_thing = FilterableSubclass(name=outer_mock)242 self.assertTrue(filterable_thing.satisfies(name__a__b__equals=3))243 def test_filtering_with_nested_attributes_ending_in_dictionary_key(self):244 """Test that Filterable subclasses can be checked for satisfaction of a filter of nested attributes that ends245 with a dictionary key.246 """247 filterable_thing = FilterableSubclass(name={"first": "Joe", "last": "Bloggs"})248 self.assertTrue(filterable_thing.satisfies(name__first__equals="Joe"))249 self.assertTrue(filterable_thing.satisfies(name__last__equals="Bloggs"))250 def test_tag_dict_filters(self):251 """Test some filters that apply to a TagDict. These should behave just the same as for a dictionary."""252 filterable_thing = FilterableSubclass(tags=TagDict({"first": "Joe", "middle": "Horatio", "last": "Bloggs"}))253 self.assertTrue(filterable_thing.satisfies(tags__last__lt="Kevin"))...

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