Best Python code snippet using sure_python
stub_predicate.py
Source:stub_predicate.py
...98 :type equals: object99 """100 self._equals = equals101 @property102 def deep_equals(self):103 """Gets the deep_equals of this StubPredicate. # noqa: E501104 :return: The deep_equals of this StubPredicate. # noqa: E501105 :rtype: object106 """107 return self._deep_equals108 @deep_equals.setter109 def deep_equals(self, deep_equals):110 """Sets the deep_equals of this StubPredicate.111 :param deep_equals: The deep_equals of this StubPredicate. # noqa: E501112 :type deep_equals: object113 """114 self._deep_equals = deep_equals115 @property116 def contains(self):117 """Gets the contains of this StubPredicate. # noqa: E501118 :return: The contains of this StubPredicate. # noqa: E501119 :rtype: object120 """121 return self._contains122 @contains.setter123 def contains(self, contains):...
reader_test.py
Source:reader_test.py
...6import topcoder as tc7class ReaderTest(unittest.TestCase):8 def setUp(self):9 pass10 def test_deep_equals(self):11 self.assertTrue(deep_equals([], []))12 self.assertTrue(deep_equals([123], [123]))13 self.assertFalse(deep_equals([123], [123, 456]))14 self.assertTrue(deep_equals([[123], [1, 2, 3]], [[123], [1, 2, 3]]))15 def test_unsupported_type(self):16 reader = tc.Reader("whatever")17 with self.assertRaises(tc.UnsupportedType):18 reader.next("object")19 def test_read_boolean(self):20 reader = tc.Reader("true")21 flag = reader.next("boolean")22 self.assertEqual(flag, True)23 reader = tc.Reader("false")24 flag = reader.next("boolean")25 self.assertEqual(flag, False)26 def test_read_boolean_error(self):27 reader = tc.Reader("lol")28 with self.assertRaises(tc.ParseError):29 flag = reader.next("boolean")30 def test_read_positive_int(self):31 reader = tc.Reader("20.14")32 number = reader.next("int")33 self.assertEqual(number, 20)34 def test_read_negative_int(self):35 reader = tc.Reader("-1")36 number = reader.next("int")37 self.assertEqual(number, -1)38 def test_read_int_error(self):39 reader = tc.Reader("NaN")40 with self.assertRaises(tc.ParseError):41 number = reader.next("int")42 def test_read_long(self):43 reader = tc.Reader("1234567890123456789")44 number = reader.next("long")45 self.assertEqual(number, 1234567890123456789)46 def test_read_positive_float(self):47 reader = tc.Reader("20.14")48 number = reader.next("float")49 self.assertEqual(number, 20.14)50 def test_read_negative_float(self):51 reader = tc.Reader("-2")52 number = reader.next("float")53 self.assertEqual(number, -2)54 def test_read_quoted_char(self):55 reader = tc.Reader("'@'")56 character = reader.next("char")57 self.assertEqual(character, '@')58 def test_read_unquoted_char(self):59 reader = tc.Reader("@")60 character = reader.next("char")61 self.assertEqual(character, '@')62 def test_read_char_error(self):63 reader = tc.Reader("'@ '")64 with self.assertRaises(tc.ParseError):65 number = reader.next("char")66 def test_read_string(self):67 reader = tc.Reader('"Eddard Stark"')68 name = reader.next("String")69 self.assertEqual(name, "Eddard Stark")70 def test_read_string_error(self):71 reader = tc.Reader('"Eddard Stark')72 with self.assertRaises(tc.ParseError):73 name = reader.next("String")74 reader = tc.Reader('Eddard Stark"')75 with self.assertRaises(tc.ParseError):76 name = reader.next("String")77 def test_read_string_with_quote(self):78 reader = tc.Reader('"Eddard "Ned"", "Stark"')79 name = reader.next("String")80 self.assertEqual(name, 'Eddard "Ned"')81 def test_read_empty_array (self):82 reader = tc.Reader("[]")83 arr = reader.next("int[]")84 def test_read_array(self):85 reader = tc.Reader("[2, 3, 1, 4, 6, 5]")86 arr = reader.next("int[]")87 self.assertTrue(deep_equals(arr, [2, 3, 1, 4, 6, 5]))88 def test_read_array_2d(self):89 reader = tc.Reader('[ ["abc", "def"], ["foo", "bar"] ]')90 arr = reader.next("String[][]")91 self.assertTrue(deep_equals(arr, [["abc", "def"], ["foo", "bar"]]))92 def test_read_everything(self):93 text = """94 [ [ "Jon Snow"95 , "Lord Varys"96 , "The "Little Finger"" ]97 , [ ] ]98 , C, 20.14, fAlSe, 'X'99 , [ -2 , 0 , 1 , 4 ]100 """101 reader = tc.Reader(text)102 self.assertTrue(deep_equals(reader.next("String[][]"), 103 [["Jon Snow", "Lord Varys", 'The "Little Finger"'], []]))104 reader.next()105 self.assertEqual(reader.next("char"), 'C')106 reader.next()107 self.assertEqual(reader.next("double"), 20.14)108 reader.next()109 self.assertEqual(reader.next("boolean"), False)110 reader.next()111 self.assertEqual(reader.next("char"), 'X')112 reader.next()113 self.assertEqual(reader.next("int[]"), [-2, 0, 1, 4])114if __name__ == "__main__":...
deep_equals.py
Source:deep_equals.py
...8__author__ = ["fkiraly"]9__all__ = ["deep_equals"]10import numpy as np11import pandas as pd12def deep_equals(x, y):13 """Test two objects for equality in value.14 Correct if x/y are one of the following valid types:15 types compatible with != comparison16 pd.Series, pd.DataFrame, np.ndarray17 lists, tuples, or dicts of a valid type (recursive)18 Parameters19 ----------20 x: object21 y: object22 Returns23 -------24 bool - True if x and y are equal in value25 x and y do not need to be equal in reference26 """27 if type(x) != type(y):28 return False29 # we now know all types are the same30 # so now we compare values31 if isinstance(x, pd.Series):32 if x.dtype != y.dtype:33 return False34 # if columns are object, recurse over entries and index35 if x.dtype == "object":36 index_equal = x.index.equals(y.index)37 return index_equal and deep_equals(list(x.values), list(y.values))38 else:39 return x.equals(y)40 elif isinstance(x, pd.DataFrame):41 if not x.columns.equals(y.columns):42 return False43 # if columns are equal and at least one is object, recurse over Series44 if sum(x.dtypes == "object") > 0:45 return np.all([deep_equals(x[c], y[c]) for c in x.columns])46 else:47 return x.equals(y)48 elif isinstance(x, np.ndarray):49 if x.dtype != y.dtype:50 return False51 return np.array_equal(x, y, equal_nan=True)52 # recursion through lists, tuples and dicts53 elif isinstance(x, (list, tuple)):54 return _tuple_equals(x, y)55 elif isinstance(x, dict):56 return _dict_equals(x, y)57 elif x != y:58 return False59 return True60def _tuple_equals(x, y):61 """Test two tuples or lists for equality.62 Correct if tuples/lists contain the following valid types:63 types compatible with != comparison64 pd.Series, pd.DataFrame, np.ndarray65 lists, tuples, or dicts of a valid type (recursive)66 Parameters67 ----------68 x: tuple or list69 y: tuple or list70 Returns71 -------72 bool - True if x and y are equal in value73 x and y do not need to be equal in reference74 """75 n = len(x)76 if n != len(y):77 return False78 # we now know dicts are same length79 for i in range(n):80 xi = x[i]81 yi = y[i]82 # recurse through xi/yi83 if not deep_equals(xi, yi):84 return False85 return True86def _dict_equals(x, y):87 """Test two dicts for equality.88 Correct if dicts contain the following valid types:89 types compatible with != comparison90 pd.Series, pd.DataFrame, np.ndarray91 lists, tuples, or dicts of a valid type (recursive)92 Parameters93 ----------94 x: dict95 y: dict96 Returns97 -------98 bool - True if x and y have equal keys and values99 """100 xkeys = set(x.keys())101 ykeys = set(y.keys())102 if xkeys != ykeys:103 return False104 # we now know all keys are the same105 for key in xkeys:106 xi = x[key]107 yi = y[key]108 # recurse through xi/yi109 if not deep_equals(xi, yi):110 return False...
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!!