How to use _check_attributes method in autotest

Best Python code snippet using autotest_python

test_integration.py

Source:test_integration.py Github

copy

Full Screen

...36class TestManager(FixtureTestCase):37 datasets = [PenData, PencilData, FountainPenData, BallPointPenData]38class TestSpecializedQuerySet(FixtureTestCase):39 datasets = [PenData, PencilData, FountainPenData, BallPointPenData]40 def _check_attributes(self, normal_objects, specialized_objects):41 """42 Helper test to run through the two querysets and43 test various attributes44 """45 for normal_object, specialized_object in zip(46 normal_objects, specialized_objects47 ):48 eq_(normal_object.__class__, WritingImplement)49 assert_not_equal(specialized_object.__class__, WritingImplement)50 compare_generalization_to_specialization(51 normal_object,52 specialized_object53 )54 ok_(isinstance(specialized_object, WritingImplement))55 def test_all(self):56 """Check the all() method works correctly"""57 all_objects = WritingImplement.objects.order_by('name')58 all_specializations = WritingImplement.specializations.order_by('name')59 eq_(len(all_objects), len(all_specializations))60 self._check_attributes(all_objects, all_specializations)61 def test_filter(self):62 """Check the filter() method works correctly"""63 filtered_objects = WritingImplement.objects \64 .filter(length__gte=10) \65 .filter(name__endswith='pen')66 filtered_specializations = WritingImplement.specializations \67 .filter(name__endswith='pen') \68 .filter(length__gte=10)69 self._check_attributes(filtered_objects, filtered_specializations)70 single_filter = WritingImplement.specializations.filter(71 name__endswith='pen', length__gte=1072 )73 eq_(single_filter[0], filtered_specializations[0])74 def test_exclude(self):75 """Check the exclude() method works correctly"""76 excluded_objects = WritingImplement.objects.exclude(length__lt=9)77 excluded_specializations = \78 WritingImplement.specializations.exclude(length__lt=9)79 self._check_attributes(excluded_objects, excluded_specializations)80 def test_slice_index(self):81 """82 Check that querysets can be sliced by a single index value correctly83 """84 all_objects = WritingImplement.objects.order_by('name')85 all_specializations = WritingImplement.specializations.order_by('name')86 eq_(len(all_objects), len(all_specializations))87 for i in range(len(all_objects)):88 o = all_objects[i]89 s = all_specializations[i]90 compare_generalization_to_specialization(o, s)91 def test_slice_range(self):92 """Test various range slices for compatibility"""93 # Two numbers:94 sliced_objects = WritingImplement.objects.order_by('name')[1:4]95 sliced_specializations = \96 WritingImplement.specializations.order_by('name')[1:4]97 self._check_attributes(sliced_objects, sliced_specializations)98 # Just end point:99 sliced_objects = WritingImplement.objects.order_by('length')[:3]100 sliced_specializations = \101 WritingImplement.specializations.order_by('length')[:3]102 self._check_attributes(sliced_objects, sliced_specializations)103 # Just start point:104 sliced_objects = WritingImplement.objects.order_by('-length')[1:]105 sliced_specializations = \106 WritingImplement.specializations.order_by('-length')[1:]107 self._check_attributes(sliced_objects, sliced_specializations)108 def test_order(self):109 """Test various orderings for compatibility"""110 # By name:111 ordered_objects = WritingImplement.objects.order_by('name')112 ordered_specializations = \113 WritingImplement.specializations.order_by('name')114 self._check_attributes(ordered_objects, ordered_specializations)115 # By inverse length and then name:116 ordered_objects = WritingImplement.objects.order_by('-length', 'name')117 ordered_specializations = WritingImplement.specializations.order_by(118 '-length', 'name'119 )120 self._check_attributes(ordered_objects, ordered_specializations)121 def test_get(self):122 """Check that the get() method behaves correctly"""123 general = WritingImplement.objects.get(name=PenData.GeneralPen.name)124 specialized = WritingImplement.specializations.get(125 name=PenData.GeneralPen.name126 )127 self._check_attributes([general], [specialized])128 def test_values(self):129 """Check values returns a ValuesQuerySet in both cases"""130 normal_values = WritingImplement.objects.values('pk', 'name')131 specialized_values = \132 WritingImplement.specializations.values('pk', 'name')133 ok_(isinstance(normal_values, ValuesQuerySet))134 ok_(isinstance(specialized_values, ValuesQuerySet))135 for normal_item, specialized_item in zip(136 normal_values, specialized_values137 ):138 eq_(normal_item['name'], specialized_item['name'])139 eq_(normal_item['pk'], specialized_item['pk'])140 def test_values_list(self):141 """Check values_list returns a ValuesListQuerySet in both cases"""142 normal_values = WritingImplement.objects.values_list('pk', 'length')143 specialized_values = WritingImplement.specializations.values_list(144 'pk', 'length'145 )146 ok_(isinstance(normal_values, ValuesListQuerySet))147 ok_(isinstance(specialized_values, ValuesListQuerySet))148 for (n_pk, n_length), (s_pk, s_length) in zip(149 normal_values, specialized_values150 ):151 eq_(n_pk, s_pk)152 eq_(n_length, s_length)153 def test_flat_values_list(self):154 """155 Check value_list with flat=True returns a ValuesListQuerySet in both156 cases157 """158 normal_values = WritingImplement.objects.values_list('pk', flat=True)159 specialized_values = WritingImplement.specializations.values_list(160 'pk', flat=True161 )162 ok_(isinstance(normal_values, ValuesListQuerySet))163 ok_(isinstance(specialized_values, ValuesListQuerySet))164 eq_(list(normal_values), list(specialized_values))165 def test_aggregate(self):166 """Aggregations work on both types of querysets in the same manner"""167 normal_aggregate = WritingImplement.objects.aggregate(Avg('length'))168 specialized_aggregate = \169 WritingImplement.specializations.aggregate(Avg('length'))170 eq_(normal_aggregate, specialized_aggregate)171 def test_count(self):172 """Counts work over both types of querysets"""173 normal_count = WritingImplement.objects.filter(length__lt=13).count()174 specialized_count = \175 WritingImplement.objects.filter(length__lt=13).count()176 eq_(normal_count, specialized_count)177 def test_in_bulk(self):178 """In bulk works across both types of queryset"""179 ids = list(WritingImplement.objects.values_list('pk', flat=True))[2:]180 normal_bulk = WritingImplement.objects.in_bulk(ids)181 specialized_bulk = WritingImplement.specializations.in_bulk(ids)182 eq_(normal_bulk.keys(), specialized_bulk.keys())183 self._check_attributes(normal_bulk.values(), specialized_bulk.values())184 def test_update(self):185 """update() works the same across querysets"""186 original_lengths = list(187 WritingImplement.objects.order_by('length').values_list(188 'length', flat=True189 )190 )191 WritingImplement.specializations.all().update(length=1+F('length'))192 new_lengths = list(193 WritingImplement.objects.order_by('length').values_list(194 'length', flat=True195 )196 )197 for original_length, new_length in zip(original_lengths, new_lengths):198 eq_(original_length+1, new_length)199 def test_complex_query(self):200 """SpecializedQuerysets can be constructed from Q objects"""201 q_small = Q(length__lt=10)202 q_large = Q(length__gt=13)203 normal_objects = WritingImplement.objects.filter(q_small | q_large)204 specialized_objects = WritingImplement.specializations.filter(205 q_small | q_large206 )...

