How to use to_not method in Sure

Best Python code snippet using sure_python

expect_to_not_test_suite.py

Source:expect_to_not_test_suite.py Github

copy

Full Screen

1import pytest2from expycted import expect3class Person:4 def __init__(self, name: str, age: int):5 self.name = name6 self.age = age7singleton = None8@pytest.fixture9def get_singleton():10 global singleton11 if singleton is None:12 singleton = Person("John", 30)13 return singleton14@pytest.mark.parametrize(15 "v1,v2,true",16 [17 (1, 2, True),18 (1, 1, False),19 (1, 0, True),20 (0, 0, False),21 (True, "True", True),22 (True, True, False),23 (True, False, True),24 ("string", "another", True),25 ("string", "string", False),26 (1, "1", True),27 (get_singleton, get_singleton, False),28 (get_singleton, Person("John", 30), True),29 ],30)31def test_to_not_equal(v1, v2, true):32 if not true:33 with pytest.raises(AssertionError):34 expect(v1).to_not.equal(v2)35 else:36 expect(v1).to_not.equal(v2)37@pytest.mark.parametrize(38 "v1,v2,true",39 [40 (1, 2, True),41 (1, 1, False),42 (1, 0, True),43 (0, 0, False),44 (True, "True", False),45 (True, True, False),46 (True, False, True),47 ("string", "another", True),48 ("string", "string", False),49 (1, "1", False),50 (get_singleton, get_singleton, False),51 (get_singleton, Person("John", 30), True),52 (1, 1.0, False),53 (2.0, 3, True),54 ],55)56def test_to_not_be(v1, v2, true):57 if not true:58 with pytest.raises(AssertionError):59 expect(v1).to_not.be(v2)60 else:61 expect(v1).to_not.be(v2)62@pytest.mark.parametrize(63 "v1,v2,true",64 [65 ([1], None, True),66 ([2], 2, False),67 (["a", 2], ["b"], True),68 (set(["a", "b"]), "a", False),69 ("abcd", "bc", False),70 ({"a": 1, "b": 2}.values(), 2, False),71 ("True", True, False),72 ("string", "ings", True),73 ("string", "string", False),74 ],75)76def test_to_not_contain(v1, v2, true):77 if not true:78 with pytest.raises(AssertionError):79 expect(v1).to_not.contain(v2)80 else:81 expect(v1).to_not.contain(v2)82@pytest.mark.parametrize(83 "v1,v2,true",84 [85 ([1], None, True),86 ([2], 2, False),87 (["a", 2], ["b"], True),88 (set(["a", "b"]), "a", False),89 ("abcd", "bc", False),90 ({"a": 1, "b": 2}.values(), 2, False),91 ("True", True, False),92 ("string", "ings", True),93 ("string", "string", False),94 (get_singleton, get_singleton, False),95 ],96)97def test_to_not_be_contained_in(v1, v2, true):98 if not true:99 with pytest.raises(AssertionError):100 expect(v2).to_not.be_contained_in(v1)101 else:102 expect(v2).to_not.be_contained_in(v1)103@pytest.mark.parametrize(104 "v1,true",105 [106 ([], False),107 ({}, False),108 (set([]), False),109 ("", False),110 ((), False),111 ("abcd", True),112 ({"a": 1, "b": 2}, True),113 ("True", True),114 ([1, 2], True),115 (set([1, 2]), True),116 ((1, 3), True),117 ],118)119def test_to_not_be_empty(v1, true):120 if not true:121 with pytest.raises(AssertionError):122 expect(v1).to_not.be_empty()123 else:124 expect(v1).to_not.be_empty()125@pytest.mark.parametrize(126 "v1,true",127 [128 (True, False),129 (False, True),130 ([], True),131 (get_singleton, True),132 ],133)134def test_to_not_be_true(v1, true):135 if not true:136 with pytest.raises(AssertionError):137 expect(v1).to_not.be_true()138 else:139 expect(v1).to_not.be_true()140@pytest.mark.parametrize(141 "v1,true",142 [143 (True, True),144 (False, False),145 ([], True),146 (get_singleton, True),147 ],148)149def test_to_not_be_false(v1, true):150 if not true:151 with pytest.raises(AssertionError):152 expect(v1).to_not.be_false()153 else:154 expect(v1).to_not.be_false()155@pytest.mark.parametrize(156 "v1,true",157 [158 (True, False),159 (1, False),160 (get_singleton, False),161 ([1], False),162 ([], True),163 (0, True),164 (False, True),165 ],166)167def test_to_not_be_truthy(v1, true):168 if not true:169 with pytest.raises(AssertionError):170 expect(v1).to_not.be_truthy()171 else:172 expect(v1).to_not.be_truthy()173@pytest.mark.parametrize(174 "v1,true",175 [176 (True, True),177 (1, True),178 (get_singleton, True),179 ([1], True),180 ([], False),181 (0, False),182 (False, False),183 ],184)185def test_to_not_be_falsey(v1, true):186 if not true:187 with pytest.raises(AssertionError):188 expect(v1).to_not.be_falsey()189 else:190 expect(v1).to_not.be_falsey()191@pytest.mark.parametrize(192 "v1,v2,true",193 [194 ([1], list, False),195 (2, int, False),196 ("a", str, False),197 (set(["a", "b"]), set, False),198 ({"a": 1, "b": 2}, dict, False),199 (True, bool, False),200 (Person("John", 30), Person, False),201 (1, int, False),202 (1.0, float, False),203 (Person("John", 30), object, True),204 ("string", "ings", True),205 ("string", int, True),206 (1, str, True),207 (1, float, True),208 (1.0, int, True),209 ],210)211def test_to_not_be_of_type(v1, v2, true):212 if not true:213 with pytest.raises(AssertionError):214 expect(v1).to_not.be_of_type(v2)215 else:216 expect(v1).to_not.be_of_type(v2)217@pytest.mark.parametrize(218 "v1,v2,true",219 [220 ([1], list, False),221 (2, int, False),222 ("a", str, False),223 (set(["a", "b"]), set, False),224 ({"a": 1, "b": 2}, dict, False),225 (True, bool, False),226 (Person("John", 30), Person, False),227 (Person("John", 30), object, False),228 (1, int, False),229 (1.0, float, False),230 ("string", "ings", False),231 ("string", int, True),232 (1, str, True),233 (1, float, True),234 (1.0, int, True),235 ],236)237def test_to_not_inherit(v1, v2, true):238 if not true:239 with pytest.raises(AssertionError):240 expect(v1).to_not.inherit(v2)241 else:242 expect(v1).to_not.inherit(v2)243# NUMERIC TESTS244@pytest.mark.parametrize(245 "v1,v2,true",246 [247 (1, 2, True),248 (3, 2, False),249 (3.2, 1, False),250 (100.1, 100.2, True),251 ([1, 2], [1, 2, 3], True),252 ([1], [2], True),253 (2, 2, True),254 ],255)256def test_to_not_be_greater_than(v1, v2, true):257 if not true:258 with pytest.raises(AssertionError):259 expect(v1).to_not.be_greater_than(v2)260 else:261 expect(v1).to_not.be_greater_than(v2)262@pytest.mark.parametrize(263 "v1,v2,true",264 [265 (1, 2, False),266 (3, 2, True),267 (3.2, 1, True),268 (100.1, 100.2, False),269 ([1, 2], [1, 2, 3], False),270 ([1], [2], False),271 (2, 2, True),272 ],273)274def test_to_not_be_lesser_than(v1, v2, true):275 if not true:276 with pytest.raises(AssertionError):277 expect(v1).to_not.be_lesser_than(v2)278 else:279 expect(v1).to_not.be_lesser_than(v2)280@pytest.mark.parametrize(281 "v1,v2,true",282 [283 (1, 2, True),284 (3, 2, False),285 (3.2, 1, False),286 (100.1, 100.2, True),287 ([1, 2], [1, 2, 3], True),288 ([1], [2], True),289 (2, 2, False),290 ],291)292def test_to_not_be_greater_or_equal_to(v1, v2, true):293 if not true:294 with pytest.raises(AssertionError):295 expect(v1).to_not.be_greater_or_equal_to(v2)296 else:297 expect(v1).to_not.be_greater_or_equal_to(v2)298@pytest.mark.parametrize(299 "v1,v2,true",300 [301 (1, 2, False),302 (3, 2, True),303 (3.2, 1, True),304 (100.1, 100.2, False),305 ([1, 2], [1, 2, 3], False),306 ([1], [2], False),307 (2, 2, False),308 ],309)310def test_to_not_be_lesser_or_equal_to(v1, v2, true):311 if not true:312 with pytest.raises(AssertionError):313 expect(v1).to_not.be_lesser_or_equal_to(v2)314 else:315 expect(v1).to_not.be_lesser_or_equal_to(v2)316@pytest.mark.parametrize(317 "v1,true",318 [319 (1, False),320 (3, False),321 (3.2, False),322 ("a", True),323 ([1, 2], True),324 (set(), True),325 (tuple(), True),326 ("123", False),327 (lambda x: x, True),328 (Person("Fero", 12), True),329 ],330)331def test_to_not_be_numeric(v1, true):332 if not true:333 with pytest.raises(AssertionError):334 expect(v1).to_not.be_numeric()335 else:...

