Best Python code snippet using robotframework
GregorianTimeType.py
Source:GregorianTimeType.py
...60 self.time_type.time_string(timeline.Time(julian_day=0, seconds=0)))61 def test_parses_time_from_string(self):62 self.assertEqual(63 timeline.Time(julian_day=0, seconds=0),64 self.time_type.parse_time("-4713-11-24 00:00:00"))65 def test_raises_ValueError_when_parsing_invalid_time(self):66 self.assertRaises(67 ValueError,68 self.time_type.parse_time, "2010-31-31 0:0:0")69 def test_raises_ValueError_when_parsing_badly_formatted_time(self):70 self.assertRaises(71 ValueError,72 self.time_type.parse_time, "2010-31-hello 0:0:0")73 def test_formats_period_to_string(self):74 time_period = TimePeriod(self.time_type,75 self.time_type.parse_time("2010-08-01 13:44:00"),76 self.time_type.parse_time("2010-08-02 13:30:00"))77 self.assertEqual(78 u"1 %s 2010 13:44 to 2 %s 2010 13:30" % (_("Aug"), _("Aug")),79 self.time_type.format_period(time_period))80 def test_returns_min_time(self):81 self.assertEqual(timeline.Time(0, 0), self.time_type.get_min_time()[0])82 def test_returns_max_time(self):83 self.assertEqual(self.time_type.parse_time("9990-01-01 00:00:00"),84 self.time_type.get_max_time()[0])85 def test_returns_half_delta(self):86 self.assertEqual(87 self.time_type.half_delta(timeline.TimeDelta(4)),88 timeline.TimeDelta(2))89 def test_returns_margin_delta(self):90 self.assertEqual(91 self.time_type.margin_delta(timeline.TimeDelta(48)),92 timeline.TimeDelta(2))93 def test_event_date_string_method(self):94 self.assertEqual(95 "2010-08-01",96 self.time_type.event_date_string(self.time_type.parse_time("2010-08-01 13:44:22")))97 def test_event_time_string_method(self):98 self.assertEqual(99 "13:44",100 self.time_type.event_time_string(self.time_type.parse_time("2010-08-01 13:44:22")))101 def test_eventtimes_equals_method_when_equals(self):102 self.assertTrue(103 self.time_type.eventtimes_equals(self.time_type.parse_time("2010-08-01 13:44:22"),104 self.time_type.parse_time("2010-08-01 13:44:00")))105 def test_eventtimes_equals_method_when_not_equals(self):106 self.assertFalse(107 self.time_type.eventtimes_equals(self.time_type.parse_time("2010-08-01 13:44:22"),108 self.time_type.parse_time("2010-07-01 13:44:22")))109 def test_div_deltas(self):110 self.assertEqual(111 self.time_type.div_timedeltas(timeline.TimeDelta(5), timeline.TimeDelta(2)),112 2.5)113 def test_get_time_at_x(self):114 time_period = TimePeriod(self.time_type,115 self.time_type.parse_time("2010-08-01 00:00:00"),116 self.time_type.parse_time("2010-08-02 00:00:00"))117 dt = self.time_type.get_time_at_x(time_period, 0.5)118 self.assertEqual(dt, self.time_type.parse_time("2010-08-01 12:00:00"))119 def test_get_weekday(self):120 dt = self.time_type.parse_time("2013-07-10 00:00:00")121 self.assertEqual(2, dt.get_day_of_week())122 def test_get_min_zoom_delta(self):123 self.assertEqual(timeline.TimeDelta(60), self.time_type.get_min_zoom_delta()[0])124class GregorianStripWeekSpec(unittest.TestCase):125 def test_start_when_week_starts_on_sunday(self):126 self.config.week_start = "sunday"127 self.assertEqual(128 self.strip.start(self.time_type.parse_time("2013-07-10 11:00:00")),129 self.time_type.parse_time("2013-07-07 00:00:00"))130 def test_start_when_week_starts_on_monday(self):131 self.config.week_start = "monday"132 self.assertEqual(133 self.strip.start(self.time_type.parse_time("2013-07-10 11:00:00")),134 self.time_type.parse_time("2013-07-08 00:00:00"))135 def test_increments_7_days(self):136 self.assertEqual(137 self.strip.increment(self.time_type.parse_time("2013-07-07 00:00:00")),138 self.time_type.parse_time("2013-07-14 00:00:00"))139 def test_label_minor(self):140 self.assertEqual(141 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),142 "")143 def test_label_major_has_no_week_when_week_starts_on_sunday(self):144 self.config.week_start = "sunday"145 self.assertEqual(146 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),147 "7-13 #Jul# 2013")148 def test_label_major_when_week_starts_on_monday(self):149 self.config.week_start = "monday"150 self.assertEqual(151 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),152 "#Week# 27 (1-7 #Jul# 2013)")153 self.assertEqual(154 self.strip.label(self.time_type.parse_time("-4-07-07 00:00:00"), True),155 "#Week# 27 (1-7 #Jul# 5 BC)")156 self.assertEqual(157 self.strip.label(self.time_type.parse_time("2013-11-25 00:00:00"), True),158 "#Week# 48 (25 #Nov#-1 #Dec# 2013)")159 self.assertEqual(160 self.strip.label(self.time_type.parse_time("-4-11-25 00:00:00"), True),161 "#Week# 48 (25 #Nov#-1 #Dec# 5 BC)")162 self.assertEqual(163 self.strip.label(self.time_type.parse_time("2013-12-30 00:00:00"), True),164 "#Week# 1 (30 #Dec# 2013-5 #Jan# 2014)")165 self.assertEqual(166 self.strip.label(self.time_type.parse_time("-4-12-30 00:00:00"), True),167 "#Week# 1 (30 #Dec# 5 BC-5 #Jan# 4 BC)")168 def setUp(self):169 self.time_type = GregorianTimeType()170 self.config = mock.Mock()171 self.strip = StripWeek(self.config)172class GregorianStripWeekdaySpec(unittest.TestCase):173 def test_start(self):174 self.assertEqual(175 self.strip.start(self.time_type.parse_time("2013-07-10 12:13:14")),176 self.time_type.parse_time("2013-07-10 00:00:00"))177 def test_increment(self):178 self.assertEqual(179 self.strip.increment(self.time_type.parse_time("2013-07-07 00:00:00")),180 self.time_type.parse_time("2013-07-08 00:00:00"))181 def test_label_minor(self):182 self.assertEqual(183 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),184 "#Sun# 7")185 def test_label_major(self):186 self.assertEqual(187 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),188 "#Sun# 7 #Jul# 2013")189 self.assertEqual(190 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00"), True),191 "#Fri# 7 #Jul# 6 BC")192 def setUp(self):193 self.time_type = GregorianTimeType()194 self.strip = StripWeekday()195class GregorianStripHourSpec(unittest.TestCase):196 def test_start(self):197 self.assertEqual(198 self.strip.start(self.time_type.parse_time("2013-07-10 12:13:14")),199 self.time_type.parse_time("2013-07-10 12:00:00"))200 def test_increment(self):201 self.assertEqual(202 self.strip.increment(self.time_type.parse_time("2013-07-07 12:00:00")),203 self.time_type.parse_time("2013-07-07 13:00:00"))204 def test_label_minor(self):205 self.assertEqual(206 self.strip.label(self.time_type.parse_time("2013-07-07 12:00:00")),207 "12")208 def test_label_major(self):209 self.assertEqual(210 self.strip.label(self.time_type.parse_time("2013-07-07 12:00:00"), True),211 "7 #Jul# 2013: 12h")212 self.assertEqual(213 self.strip.label(self.time_type.parse_time("-5-07-07 12:00:00"), True),214 "7 #Jul# 6 BC: 12h")215 def setUp(self):216 self.time_type = GregorianTimeType()217 self.strip = StripHour()218class GregorianStripCenturySpec(unittest.TestCase):219 def test_start(self):220 self.assertEqual(221 self.strip.start(self.time_type.parse_time("2013-07-10 12:33:15")),222 self.time_type.parse_time("2000-01-01 00:00:00"))223 self.assertEqual(224 self.strip.start(self.time_type.parse_time("1013-07-10 12:33:15")),225 self.time_type.parse_time("1000-01-01 00:00:00"))226 self.assertEqual(227 self.strip.start(self.time_type.parse_time("13-07-10 12:33:15")),228 self.time_type.parse_time("0-01-01 00:00:00"))229 self.assertEqual(230 self.strip.start(self.time_type.parse_time("-33-07-10 12:33:15")),231 self.time_type.parse_time("-100-01-01 00:00:00"))232 def test_increment(self):233 self.assertEqual(234 self.strip.increment(self.time_type.parse_time("2000-01-01 00:00:00")),235 self.time_type.parse_time("2100-01-01 00:00:00"))236 def test_label_minor(self):237 self.assertEqual(238 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),239 "")240 def test_label_major(self):241 self.assertEqual(242 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),243 "21 century")244 def setUp(self):245 self.time_type = GregorianTimeType()246 self.strip = StripCentury()247class GregorianStripDaySpec(unittest.TestCase):248 def test_start(self):249 self.assertEqual(250 self.strip.start(self.time_type.parse_time("2013-07-10 12:33:15")),251 self.time_type.parse_time("2013-07-10 00:00:00"))252 def test_increment(self):253 self.assertEqual(254 self.strip.increment(self.time_type.parse_time("2013-07-10 00:00:00")),255 self.time_type.parse_time("2013-07-11 00:00:00"))256 def test_label_minor(self):257 self.assertEqual(258 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),259 "7")260 def test_label_major(self):261 self.assertEqual(262 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),263 "7 #Jul# 2013")264 self.assertEqual(265 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00"), True),266 "7 #Jul# 6 BC")267 def setUp(self):268 self.time_type = GregorianTimeType()269 self.strip = StripDay()270class GregorianStripMonthSpec(unittest.TestCase):271 def test_start(self):272 self.assertEqual(273 self.strip.start(self.time_type.parse_time("2013-07-10 12:33:15")),274 self.time_type.parse_time("2013-07-01 00:00:00"))275 def test_increment(self):276 self.assertEqual(277 self.strip.increment(self.time_type.parse_time("2013-07-01 00:00:00")),278 self.time_type.parse_time("2013-08-01 00:00:00"))279 def test_label_minor(self):280 self.assertEqual(281 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),282 _("Jul"))283 def test_label_major(self):284 self.assertEqual(285 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),286 "#Jul# 2013")287 self.assertEqual(288 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00"), True),289 "#Jul# 6 BC")290 def setUp(self):291 self.time_type = GregorianTimeType()292 self.strip = StripMonth()293class GregorianStripYearSpec(unittest.TestCase):294 def test_start(self):295 self.assertEqual(296 self.strip.start(self.time_type.parse_time("2013-07-10 12:33:15")),297 self.time_type.parse_time("2013-01-01 00:00:00"))298 def test_increment(self):299 self.assertEqual(300 self.strip.increment(self.time_type.parse_time("2013-01-01 00:00:00")),301 self.time_type.parse_time("2014-01-01 00:00:00"))302 def test_label_minor(self):303 self.assertEqual(304 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),305 "2013")306 self.assertEqual(307 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00")),308 "6 BC")309 def test_label_major(self):310 self.assertEqual(311 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),312 "2013")313 self.assertEqual(314 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00"), True),315 "6 BC")316 def setUp(self):317 self.time_type = GregorianTimeType()318 self.strip = StripYear()319class GregorianStripDecadeSpec(unittest.TestCase):320 def test_start(self):321 self.assertEqual(322 self.strip.start(self.time_type.parse_time("2013-07-10 12:33:15")),323 self.time_type.parse_time("2000-01-01 00:00:00"))324 self.assertEqual(325 self.strip.start(self.time_type.parse_time("5-07-10 12:33:15")),326 self.time_type.parse_time("-10-01-01 00:00:00"))327 self.assertEqual(328 self.strip.start(self.time_type.parse_time("-5-07-10 12:33:15")),329 self.time_type.parse_time("-20-01-01 00:00:00"))330 self.assertEqual(331 self.strip.start(self.time_type.parse_time("-11-07-10 12:33:15")),332 self.time_type.parse_time("-30-01-01 00:00:00"))333 def test_increment(self):334 self.assertEqual(335 self.strip.increment(self.time_type.parse_time("2010-01-01 00:00:00")),336 self.time_type.parse_time("2020-01-01 00:00:00"))337 def test_label(self):338 self.assertEqual(339 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),340 "2010s")341 self.assertEqual(342 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00")),343 "0s BC")344 def setUp(self):345 self.time_type = GregorianTimeType()346 self.strip = StripDecade()347class GregorianTimeTypeDeltaFormattingSpec(unittest.TestCase):348 def setUp(self):349 self.time_type = GregorianTimeType()350 def test_format_delta_method(self):351 time_period1 = TimePeriod(self.time_type,352 self.time_type.parse_time("2010-08-01 13:44:00"),353 self.time_type.parse_time("2010-08-01 13:44:00"))354 time_period2 = TimePeriod(self.time_type,355 self.time_type.parse_time("2010-08-02 13:44:00"),356 self.time_type.parse_time("2010-08-02 13:44:00"))357 delta = time_period2.start_time - time_period1.start_time358 self.assertEqual(u"1 %s" % _("day"), self.time_type.format_delta(delta))359 def test_format_one_minute_delta(self):360 delta = self.get_days_delta(days=0, hours=0, minutes=1)361 self.assertEqual(u"1 %s" % _("minute"), self.time_type.format_delta(delta))362 def test_format_two_minutes_delta(self):363 delta = self.get_days_delta(days=0, hours=0, minutes=2)364 self.assertEqual(u"2 %s" % _("minutes"), self.time_type.format_delta(delta))365 def test_format_one_hour_delta(self):366 delta = self.get_days_delta(days=0, hours=1, minutes=0)367 self.assertEqual(u"1 %s" % _("hour"), self.time_type.format_delta(delta))368 def test_format_two_hour_delta(self):369 delta = self.get_days_delta(days=0, hours=2, minutes=0)370 self.assertEqual(u"2 %s" % _("hours"), self.time_type.format_delta(delta))371 def test_format_one_day_delta(self):372 delta = self.get_days_delta(days=1, hours=0, minutes=0)373 self.assertEqual(u"1 %s" % _("day"), self.time_type.format_delta(delta))374 def test_format_two_days_delta(self):375 delta = self.get_days_delta(days=2, hours=0, minutes=0)376 self.assertEqual(u"2 %s" % _("days"), self.time_type.format_delta(delta))377 def test_format_one_hour_one_minute_delta(self):378 delta = self.get_days_delta(days=0, hours=1, minutes=1)379 self.assertEqual(u"1 %s 1 %s" % (_("hour"), _("minute")), self.time_type.format_delta(delta))380 def test_format_one_hour_two_minutes_delta(self):381 delta = self.get_days_delta(days=0, hours=1, minutes=2)382 self.assertEqual(u"1 %s 2 %s" % (_("hour"), _("minutes")), self.time_type.format_delta(delta))383 def test_format_one_day_one_hour_delta(self):384 delta = self.get_days_delta(days=1, hours=1, minutes=0)385 self.assertEqual(u"1 %s 1 %s" % (_("day"), _("hour")), self.time_type.format_delta(delta))386 def test_format_one_day_two_hour_delta(self):387 delta = self.get_days_delta(days=1, hours=2, minutes=0)388 self.assertEqual(u"1 %s 2 %s" % (_("day"), _("hours")), self.time_type.format_delta(delta))389 def test_format_two_days_two_hour_delta(self):390 delta = self.get_days_delta(days=2, hours=2, minutes=0)391 self.assertEqual(u"2 %s 2 %s" % (_("days"), _("hours")), self.time_type.format_delta(delta))392 def test_format_two_days_two_hour_one_minute_delta(self):393 delta = self.get_days_delta(days=2, hours=2, minutes=1)394 self.assertEqual(u"2 %s 2 %s 1 %s" % (_("days"), _("hours"), _("minute")), self.time_type.format_delta(delta))395 def test_format_two_days_two_hour_two_minutes_delta(self):396 delta = self.get_days_delta(days=2, hours=2, minutes=2)397 self.assertEqual(u"2 %s 2 %s 2 %s" % (_("days"), _("hours"), _("minutes")), self.time_type.format_delta(delta))398 def test_format_hundred_days_one_minute_delta(self):399 delta = self.get_days_delta(days=100, hours=0, minutes=0)400 self.assertEqual(u"100 %s" % _("days"), self.time_type.format_delta(delta))401 def test_format_2_years_2_months(self):402 time_period1 = self.create_point_period(1, 1, 1999, 0, 0)403 time_period2 = self.create_point_period(1, 3, 2001, 0, 0)404 delta = time_period2.start_time - time_period1.start_time405 self.assertEqual(u"790 %s" % _("days"), self.time_type.format_delta(delta))406 def test_format_overlapping_events(self):407 time_period1 = TimePeriod(self.time_type,408 self.time_type.parse_time("2010-08-01 13:44:00"),409 self.time_type.parse_time("2010-08-03 13:44:00"))410 time_period2 = TimePeriod(self.time_type,411 self.time_type.parse_time("2010-08-01 13:44:00"),412 self.time_type.parse_time("2010-08-03 13:44:00"))413 delta = time_period2.start_time - time_period1.end_time414 self.assertEqual("0", self.time_type.format_delta(delta))415 def create_point_period(self, day, month, year, hour, minute):416 dt = Gregorian(year, month, day, hour, minute, 0).to_time()417 return TimePeriod(self.time_type, dt, dt)418 def get_days_delta(self, days=0, hours=0, minutes=0):419 return timeline.TimeDelta(days * 24 * 60 *60 + hours * 60 * 60 + minutes * 60)420class GregorianTimeNavigationFunctionsSpec(unittest.TestCase):421 def test_fit_week_should_display_the_week_of_the_day_that_is_in_the_center(self):422 self.when_navigating(fit_week_fn, "30 Oct 2012", "13 Nov 2012")423 self.then_period_becomes("5 Nov 2012", "12 Nov 2012")424 def test_fit_week_sunday_start_should_display_the_week_of_the_day_that_is_in_the_center(self):425 self.when_navigating(fit_week_fn, "30 Oct 2012", "13 Nov 2012", False)426 self.then_period_becomes("4 Nov 2012", "11 Nov 2012")...
timetype.py
Source:timetype.py
...62 self.time_type.time_string(GregorianTime(julian_day=0, seconds=0)))63 def test_parses_time_from_string(self):64 self.assertEqual(65 GregorianTime(julian_day=0, seconds=0),66 self.time_type.parse_time("-4713-11-24 00:00:00"))67 def test_raises_ValueError_when_parsing_invalid_time(self):68 self.assertRaises(69 ValueError,70 self.time_type.parse_time, "2010-31-31 0:0:0")71 def test_raises_ValueError_when_parsing_badly_formatted_time(self):72 self.assertRaises(73 ValueError,74 self.time_type.parse_time, "2010-31-hello 0:0:0")75 def test_formats_period_to_string(self):76 time_period = TimePeriod(self.time_type.parse_time("2010-08-01 13:44:00"),77 self.time_type.parse_time("2010-08-02 13:30:00"))78 self.assertEqual(79 u"1 %s 2010 13:44 to 2 %s 2010 13:30" % (_("Aug"), _("Aug")),80 self.time_type.format_period(time_period))81 def test_returns_min_time(self):82 self.assertEqual(GregorianTime(0, 0), self.time_type.get_min_time())83 def test_returns_max_time(self):84 self.assertEqual(self.time_type.parse_time("9990-01-01 00:00:00"),85 self.time_type.get_max_time())86 def test_get_weekday(self):87 dt = self.time_type.parse_time("2013-07-10 00:00:00")88 self.assertEqual(2, self.time_type.get_day_of_week(dt))89 def test_get_min_zoom_delta(self):90 self.assertEqual(GregorianDelta(60), self.time_type.get_min_zoom_delta()[0])91 def test_is_weekend_day(self):92 DAYS = [93 ("11 Jan 2016", False), # Monday94 ("12 Jan 2016", False),95 ("13 Jan 2016", False),96 ("14 Jan 2016", False),97 ("15 Jan 2016", False),98 ("16 Jan 2016", True),99 ("17 Jan 2016", True),100 ]101 for day, expected_is_weekend in DAYS:102 self.assertEqual(103 self.time_type.is_weekend_day(human_time_to_gregorian(day)),104 expected_is_weekend105 )106class describe_gregorian_strip_week(UnitTestCase):107 def test_start_when_week_starts_on_sunday(self):108 self.appearance.set_week_start("sunday")109 self.assertEqual(110 self.strip.start(self.time_type.parse_time("2013-07-10 11:00:00")),111 self.time_type.parse_time("2013-07-07 00:00:00"))112 def test_start_when_week_starts_on_monday(self):113 self.appearance.set_week_start("monday")114 self.assertEqual(115 self.strip.start(self.time_type.parse_time("2013-07-10 11:00:00")),116 self.time_type.parse_time("2013-07-08 00:00:00"))117 def test_increments_7_days(self):118 self.assertEqual(119 self.strip.increment(self.time_type.parse_time("2013-07-07 00:00:00")),120 self.time_type.parse_time("2013-07-14 00:00:00"))121 def test_label_minor(self):122 self.assertEqual(123 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),124 "")125 def test_label_major_has_no_week_when_week_starts_on_sunday(self):126 self.appearance.set_week_start("sunday")127 self.assertEqual(128 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),129 u"7-13 âªJulâ« 2013"130 )131 def test_label_major_when_week_starts_on_monday(self):132 self.appearance.set_week_start("monday")133 self.assertEqual(134 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),135 u"âªWeekâ« 27 (1-7 âªJulâ« 2013)"136 )137 self.assertEqual(138 self.strip.label(self.time_type.parse_time("-4-07-07 00:00:00"), True),139 u"âªWeekâ« 27 (1-7 âªJulâ« 5 âªBCâ«)"140 )141 self.assertEqual(142 self.strip.label(self.time_type.parse_time("2013-11-25 00:00:00"), True),143 u"âªWeekâ« 48 (25 âªNovâ«-1 âªDecâ« 2013)"144 )145 self.assertEqual(146 self.strip.label(self.time_type.parse_time("-4-11-25 00:00:00"), True),147 u"âªWeekâ« 48 (25 âªNovâ«-1 âªDecâ« 5 âªBCâ«)"148 )149 self.assertEqual(150 self.strip.label(self.time_type.parse_time("2013-12-30 00:00:00"), True),151 u"âªWeekâ« 1 (30 âªDecâ« 2013-5 âªJanâ« 2014)"152 )153 self.assertEqual(154 self.strip.label(self.time_type.parse_time("-4-12-30 00:00:00"), True),155 u"âªWeekâ« 1 (30 âªDecâ« 5 âªBCâ«-5 âªJanâ« 4 âªBCâ«)"156 )157 def setUp(self):158 UnitTestCase.setUp(self)159 self.app = wx.App()160 self.time_type = GregorianTimeType()161 self.appearance = Appearance()162 self.strip = StripWeek(self.appearance)163class describe_gregorian_strip_weekday(UnitTestCase):164 def test_start(self):165 self.assertEqual(166 self.strip.start(self.time_type.parse_time("2013-07-10 12:13:14")),167 self.time_type.parse_time("2013-07-10 00:00:00"))168 def test_increment(self):169 self.assertEqual(170 self.strip.increment(self.time_type.parse_time("2013-07-07 00:00:00")),171 self.time_type.parse_time("2013-07-08 00:00:00"))172 def test_label_minor(self):173 self.assertEqual(174 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),175 u"âªSunâ« 7"176 )177 def test_label_major(self):178 self.assertEqual(179 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),180 u"âªSunâ« 7 âªJulâ« 2013"181 )182 self.assertEqual(183 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00"), True),184 u"âªFriâ« 7 âªJulâ« 6 âªBCâ«"185 )186 def setUp(self):187 UnitTestCase.setUp(self)188 self.time_type = GregorianTimeType()189 self.strip = StripWeekday()190class describe_gregorian_strip_hour(UnitTestCase):191 def test_start(self):192 self.assertEqual(193 self.strip.start(self.time_type.parse_time("2013-07-10 12:13:14")),194 self.time_type.parse_time("2013-07-10 12:00:00"))195 def test_increment(self):196 self.assertEqual(197 self.strip.increment(self.time_type.parse_time("2013-07-07 12:00:00")),198 self.time_type.parse_time("2013-07-07 13:00:00"))199 def test_label_minor(self):200 self.assertEqual(201 self.strip.label(self.time_type.parse_time("2013-07-07 12:00:00")),202 "12")203 def test_label_major(self):204 self.assertEqual(205 self.strip.label(self.time_type.parse_time("2013-07-07 12:00:00"), True),206 u"7 âªJulâ« 2013: 12h"207 )208 self.assertEqual(209 self.strip.label(self.time_type.parse_time("-5-07-07 12:00:00"), True),210 u"7 âªJulâ« 6 âªBCâ«: 12h"211 )212 def setUp(self):213 UnitTestCase.setUp(self)214 self.time_type = GregorianTimeType()215 self.strip = StripHour()216class describe_gregorian_strip_day(UnitTestCase):217 def test_start(self):218 self.assertEqual(219 self.strip.start(self.time_type.parse_time("2013-07-10 12:33:15")),220 self.time_type.parse_time("2013-07-10 00:00:00"))221 def test_increment(self):222 self.assertEqual(223 self.strip.increment(self.time_type.parse_time("2013-07-10 00:00:00")),224 self.time_type.parse_time("2013-07-11 00:00:00"))225 def test_label_minor(self):226 self.assertEqual(227 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),228 "7")229 def test_label_major(self):230 self.assertEqual(231 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),232 u"7 âªJulâ« 2013"233 )234 self.assertEqual(235 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00"), True),236 u"7 âªJulâ« 6 âªBCâ«"237 )238 def setUp(self):239 UnitTestCase.setUp(self)240 self.time_type = GregorianTimeType()241 self.strip = StripDay()242class describe_gregorian_strip_month(UnitTestCase):243 def test_start(self):244 self.assertEqual(245 self.strip.start(self.time_type.parse_time("2013-07-10 12:33:15")),246 self.time_type.parse_time("2013-07-01 00:00:00"))247 def test_increment(self):248 self.assertEqual(249 self.strip.increment(self.time_type.parse_time("2013-07-01 00:00:00")),250 self.time_type.parse_time("2013-08-01 00:00:00"))251 def test_label_minor(self):252 self.assertEqual(253 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),254 _("Jul"))255 def test_label_major(self):256 self.assertEqual(257 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),258 u"âªJulâ« 2013"259 )260 self.assertEqual(261 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00"), True),262 u"âªJulâ« 6 âªBCâ«"263 )264 def setUp(self):265 UnitTestCase.setUp(self)266 self.time_type = GregorianTimeType()267 self.strip = StripMonth()268class describe_gregorian_strip_year(UnitTestCase):269 def test_start(self):270 self.assertEqual(271 self.strip.start(self.time_type.parse_time("2013-07-10 12:33:15")),272 self.time_type.parse_time("2013-01-01 00:00:00"))273 def test_increment(self):274 self.assertEqual(275 self.strip.increment(self.time_type.parse_time("2013-01-01 00:00:00")),276 self.time_type.parse_time("2014-01-01 00:00:00"))277 def test_label_minor(self):278 self.assertEqual(279 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),280 "2013")281 self.assertEqual(282 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00")),283 u"6 âªBCâ«"284 )285 def test_label_major(self):286 self.assertEqual(287 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00"), True),288 "2013")289 self.assertEqual(290 self.strip.label(self.time_type.parse_time("-5-07-07 00:00:00"), True),291 u"6 âªBCâ«"292 )293 def setUp(self):294 UnitTestCase.setUp(self)295 self.time_type = GregorianTimeType()296 self.strip = StripYear()297class describe_gregorian_strip_decade(UnitTestCase):298 def test_label(self):299 for (time, expected_label) in [300 ("7 Jul -19", u"20s âªBCâ«"),301 ("7 Jul -18", u"10s âªBCâ«"),302 ("7 Jul -9", u"10s âªBCâ«"),303 ("7 Jul -8", u"0s âªBCâ«"),304 ("7 Jul 0", u"0s âªBCâ«"),305 ("7 Jul 1", u"0s"),306 ("7 Jul 9", u"0s"),307 ("7 Jul 10", u"10s"),308 ("7 Jul 19", u"10s"),309 ("7 Jul 20", u"20s"),310 ("7 Jul 2013", u"2010s"),311 ]:312 self.assertEqual(313 self.strip.label(human_time_to_gregorian(time)),314 expected_label315 )316 def test_start(self):317 for (start_year, expected_decade_start_year) in [318 # 20s BC319 (-19, -28),320 # 10s BC321 (-18, -18),322 (-9, -18),323 # 0s BC324 (-8, -8),325 (0, -8),326 # 0s327 (1, 1),328 (9, 1),329 # 10s330 (10, 10),331 (19, 10),332 # 20s333 (20, 20),334 # 2010s335 (2010, 2010),336 (2013, 2010),337 ]:338 self.assertEqual(339 self.strip.start(human_time_to_gregorian(340 "10 Jul {0} 12:33:15".format(start_year)341 )),342 human_time_to_gregorian(343 "1 Jan {0} 00:00:00".format(expected_decade_start_year)344 )345 )346 def test_increment(self):347 for (start_year, expected_next_start_year) in [348 (-28, -18),349 (-18, -8),350 (-8, 1),351 (1, 10),352 (10, 20),353 (2010, 2020),354 ]:355 self.assertEqual(356 self.strip.increment(human_time_to_gregorian(357 "1 Jan {0}".format(start_year)358 )),359 human_time_to_gregorian(360 "1 Jan {0}".format(expected_next_start_year)361 )362 )363 def setUp(self):364 UnitTestCase.setUp(self)365 self.time_type = GregorianTimeType()366 self.strip = StripDecade()367class describe_gregorian_strip_century(UnitTestCase):368 def test_label_minor(self):369 self.assertEqual(370 self.strip.label(self.time_type.parse_time("2013-07-07 00:00:00")),371 "")372 def test_label_major(self):373 for (time, expected_label) in [374 ("7 Jul -199", u"200s âªBCâ«"),375 ("7 Jul -198", u"100s âªBCâ«"),376 ("7 Jul -99", u"100s âªBCâ«"),377 ("7 Jul -98", u"0s âªBCâ«"),378 ("7 Jul 0", u"0s âªBCâ«"),379 ("7 Jul 1", u"0s"),380 ("7 Jul 99", u"0s"),381 ("7 Jul 100", u"100s"),382 ("7 Jul 199", u"100s"),383 ("7 Jul 200", u"200s"),384 ("7 Jul 2013", u"2000s"),385 ]:386 self.assertEqual(387 self.strip.label(human_time_to_gregorian(time), major=True),388 expected_label,389 )390 def test_start(self):391 for (start_year, expected_century_start_year) in [392 # 200s BC393 (-199, -298),394 # 100s BC395 (-198, -198),396 (-99, -198),397 # # 0s BC398 (-98, -98),399 (0, -98),400 # 0s401 (1, 1),402 (99, 1),403 # 100s404 (100, 100),405 (199, 100),406 # 200s407 (200, 200),408 # 2000s409 (2000, 2000),410 (2010, 2000),411 (2099, 2000),412 ]:413 self.assertEqual(414 self.strip.start(human_time_to_gregorian(415 "10 Jul {0} 12:33:15".format(start_year)416 )),417 human_time_to_gregorian(418 "1 Jan {0} 00:00:00".format(expected_century_start_year)419 )420 )421 def test_increment(self):422 for (start_year, expected_next_start_year) in [423 (-298, -198),424 (-198, -98),425 (-98, 1),426 (1, 100),427 (100, 200),428 (200, 300),429 ]:430 self.assertEqual(431 self.strip.increment(human_time_to_gregorian(432 "1 Jan {0}".format(start_year)433 )),434 human_time_to_gregorian(435 "1 Jan {0}".format(expected_next_start_year)436 )437 )438 def setUp(self):439 UnitTestCase.setUp(self)440 self.time_type = GregorianTimeType()441 self.strip = StripCentury()442class describe_gregorian_time_type_delta_formatting(UnitTestCase):443 def setUp(self):444 UnitTestCase.setUp(self)445 self.time_type = GregorianTimeType()446 def test_format_delta_method(self):447 time_period1 = TimePeriod(self.time_type.parse_time("2010-08-01 13:44:00"),448 self.time_type.parse_time("2010-08-01 13:44:00"))449 time_period2 = TimePeriod(self.time_type.parse_time("2010-08-02 13:44:00"),450 self.time_type.parse_time("2010-08-02 13:44:00"))451 delta = time_period2.start_time - time_period1.start_time452 self.assertEqual(u"1 %s" % _("day"), self.time_type.format_delta(delta))453 def test_format_one_minute_delta(self):454 delta = self.get_days_delta(days=0, hours=0, minutes=1)455 self.assertEqual(u"1 %s" % _("minute"), self.time_type.format_delta(delta))456 def test_format_two_minutes_delta(self):457 delta = self.get_days_delta(days=0, hours=0, minutes=2)458 self.assertEqual(u"2 %s" % _("minutes"), self.time_type.format_delta(delta))459 def test_format_one_hour_delta(self):460 delta = self.get_days_delta(days=0, hours=1, minutes=0)461 self.assertEqual(u"1 %s" % _("hour"), self.time_type.format_delta(delta))462 def test_format_two_hour_delta(self):463 delta = self.get_days_delta(days=0, hours=2, minutes=0)464 self.assertEqual(u"2 %s" % _("hours"), self.time_type.format_delta(delta))465 def test_format_one_day_delta(self):466 delta = self.get_days_delta(days=1, hours=0, minutes=0)467 self.assertEqual(u"1 %s" % _("day"), self.time_type.format_delta(delta))468 def test_format_two_days_delta(self):469 delta = self.get_days_delta(days=2, hours=0, minutes=0)470 self.assertEqual(u"2 %s" % _("days"), self.time_type.format_delta(delta))471 def test_format_one_hour_one_minute_delta(self):472 delta = self.get_days_delta(days=0, hours=1, minutes=1)473 self.assertEqual(u"1 %s 1 %s" % (_("hour"), _("minute")), self.time_type.format_delta(delta))474 def test_format_one_hour_two_minutes_delta(self):475 delta = self.get_days_delta(days=0, hours=1, minutes=2)476 self.assertEqual(u"1 %s 2 %s" % (_("hour"), _("minutes")), self.time_type.format_delta(delta))477 def test_format_one_day_one_hour_delta(self):478 delta = self.get_days_delta(days=1, hours=1, minutes=0)479 self.assertEqual(u"1 %s 1 %s" % (_("day"), _("hour")), self.time_type.format_delta(delta))480 def test_format_one_day_two_hour_delta(self):481 delta = self.get_days_delta(days=1, hours=2, minutes=0)482 self.assertEqual(u"1 %s 2 %s" % (_("day"), _("hours")), self.time_type.format_delta(delta))483 def test_format_two_days_two_hour_delta(self):484 delta = self.get_days_delta(days=2, hours=2, minutes=0)485 self.assertEqual(u"2 %s 2 %s" % (_("days"), _("hours")), self.time_type.format_delta(delta))486 def test_format_two_days_two_hour_one_minute_delta(self):487 delta = self.get_days_delta(days=2, hours=2, minutes=1)488 self.assertEqual(u"2 %s 2 %s 1 %s" % (_("days"), _("hours"), _("minute")), self.time_type.format_delta(delta))489 def test_format_two_days_two_hour_two_minutes_delta(self):490 delta = self.get_days_delta(days=2, hours=2, minutes=2)491 self.assertEqual(u"2 %s 2 %s 2 %s" % (_("days"), _("hours"), _("minutes")), self.time_type.format_delta(delta))492 def test_format_hundred_days_one_minute_delta(self):493 delta = self.get_days_delta(days=100, hours=0, minutes=0)494 self.assertEqual(u"100 %s" % _("days"), self.time_type.format_delta(delta))495 def test_format_2_years_2_months(self):496 time_period1 = self.create_point_period(1, 1, 1999, 0, 0)497 time_period2 = self.create_point_period(1, 3, 2001, 0, 0)498 delta = time_period2.start_time - time_period1.start_time499 self.assertEqual(500 u'2 âªyearsâ« 60 âªdaysâ«',501 self.time_type.format_delta(delta)502 )503 def test_format_overlapping_events(self):504 time_period1 = TimePeriod(self.time_type.parse_time("2010-08-01 13:44:00"),505 self.time_type.parse_time("2010-08-03 13:44:00"))506 time_period2 = TimePeriod(self.time_type.parse_time("2010-08-01 13:44:00"),507 self.time_type.parse_time("2010-08-03 13:44:00"))508 delta = time_period2.start_time - time_period1.end_time509 self.assertEqual(510 u'2 âªdaysâ«',511 self.time_type.format_delta(delta)512 )513 def create_point_period(self, day, month, year, hour, minute):514 dt = GregorianDateTime(year, month, day, hour, minute, 0).to_time()515 return TimePeriod(dt, dt)516 def get_days_delta(self, days=0, hours=0, minutes=0):517 return GregorianDelta(days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60)518class describe_gregorian_time_navigation_functions(UnitTestCase):519 def test_fit_week_should_display_the_week_of_the_day_that_is_in_the_center(self):520 self.when_navigating(fit_week_fn, "30 Oct 2012", "13 Nov 2012")521 self.then_period_becomes("5 Nov 2012", "12 Nov 2012")...
test_Parser.py
Source:test_Parser.py
...111 actual = parsed_data.perons_df112 assert_frame_equal(expected, actual, check_dtype=False)113def test_parse_stop_times_df(parsed_data: ParsedData) -> None:114 expected = pd.DataFrame([115 [1652, 2, 1, parse_time('06:50:00'), 60, 8404, 7],116 [1652, 2, 1, parse_time('06:51:00'), 58, 8202, 8],117 [1652, 2, 1, parse_time('06:52:00'), 1230, 287801, 9],118 [1652, 2, 1, parse_time('06:53:00'), 57, 8101, 10],119 [1652, 2, 1, parse_time('06:55:00'), 1626, 311102, 11],120 [337, 2, 3, parse_time('04:52:00'), 57, 8102, 1],121 [337, 2, 3, parse_time('04:54:00'), 58, 8203, 2],122 [337, 2, 3, parse_time('04:55:00'), 61, 8502, 3],123 [337, 3, 3, parse_time('23:57:00'), 61, 8503, 12],124 [337, 3, 3, parse_time('23:59:00'), 1230, 287801, 13],125 [337, 3, 3, parse_time('24:00:00'), 57, 8101, 14],126 [337, 3, 3, parse_time('24:02:00'), 55, 7904, 15],127 ], columns=['block_id', 'trip_num', 'service_id', 'departure_time', 'stop_id', 'peron_id', 'stop_sequence']) \128 .set_index(['service_id', 'block_id', 'trip_num', 'stop_sequence']) \129 [['stop_id', 'peron_id', 'departure_time']]130 actual = parsed_data.stop_times_df131 assert_frame_equal(expected, actual, check_dtype=False)132def test_create_transfers_df(parsed_data: ParsedData) -> None:133 expected = pd.DataFrame([134 [1652, 2, 1, parse_time('06:50:00'), parse_time('06:51:00'), 60, 58, 8404, 8202, 7, 60],135 [1652, 2, 1, parse_time('06:51:00'), parse_time('06:52:00'), 58, 1230, 8202, 287801, 8, 60],136 [1652, 2, 1, parse_time('06:52:00'), parse_time('06:53:00'), 1230, 57, 287801, 8101, 9, 60],137 [1652, 2, 1, parse_time('06:53:00'), parse_time('06:55:00'), 57, 1626, 8101, 311102, 10, 120],138 [337, 2, 3, parse_time('04:52:00'), parse_time('04:54:00'), 57, 58, 8102, 8203, 1, 120],139 [337, 2, 3, parse_time('04:54:00'), parse_time('04:55:00'), 58, 61, 8203, 8502, 2, 60],140 [337, 3, 3, parse_time('23:57:00'), parse_time('23:59:00'), 61, 1230, 8503, 287801, 12, 120],141 [337, 3, 3, parse_time('23:59:00'), parse_time('24:00:00'), 1230, 57, 287801, 8101, 13, 60],142 [337, 3, 3, parse_time('24:00:00'), parse_time('24:02:00'), 57, 55, 8101, 7904, 14, 120],143 ], columns=['block_id', 'trip_num', 'service_id', 'start_time', 'end_time',144 'start_stop_id', 'end_stop_id', 'start_peron_id', 'end_peron_id', 'stop_sequence', 'duration'])145 actual = parsed_data.transfers_df...
parse-time_test.py
Source:parse-time_test.py
1from library import parse_time2class TestClass:3 def test_one_digit_single_times(self):4 assert parse_time("1s") == 15 assert parse_time("2s") == 26 assert parse_time("1m") == 607 assert parse_time("2m") == 1208 assert parse_time("1h") == 36009 assert parse_time("2h") == 720010 assert parse_time("1d") == 8640011 assert parse_time("2d") == 17280012 def test_one_digit_double_times(self):13 assert parse_time("1m1s") == 6114 assert parse_time("1m2s") == 6215 assert parse_time("2m1s") == 12116 assert parse_time("2m2s") == 12217 assert parse_time("1h1s") == 360118 assert parse_time("1h2s") == 360219 assert parse_time("1h1m") == 366020 assert parse_time("1h2m") == 372021 assert parse_time("2h1s") == 720122 assert parse_time("2h2s") == 720223 assert parse_time("2h1m") == 726024 assert parse_time("2h2m") == 732025 assert parse_time("1d1s") == 8640126 assert parse_time("1d2s") == 8640227 assert parse_time("1d1m") == 8646028 assert parse_time("1d2m") == 8652029 assert parse_time("1d1h") == 9000030 assert parse_time("1d2h") == 9360031 assert parse_time("2d1s") == 17280132 assert parse_time("2d2s") == 17280233 assert parse_time("2d1m") == 17286034 assert parse_time("2d2m") == 17292035 assert parse_time("2d1h") == 17640036 assert parse_time("2d2h") == 18000037 def test_one_digit_triple_times(self):38 assert parse_time("1h1m1s") == 366139 assert parse_time("1h1m2s") == 366240 assert parse_time("1h2m1s") == 372141 assert parse_time("1h2m2s") == 372242 assert parse_time("2h1m1s") == 726143 assert parse_time("2h1m2s") == 726244 assert parse_time("2h2m1s") == 732145 assert parse_time("2h2m2s") == 732246 assert parse_time("1d1m1s") == 8646147 assert parse_time("1d1m2s") == 8646248 assert parse_time("1d2m1s") == 8652149 assert parse_time("1d2m2s") == 8652250 assert parse_time("1d1h1s") == 9000151 assert parse_time("1d1h2s") == 9000252 assert parse_time("1d1h1m") == 9006053 assert parse_time("1d1h2m") == 9012054 assert parse_time("1d2h1s") == 9360155 assert parse_time("1d2h2s") == 9360256 assert parse_time("1d2h1m") == 9366057 assert parse_time("1d2h2m") == 9372058 assert parse_time("2d1m1s") == 17286159 assert parse_time("2d1m2s") == 17286260 assert parse_time("2d2m1s") == 17292161 assert parse_time("2d2m2s") == 17292262 assert parse_time("2d1h1s") == 17640163 assert parse_time("2d1h2s") == 17640264 assert parse_time("2d1h1m") == 17646065 assert parse_time("2d1h2m") == 17652066 assert parse_time("2d2h1s") == 18000167 assert parse_time("2d2h2s") == 18000268 assert parse_time("2d2h1m") == 18006069 assert parse_time("2d2h2m") == 18012070 def test_one_digit_quad_times(self):71 assert parse_time("1d1h1m1s") == 9006172 assert parse_time("1d1h1m2s") == 9006273 assert parse_time("1d1h2m1s") == 9012174 assert parse_time("1d1h2m2s") == 9012275 assert parse_time("1d2h1m1s") == 9366176 assert parse_time("1d2h1m2s") == 9366277 assert parse_time("1d2h2m1s") == 9372178 assert parse_time("1d2h2m2s") == 9372279 assert parse_time("2d1h1m1s") == 17646180 assert parse_time("2d1h1m2s") == 17646281 assert parse_time("2d1h2m1s") == 17652182 assert parse_time("2d1h2m2s") == 17652283 assert parse_time("2d2h1m1s") == 18006184 assert parse_time("2d2h1m2s") == 18006285 assert parse_time("2d2h2m1s") == 18012186 assert parse_time("2d2h2m2s") == 18012287 def test_two_digit_times(self):88 assert parse_time("10s") == 1089 assert parse_time("20s") == 2090 assert parse_time("10m") == 60091 assert parse_time("20m") == 120092 assert parse_time("10h") == 3600093 assert parse_time("20h") == 7200094 assert parse_time("10d") == 86400095 assert parse_time("20d") == 172800096 def test_three_digit_times(self):97 assert parse_time("100s") == 10098 assert parse_time("200s") == 20099 assert parse_time("100m") == 6000100 assert parse_time("200m") == 12000101 assert parse_time("100h") == 360000102 assert parse_time("200h") == 720000103 assert parse_time("100d") == 8640000104 assert parse_time("200d") == 17280000105 def test_no_letter_single_times(self):106 assert parse_time("1") == 60107 assert parse_time("2") == 120108 def test_no_letter_double_times(self):109 assert parse_time("10") == 600110 assert parse_time("20") == 1200111 def test_no_letter_triple_times(self):112 assert parse_time("100") == 6000113 assert parse_time("200") == 12000114 def test_empty_times(self):115 assert parse_time("0s") == 0116 assert parse_time("0m") == 0...
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!!