Full Screen

Full Screen

logic.py

Source:logic.py Github

copy

Full Screen

2import pandas as pd3def _overlapping_period(row, df, start_date, end_date):4 _df = df[df.index != row.name]5 return ~((row[start_date] <= _df[end_date]) & (row[end_date] >= _df[end_date])).any()6def _check_attributes(gdf, attributes):7 for i in attributes:8 if type(i) == str:9 if not i in gdf.columns:10 raise KeyError(fr"'{i}' not in columns: {gdf.columns.to_list()}. Rule cannot be executed")11def LE(gdf, left, right, dtype=bool):12 """13 Evaluate if left is less or equal to/than right14 Parameters15 ----------16 gdf : GeoDataFrame17 Input GeoDataFrame18 left : str, numeric19 Left column or value in expression20 right : TYPE21 Right column or value in expression22 dtype : dtype, optional23 dtype assigned to result Series24 The default is bool.25 Returns26 -------27 result : Series28 Pandas Series (default dtype = bool)29 """30 _check_attributes(gdf, [left, right])31 expression = f"{left} <= {right}".lower()32 return gdf.eval(expression).astype(dtype)33def LT(gdf, left, right, dtype=bool):34 """35 Evaluate if left is less than right36 Parameters37 ----------38 gdf : GeoDataFrame39 Input GeoDataFrame40 left : str, numeric41 Left column or value in expression42 right : TYPE43 Right column or value in expression44 dtype : dtype, optional45 dtype assigned to result Series46 The default is bool.47 Returns48 -------49 result : Series50 Pandas Series (default dtype = bool)51 """52 _check_attributes(gdf, [left, right])53 expression = f"{left} < {right}".lower()54 return gdf.eval(expression).astype(dtype)55def GT(gdf, left, right, dtype=bool):56 """57 Evaluate if left is greater than right58 Parameters59 ----------60 gdf : GeoDataFrame61 Input GeoDataFrame62 left : str, numeric63 Left column or value in expression64 right : TYPE65 Right column or value in expression66 dtype : dtype, optional67 dtype assigned to result Series68 The default is bool.69 Returns70 -------71 result : Series72 Pandas Series (default dtype = bool)73 """74 _check_attributes(gdf, [left, right])75 expression = f"{left} > {right}".lower()76 return gdf.eval(expression).astype(dtype)77def GE(gdf, left, right, dtype=bool):78 """Evaluate if left is greater or equal to/than right79 Parameters80 ----------81 gdf : GeoDataFrame82 Input GeoDataFrame83 left : str, numeric84 Left column or value in expression85 right : TYPE86 Right column or value in expression87 dtype : dtype, optional88 dtype assigned to result Series89 The default is bool.90 Returns91 -------92 result : Series93 Pandas Series (default dtype = bool)94 """95 _check_attributes(gdf, [left, right])96 expression = f"{left} >= {right}".lower()97 return gdf.eval(expression).astype(dtype)98def EQ(gdf, left, right, dtype=bool):99 """Evalate if left an right expression are equal100 Parameters101 ----------102 gdf : GeoDataFrame103 Input GeoDataFrame104 left : str, numeric105 Left column or value in expression106 right : TYPE107 Right column or value in expression108 dtype : dtype, optional109 dtype assigned to result Series110 The default is bool.111 Returns112 -------113 result : Series114 Pandas Series (default dtype = bool)115 """116 _check_attributes(gdf, [left, right])117 expression = f"{left} == {right}".lower()118 return gdf.eval(expression).astype(dtype)119def BE(gdf, parameter, min, max, inclusive=False):120 """Evaluate if parameter-value is between min/max inclusive (true/false)121 Parameters122 ----------123 gdf : GeoDataFrame124 Input GeoDataFrame125 parameter: str126 Input column with numeric values127 min : numeric128 Lower limit of function129 max : numeric130 Upper limit of function131 inclusive : bool, optional132 To include min and max133 The default is False.134 Returns135 -------136 result : Series137 Pandas Series (default dtype = bool)138 """139 _check_attributes(gdf, [parameter, min, max])140 if inclusive:141 series = GE(gdf, parameter, min, dtype=bool) & LE(142 gdf, parameter, max, dtype=bool143 )144 else:145 series = GT(gdf, parameter, min, dtype=bool) & LT(146 gdf, parameter, max, dtype=bool147 )148 return series149def ISIN(gdf, parameter, array):150 """Evaluate if values in parameter are in array151 Parameters152 ----------153 gdf : GeoDataFrame154 Input GeoDataFrame155 parameter: str156 Input column with numeric values157 array : list158 list of possible values that return True159 Returns160 -------161 result : Series162 Pandas Series (default dtype = bool)163 """164 _check_attributes(gdf, [parameter])165 return gdf[parameter].isin(array)166def NOTIN(gdf, parameter, array):167 """Evaluate if values in parameter are not in array168 Parameters169 ----------170 gdf : GeoDataFrame171 Input GeoDataFrame172 parameter: str173 Input column with numeric values174 array : list175 list of possible values that return False176 Returns177 -------178 result : Series179 Pandas Series (default dtype = bool)180 """181 _check_attributes(gdf, [parameter])182 return ~ISIN(gdf, parameter, array)183def NOTNA(gdf, parameter):184 """Evaluate if values in parameter ar not NaN or None185 Parameters186 ----------187 gdf : GeoDataFrame188 Input GeoDataFrame189 parameter: str190 Input column with numeric values191 Returns192 -------193 result : Series194 Pandas Series (default dtype = bool)195 """196 _check_attributes(gdf, [parameter])197 return gdf[parameter].notna()198def join_object_exists(gdf, join_gdf, join_object):199 """Evaluate if defined related_object id exists in globalid parameter of200 related object-table.201 Parameters202 ----------203 gdf : GeoDataFrame204 Input GeoDataFrame205 related_gdf : GeoDataFrame206 Input GeoDataFrame with related objects207 object: str208 HyDAMO object name of related object-layer209 Returns210 -------211 result : Series212 Pandas Series (default dtype = bool)213 """214 _check_attributes(join_gdf, ["globalid"])215 _check_attributes(gdf, [f"{join_object}id"])216 return gdf[f"{join_object}id"].isin(join_gdf["globalid"])217def consistent_period(gdf,218 max_gap=1,219 groupers=["pompid", "regelmiddelid"],220 priority="prioriteit",221 start_date="beginperiode",222 date_format = "%d%m",223 end_date="eindperiode"):224 """Check if a periodic-based table is time-consistent225 Parameters226 ----------227 gdf : GeoDataFrame228 Input GeoDataFrame229 max_gap: int...

Full Screen

Full Screen

ast_walker.py

Source:ast_walker.py Github

copy

Full Screen

...4 self._walk_with_attrs(node, attributes, nodes)5 else:6 self._walk_with_list_of_attrs(node, attributes, nodes)7 def _walk_with_attrs(self, node, attributes, nodes):8 if self._check_attributes(node, attributes):9 nodes.append(node)10 else:11 if "children" in node and node["children"]:12 for child in node["children"]:13 self._walk_with_attrs(child, attributes, nodes)14 def _walk_with_list_of_attrs(self, node, list_of_attributes, nodes):15 if self._check_list_of_attributes(node, list_of_attributes):16 nodes.append(node)17 else:18 if "children" in node and node["children"]:19 for child in node["children"]:20 self._walk_with_list_of_attrs(child, list_of_attributes, nodes)21 def _check_attributes(self, node, attributes):22 for name in attributes:23 if name == "attributes":24 if "attributes" not in node or not self._check_attributes(node["attributes"], attributes["attributes"]):25 return False26 else:27 if name not in node or node[name] != attributes[name]:28 return False29 return True30 def _check_list_of_attributes(self, node, list_of_attributes):31 for attrs in list_of_attributes:32 if self._check_attributes(node, attrs):33 return True...

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