Full Screen

Full Screen

start_end.py

Source:start_end.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import collections3from six.moves import collections_abc4from ..operator import Operator5from ..constants import STR_TYPES6class StarEndBaseOpeartor(Operator):7 # Is the operator a keyword8 kind = Operator.Type.MATCHER9 # Chain aliases10 aliases = (11 'word', 'string', 'number', 'name', 'numbers', 'items',12 'value', 'char', 'letter', 'by', 'character', 'item',13 )14 def match(self, subject, *expected):15 if self.is_unordered_dict(subject):16 return False, ['does not have ordered keys']17 return self.matches(subject, *expected)18 def is_unordered_dict(self, subject):19 if isinstance(subject, collections_abc.Mapping):20 if not hasattr(collections, 'OrderedDict'):21 return True22 return not isinstance(subject, collections.OrderedDict)23 return False24class StartWithOperator(StarEndBaseOpeartor):25 """26 Asserts if a given value starts with a specific items.27 Example::28 # Should style29 'foo' | should.start_with('f')30 'foo' | should.start_with('fo')31 [1, 2, 3] | should.start_with.number(1)32 iter([1, 2, 3]) | should.start_with.numbers(1, 2)33 OrderedDict([('foo', 0), ('bar', 1)]) | should.start_with.item('foo')34 # Should style - negation form35 'foo' | should.do_not.start_with('o')36 'foo' | should.do_not.start_with('o')37 [1, 2, 3] | should.do_not.start_with(2)38 iter([1, 2, 3]) | should.do_not.start_with.numbers(3, 4)39 OrderedDict([('foo', 0), ('bar', 1)]) | should.start_with('bar')40 # Expect style41 'foo' | expect.to.start_with('f')42 'foo' | expect.to.start_with('fo')43 [1, 2, 3] | expect.to.start_with.number(1)44 iter([1, 2, 3]) | expect.to.start_with.numbers(1, 2)45 OrderedDict([('foo', 0), ('bar', 1)]) | expect.to.start_with('foo')46 # Expect style - negation form47 'foo' | expect.to_not.start_with('f')48 'foo' | expect.to_not.start_with('fo')49 [1, 2, 3] | expect.to_not.start_with.number(1)50 iter([1, 2, 3]) | expect.to_not.start_with.numbers(1, 2)51 OrderedDict([('foo', 0), ('bar', 1)]) | expect.to_not.start_with('foo')52 """53 # Operator keywords54 operators = ('start_with', 'starts_with', 'startswith')55 # Expected template message56 expected_message = Operator.Dsl.Message(57 'an object that starts with items "{value}"',58 'an object that does not start with items "{value}"',59 )60 # Subject template message61 subject_message = Operator.Dsl.Message(62 'an object of type "{type}" with value "{value}"',63 )64 def matches(self, subject, *expected):65 if isinstance(subject, STR_TYPES):66 return (67 subject.startswith(expected[0]),68 ['starts with {0!r}'.format(subject[:-len(expected[0])])])69 head = list(subject)[:len(expected)]70 return (71 list(expected) == head,72 ['starts with {0!r}'.format(head)])73class EndWithOperator(StarEndBaseOpeartor):74 """75 Asserts if a given value ends with a specific items.76 Example::77 # Should style78 'foo' | should.ends_with('o')79 'foo' | should.ends_with('oo')80 [1, 2, 3] | should.ends_with.number(3)81 iter([1, 2, 3]) | should.ends_with.numbers(2, 3)82 OrderedDict([('foo', 0), ('bar', 1)]) | should.ends_with.item('bar')83 # Should style - negation form84 'foo' | should.do_not.ends_with('f')85 'foo' | should.do_not.ends_with('o')86 [1, 2, 3] | should.do_not.ends_with(2)87 iter([1, 2, 3]) | should.do_not.ends_with.numbers(3, 4)88 OrderedDict([('foo', 0), ('bar', 1)]) | should.ends_with('foo')89 # Expect style90 'foo' | expect.to.ends_with('o')91 'foo' | expect.to.ends_with('oo')92 [1, 2, 3] | expect.to.ends_with.number(3)93 iter([1, 2, 3]) | expect.to.ends_with.numbers(2, 3)94 OrderedDict([('foo', 0), ('bar', 1)]) | expect.to.ends_with('bar')95 # Expect style - negation form96 'foo' | expect.to_not.ends_with('f')97 'foo' | expect.to_not.ends_with('oo')98 [1, 2, 3] | expect.to_not.ends_with.number(2)99 iter([1, 2, 3]) | expect.to_not.ends_with.numbers(1, 2)100 OrderedDict([('foo', 0), ('bar', 1)]) | expect.to_not.ends_with('foo')101 """102 # Operator keywords103 operators = ('end_with', 'ends_with', 'endswith')104 # Expected template message105 expected_message = Operator.Dsl.Message(106 'an object that ends with items "{value}"',107 'an object that does not end with items "{value}"',108 )109 # Subject template message110 subject_message = Operator.Dsl.Message(111 'an object of type "{type}" with value "{value}"',112 )113 def matches(self, subject, *expected):114 if isinstance(subject, STR_TYPES):115 return (116 subject.endswith(expected[0]),117 ['ends with {0!r}'.format(subject[-len(expected[0]):])])118 tail = list(subject)[-len(expected):]119 return (120 list(expected) == tail,...

