Best Python code snippet using localstack_python
test_filters.py
Source:test_filters.py
...40 # Period 2, day 21, you would sync February 21-March 20th41 def test_may15_period0(self):42 with patch_today(*MAY_15):43 filter_ = CustomMonthFilter(start_of_month=21, period=0)44 date_span = filter_.get_filter_value(user=None, ui_filter=None)45 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=4, day=21))46 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=5, day=20))47 def test_may15_period1(self):48 with patch_today(*MAY_15):49 filter_ = CustomMonthFilter(start_of_month=21, period=1)50 date_span = filter_.get_filter_value(user=None, ui_filter=None)51 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=3, day=21))52 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=4, day=20))53 def test_may15_period2(self):54 with patch_today(*MAY_15):55 filter_ = CustomMonthFilter(start_of_month=21, period=2)56 date_span = filter_.get_filter_value(user=None, ui_filter=None)57 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=2, day=21))58 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=3, day=20))59 # Assume it was May 20:60 # Period 0, day 21, you would sync April 21-May 20th61 # Period 1, day 21, you would sync March 21-April 20th62 # Period 2, day 21, you would sync February 21-March 20th63 def test_may20_period0(self):64 with patch_today(*MAY_20):65 filter_ = CustomMonthFilter(start_of_month=21, period=0)66 date_span = filter_.get_filter_value(user=None, ui_filter=None)67 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=4, day=21))68 self.assertEqual(date_span.enddate, self.date_class(*MAY_20))69 def test_may20_period1(self):70 with patch_today(*MAY_20):71 filter_ = CustomMonthFilter(start_of_month=21, period=1)72 date_span = filter_.get_filter_value(user=None, ui_filter=None)73 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=3, day=21))74 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=4, day=20))75 def test_may20_period2(self):76 with patch_today(*MAY_20):77 filter_ = CustomMonthFilter(start_of_month=21, period=2)78 date_span = filter_.get_filter_value(user=None, ui_filter=None)79 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=2, day=21))80 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=3, day=20))81 # Assume it was May 21:82 # Period 0, day 21, you would sync May 21-June 20th83 # Period 1, day 21, you would sync April 21-May 20th84 # Period 2, day 21, you would sync March 21-April 20th85 def test_may21_period0(self):86 with patch_today(*MAY_21):87 filter_ = CustomMonthFilter(start_of_month=21, period=0)88 date_span = filter_.get_filter_value(user=None, ui_filter=None)89 self.assertEqual(date_span.startdate, self.date_class(*MAY_21))90 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=6, day=20))91 def test_may21_period1(self):92 with patch_today(*MAY_21):93 filter_ = CustomMonthFilter(start_of_month=21, period=1)94 date_span = filter_.get_filter_value(user=None, ui_filter=None)95 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=4, day=21))96 self.assertEqual(date_span.enddate, self.date_class(*MAY_20))97 def test_may21_period2(self):98 with patch_today(*MAY_21):99 filter_ = CustomMonthFilter(start_of_month=21, period=2)100 date_span = filter_.get_filter_value(user=None, ui_filter=None)101 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=3, day=21))102 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=4, day=20))103 # May 15 for 10 days from the end of the month (start_of_month = -10):104 # Period 0, day 21, you would sync April 20-May 20th105 # Period 1, day 21, you would sync March 21-April 19th106 # Period 2, day 21, you would sync February 18-March 20th107 def test_may15_minus10_period0(self):108 with patch_today(*MAY_15):109 filter_ = CustomMonthFilter(start_of_month=-10, period=0)110 date_span = filter_.get_filter_value(user=None, ui_filter=None)111 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=4, day=20))112 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=5, day=20))113 def test_may15_minus10_period1(self):114 with patch_today(*MAY_15):115 filter_ = CustomMonthFilter(start_of_month=-10, period=1)116 date_span = filter_.get_filter_value(user=None, ui_filter=None)117 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=3, day=21))118 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=4, day=19))119 def test_may15_minus10_period2(self):120 with patch_today(*MAY_15):121 filter_ = CustomMonthFilter(start_of_month=-10, period=2)122 date_span = filter_.get_filter_value(user=None, ui_filter=None)123 self.assertEqual(date_span.startdate, self.date_class(year=2015, month=2, day=18))124 self.assertEqual(date_span.enddate, self.date_class(year=2015, month=3, day=20))125class AutoFilterTests(TestCase):126 @classmethod127 def setUpClass(cls):128 super(AutoFilterTests, cls).setUpClass()129 cls.domain = Domain(name=DOMAIN)130 cls.domain.save()131 cls.country = LocationType(domain=DOMAIN, name='country')132 cls.country.save()133 cls.state = LocationType(134 domain=DOMAIN,135 name='state',136 parent_type=cls.country,137 )138 cls.state.save()139 cls.city = LocationType(140 domain=DOMAIN,141 name='city',142 parent_type=cls.state,143 shares_cases=True,144 )145 cls.city.save()146 cls.usa = SQLLocation(147 domain=DOMAIN,148 name='The United States of America',149 site_code='usa',150 location_type=cls.country,151 )152 cls.usa.save()153 cls.massachusetts = SQLLocation(154 domain=DOMAIN,155 name='Massachusetts',156 site_code='massachusetts',157 location_type=cls.state,158 parent=cls.usa,159 )160 cls.massachusetts.save()161 cls.new_york = SQLLocation(162 domain=DOMAIN,163 name='New York',164 site_code='new_york',165 location_type=cls.state,166 parent=cls.usa,167 )168 cls.new_york.save()169 cls.cambridge = SQLLocation(170 domain=DOMAIN,171 name='Cambridge',172 site_code='cambridge',173 location_type=cls.city,174 parent=cls.massachusetts,175 )176 cls.cambridge.save()177 cls.somerville = SQLLocation(178 domain=DOMAIN,179 name='Somerville',180 site_code='somerville',181 location_type=cls.city,182 parent=cls.massachusetts,183 )184 cls.somerville.save()185 cls.nyc = SQLLocation(186 domain=DOMAIN,187 name='New York City',188 site_code='nyc',189 location_type=cls.city,190 parent=cls.new_york,191 )192 cls.nyc.save()193 cls.drew = CommCareUser(194 domain=DOMAIN,195 username='drew',196 location_id=cls.nyc.location_id,197 assigned_location_ids=[cls.nyc.location_id],198 )199 cls.jon = CommCareUser(200 domain=DOMAIN,201 username='jon',202 location_id=cls.cambridge.location_id,203 assigned_location_ids=[cls.cambridge.location_id],204 )205 cls.nate = CommCareUser(206 domain=DOMAIN,207 username='nate',208 location_id=cls.somerville.location_id,209 assigned_location_ids=[cls.somerville.location_id],210 )211 cls.sheel = CommCareUser(212 domain=DOMAIN,213 username='sheel',214 location_id=cls.somerville.location_id,215 assigned_location_ids=[cls.somerville.location_id],216 last_login=datetime.datetime.now(),217 date_joined=datetime.datetime.now(),218 )219 cls.sheel.save()220 def setUp(self):221 self.ui_filter = Mock()222 self.ui_filter.name = 'test_filter'223 self.ui_filter.value.return_value = 'result'224 @classmethod225 def tearDownClass(cls):226 cls.sheel.delete()227 cls.nyc.delete()228 cls.somerville.delete()229 cls.cambridge.delete()230 cls.new_york.delete()231 cls.massachusetts.delete()232 cls.usa.delete()233 cls.city.delete()234 cls.state.delete()235 cls.country.delete()236 cls.domain.delete()237 super(AutoFilterTests, cls).tearDownClass()238 def test_filter_by_case_sharing_group_id(self):239 result = _filter_by_case_sharing_group_id(self.sheel, None)240 self.assertEqual(result, [Choice(value=self.somerville.location_id, display=None)])241 def test_filter_by_location_id(self):242 result = _filter_by_location_id(self.drew, self.ui_filter)243 self.ui_filter.value.assert_called_with(test_filter=self.nyc.location_id,244 request_user=self.drew)245 self.assertEqual(result, 'result')246 def test_filter_by_parent_location_id(self):247 result = _filter_by_parent_location_id(self.jon, self.ui_filter)248 self.ui_filter.value.assert_called_with(test_filter=self.massachusetts.location_id,249 request_user=self.jon)250 self.assertEqual(result, 'result')251 def test_filter_by_username(self):252 result = _filter_by_username(self.sheel, None)253 self.assertEqual(result, Choice(value='sheel', display=None))254 def test_filter_by_user_id(self):255 result = _filter_by_user_id(self.sheel, None)256 self.assertEqual(result, Choice(value=self.sheel._id, display=None))257 def _get_dynamic_choice_list_ui_filter(self):258 return DynamicChoiceListFilter(259 "my name",260 "my_field",261 "string",262 "my label",263 True,264 dynamic_choice_list_url,265 DataSourceColumnChoiceProvider(None, None)266 )267 # AncestorLocationTypeFilter is not an AutoFilter, but we'll hitch a ride here to reuse setup and teardown268 def test_ancestor_location_type_filter(self):269 ucr_filter = AncestorLocationTypeFilter(ancestor_location_type_name='state')270 ui_filter = self._get_dynamic_choice_list_ui_filter()271 ancestor_state_value = ucr_filter.get_filter_value(self.nate, ui_filter)272 self.assertEqual(273 ancestor_state_value,274 [Choice(275 value=self.massachusetts.location_id,276 display=self.massachusetts.location_id277 )]278 )279 def test_ancestor_location_type_filter_with_no_location_found(self):280 ucr_filter = AncestorLocationTypeFilter(ancestor_location_type_name='banana')281 ui_filter = self._get_dynamic_choice_list_ui_filter()282 ancestor_state_value = ucr_filter.get_filter_value(self.nate, ui_filter)283 self.assertEqual(ancestor_state_value, ui_filter.default_value())284class NumericFilterTests(TestCase):285 def test_numeric_filter(self):286 self.assertEqual(287 NumericFilter.wrap({'operator': '>', 'operand': '1.5'}).get_filter_value(None, None),288 {'operator': '>', 'operand': 1.5}...
telescope.py
Source:telescope.py
...8 def list_focusing_configurations(self, focuser_name, cfw_name):9 return self.equipment_subprofile('focuser', "%s,%s" % (focuser_name, cfw_name)).list_subprofiles()10class FilterFocuserProfile(base.BaseProfile):11 def get_filter_offset(self, filter_name, from_filter=None):12 offset = self.get_filter_value(filter_name, "filter_offset", None, float)13 if offset is not None and from_filter is not None:14 ref_offset = self.get_filter_offset(from_filter)15 if ref_offset is None:16 return None17 else:18 offset -= ref_offset19 return offset20 def set_filter_offset(self, filter_name, offset, from_filter=None):21 offset = float(offset)22 if from_filter is not None:23 ref_offset = self.get_filter_offset(from_filter)24 if ref_offset is not None:25 offset += ref_offset26 return self.set_filter_value(filter_name, "filter_offset", offset)27 def del_filter_offset(self, filter_name):28 return self.del_filter_value(filter_name, "filter_offset")29 @property30 def filter_offsets(self):31 return {32 k[14:-1]: v33 for k, v in self.values.items()34 if k.startswith("filter_offset[") and k.endswith("]")35 }36 def reset_filter_offsets(self):37 for filter_name in self.filter_offsets:38 self.del_filter_offset(filter_name)39 def get_filter_value(self, filter_name, value_name, *p, **kw):40 return self.get_value("%s[%s]" % (value_name, filter_name), *p, **kw)41 def set_filter_value(self, filter_name, value_name, value):42 return self.set_value("%s[%s]" % (value_name, filter_name), value)43 def del_filter_value(self, filter_name, value_name):44 return self.del_value("%s[%s]" % (value_name, filter_name))...
day3.py
Source:day3.py
...24 diagnostics, nbits = _get_diagnostics()25 while True:26 for bit in range(nbits):27 counts = Counter([row[bit] for row in diagnostics])28 filter_value = get_filter_value(counts)29 diagnostics = [row for row in diagnostics if row[bit] == filter_value]30 if len(diagnostics) == 1:31 return int(diagnostics[0], 2)32def _get_most_common(counts):33 if counts.get("1", 0) >= counts.get("0", 0):34 return "1"35 else:36 return "0"37def _get_least_common(counts):38 if counts.get("1", 0) < counts.get("0", 0):39 return "1"40 else:41 return "0"42def _get_diagnostics():...
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!!