Full Screen

Full Screen

type.py

Source:type.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import types3import inspect4from array import array5from ..operator import Operator6# Type alias mappings7MAPPINGS = {8 'string': str,9 'int': int,10 'integer': int,11 'number': int,12 'object': object,13 'float': float,14 'bool': bool,15 'boolean': bool,16 'complex': complex,17 'list': list,18 'dict': dict,19 'dictionary': dict,20 'tuple': tuple,21 'set': set,22 'array': array,23 'lambda': types.LambdaType,24 'generator': types.GeneratorType,25 'asyncgenerator': getattr(types, 'GeneratorType', None),26 'class': 'class',27 'method': 'method',28 'module': 'module',29 'function': 'function',30 'coroutine': 'coroutine',31 'generatorfunction': 'generatorfunction',32 'generator function': 'generatorfunction',33 'coroutinefunction': 'coroutinefunction',34}35class TypeOperator(Operator):36 """37 Asserts if a given object satisfies a type.38 You can use both a type alias string or a ``type`` object.39 Example::40 # Should style41 1 | should.be.an('int')42 1 | should.be.an('number')43 True | should.be.a('bool')44 True | should.be.type(bool)45 'foo' | should.be.a(str)46 'foo' | should.be.a('string')47 [1, 2, 3] | should.be.a('list')48 [1, 2, 3] | should.have.type.of(list)49 (1, 2, 3) | should.be.a('tuple')50 (1, 2, 3) | should.have.type.of(tuple)51 (lamdba x: x) | should.be.a('lambda')52 'foo' | should.be.instance.of('string')53 # Should style - negation form54 1 | should.not_be.an('int')55 1 | should.not_be.an('number')56 True | should.not_be.a('bool')57 True | should.not_be.type(bool)58 'foo' | should.not_be.a(str)59 'foo' | should.not_be.a('string')60 [1, 2, 3] | should.not_be.a('list')61 [1, 2, 3] | should.have_not.type.of(list)62 (1, 2, 3) | should.not_be.a('tuple')63 (1, 2, 3) | should.have_not.type.of(tuple)64 (lamdba x: x) | should.not_be.a('lambda')65 # Expect style66 1 | expect.to.be.an('int')67 1 | expect.to.be.an('number')68 True | expect.to.be.a('bool')69 True | expect.to.be.type(bool)70 'foo' | expect.to.be.a(str)71 'foo' | expect.to.be.a('string')72 [1, 2, 3] | expect.to.be.a('list')73 [1, 2, 3] | expect.to.have.type.of(list)74 (1, 2, 3) | expect.to.be.a('tuple')75 (1, 2, 3) | expect.to.have.type.of(tuple)76 (lamdba x: x) | expect.to.be.a('lambda')77 'foo' | expect.to.be.instance.of('string')78 # Expect style - negation form79 1 | expect.to_not.be.an('int')80 1 | expect.to_not.be.an('number')81 True | expect.to_not.be.a('bool')82 True | expect.to_not.be.type(bool)83 'foo' | expect.to_not.be.a(str)84 'foo' | expect.to_not.be.a('string')85 [1, 2, 3] | expect.to_not.be.a('list')86 [1, 2, 3] | expect.to_not.have.type.of(list)87 (1, 2, 3) | expect.to_not.be.a('tuple')88 (1, 2, 3) | expect.to_not.have.type.of(tuple)89 (lamdba x: x) | expect.to_not.be.a('lambda')90 'foo' | expect.to_not.be.instance.of('string')91 """92 # Is the operator a keyword93 kind = Operator.Type.MATCHER94 # Operator keywords95 operators = ('type', 'types', 'a', 'an', 'instance')96 # Operator chain aliases97 aliases = ('type', 'types', 'of', 'equal', 'to')98 # Subject message template99 expected_message = Operator.Dsl.Message(100 'an object that is a "{value}" type',101 'an object that is not a "{value}" type'102 )103 # Subject template message104 subject_message = Operator.Dsl.Message(105 'an object of type "{type}" with value "{value}"'106 )107 def match(self, value, expected):108 # Custom expectations yielded values109 self.value = type(value).__name__110 self.expected = expected111 # Get type alias112 if type(expected) is str:113 self.expected = expected114 _expected = MAPPINGS.get(expected)115 # Overwrite type value string116 self.expected = _expected117 if not _expected:118 raise ValueError('unsupported type alias: {}'.format(expected))119 if type(_expected) is str:120 return getattr(inspect, 'is{}'.format(expected))(value)121 expected = _expected122 # Check None type123 if expected is None:124 return value is None...

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 Sure 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