Exemplo n.º 1
0
    def test_export_frequencies_txt_minimal(self):
        Frequency.objects.create(
            trip=self.trip, start_time=Seconds.from_hms(hours=6),
            end_time=Seconds.from_hms(hours=22), headway_secs=1800)
        frequencies_txt = Frequency.objects.in_feed(self.feed).export_txt()
        self.assertEqual(frequencies_txt, """\
trip_id,start_time,end_time,headway_secs
STBA,06:00:00,22:00:00,1800
""")
Exemplo n.º 2
0
    def test_export_frequencies_txt_minimal(self):
        Frequency.objects.create(
            trip=self.trip, start_time=Seconds.from_hms(hours=6),
            end_time=Seconds.from_hms(hours=22), headway_secs=1800)
        frequencies_txt = Frequency.export_txt(self.feed)
        self.assertEqual(frequencies_txt, """\
trip_id,start_time,end_time,headway_secs
STBA,06:00:00,22:00:00,1800
""")
Exemplo n.º 3
0
 def test_comparison(self):
     one_minute = Seconds(60)
     one_hour = Seconds(3600)
     one_hour2 = Seconds(3600)
     self.assertTrue(one_hour > one_minute)
     self.assertFalse(one_hour > one_hour2)
     self.assertTrue(one_hour >= one_hour2)
     self.assertTrue(one_hour == one_hour2)
     self.assertFalse(one_hour != one_hour2)
     self.assertFalse(one_hour < one_hour2)
     self.assertTrue(one_hour <= one_hour2)
Exemplo n.º 4
0
    def test_import_frequencies_txt_maximal(self):
        frequencies_txt = StringIO.StringIO("""\
trip_id,start_time,end_time,headway_secs,exact_times
STBA,6:00:00,23:30:35,1800,1
""")
        Frequency.import_txt(frequencies_txt, self.feed)
        frequency = Frequency.objects.get()
        self.assertEqual(frequency.trip, self.trip)
        self.assertEqual(frequency.start_time, Seconds.from_hms(hours=6))
        self.assertEqual(frequency.end_time, Seconds.from_hms(23, 30, 35))
        self.assertEqual(frequency.headway_secs, 1800)
        self.assertEqual(frequency.exact_times, '1')
Exemplo n.º 5
0
    def test_import_frequencies_txt_maximal(self):
        frequencies_txt = StringIO.StringIO("""\
trip_id,start_time,end_time,headway_secs,exact_times
STBA,6:00:00,23:30:35,1800,1
""")
        Frequency.import_txt(frequencies_txt, self.feed)
        frequency = Frequency.objects.get()
        self.assertEqual(frequency.trip, self.trip)
        self.assertEqual(frequency.start_time, Seconds.from_hms(hours=6))
        self.assertEqual(frequency.end_time, Seconds.from_hms(23, 30, 35))
        self.assertEqual(frequency.headway_secs, 1800)
        self.assertEqual(frequency.exact_times, '1')
Exemplo n.º 6
0
    def test_import_frequencies_txt_duplicate(self):
        frequencies_txt = StringIO("""\
trip_id,start_time,end_time,headway_secs
STBA,6:00:00,8:00:00,1800
STBA,6:00:00,10:00:00,1200
STBA,10:00:00,12:00:00,1500
""")
        Frequency.import_txt(frequencies_txt, self.feed)
        self.assertEqual(2, Frequency.objects.count())
        freq1, freq2 = Frequency.objects.order_by('start_time')
        self.assertEqual(freq1.trip, self.trip)
        self.assertEqual(freq1.start_time, Seconds.from_hms(hours=6))
        self.assertEqual(freq1.end_time, Seconds.from_hms(hours=8))
        self.assertEqual(freq1.headway_secs, 1800)
        self.assertEqual(freq2.trip, self.trip)
        self.assertEqual(freq2.start_time, Seconds.from_hms(hours=10))
        self.assertEqual(freq2.end_time, Seconds.from_hms(hours=12))
        self.assertEqual(freq2.headway_secs, 1500)
Exemplo n.º 7
0
    def test_import_frequencies_txt_duplicate(self):
        frequencies_txt = StringIO("""\
trip_id,start_time,end_time,headway_secs
STBA,6:00:00,8:00:00,1800
STBA,6:00:00,10:00:00,1200
STBA,10:00:00,12:00:00,1500
""")
        Frequency.import_txt(frequencies_txt, self.feed)
        self.assertEqual(2, Frequency.objects.count())
        freq1, freq2 = Frequency.objects.order_by('start_time')
        self.assertEqual(freq1.trip, self.trip)
        self.assertEqual(freq1.start_time, Seconds.from_hms(hours=6))
        self.assertEqual(freq1.end_time, Seconds.from_hms(hours=8))
        self.assertEqual(freq1.headway_secs, 1800)
        self.assertEqual(freq2.trip, self.trip)
        self.assertEqual(freq2.start_time, Seconds.from_hms(hours=10))
        self.assertEqual(freq2.end_time, Seconds.from_hms(hours=12))
        self.assertEqual(freq2.headway_secs, 1500)
Exemplo n.º 8
0
    def test_import_frequencies_txt_omitted_with_rollover(self):
        frequencies_txt = StringIO.StringIO("""\
trip_id,start_time,end_time,headway_secs,exact_times
STBA,00:50:00,24:10:00,1800,
""")
        Frequency.import_txt(frequencies_txt, self.feed)
        frequency = Frequency.objects.get()
        self.assertEqual(str(frequency.start_time), '00:50:00')
        self.assertEqual(frequency.end_time, Seconds.from_hms(24, 10))
        self.assertEqual(frequency.headway_secs, 1800)
        self.assertEqual(frequency.exact_times, '')
Exemplo n.º 9
0
    def test_import_frequencies_txt_omitted_with_rollover(self):
        frequencies_txt = StringIO.StringIO("""\
trip_id,start_time,end_time,headway_secs,exact_times
STBA,00:50:00,24:10:00,1800,
""")
        Frequency.import_txt(frequencies_txt, self.feed)
        frequency = Frequency.objects.get()
        self.assertEqual(str(frequency.start_time), '00:50:00')
        self.assertEqual(frequency.end_time, Seconds.from_hms(24, 10))
        self.assertEqual(frequency.headway_secs, 1800)
        self.assertEqual(frequency.exact_times, '')
Exemplo n.º 10
0
 def test_from_hms(self):
     standard = Seconds(45296)
     from_hms = Seconds.from_hms(hours=12, minutes=34, seconds=56)
     self.assertEqual(standard, from_hms)
Exemplo n.º 11
0
 def test_prep_db_value_Seconds(self):
     self.assertEqual(500, self.f.get_prep_value(Seconds(500)))
Exemplo n.º 12
0
 def test_to_python_hms_string(self):
     self.assertEqual(Seconds(3661), self.f.to_python('01:01:01'))
Exemplo n.º 13
0
 def test_to_python_seconds_string(self):
     self.assertEqual(Seconds(500), self.f.to_python('500'))
Exemplo n.º 14
0
 def test_to_python_Seconds(self):
     self.assertEqual(Seconds(500), self.f.to_python(Seconds(500)))
Exemplo n.º 15
0
 def test_to_python_int(self):
     self.assertEqual(Seconds(400), self.f.to_python(400))
Exemplo n.º 16
0
 def test_unequal_int(self):
     seconds = Seconds(1000)
     self.assertNotEqual(seconds, 1000)
Exemplo n.º 17
0
 def test_from_hms(self):
     standard = Seconds(45296)
     from_hms = Seconds.from_hms(hours=12, minutes=34, seconds=56)
     self.assertEqual(standard, from_hms)
Exemplo n.º 18
0
 def test_string(self):
     self.assertEqual('00:00:00', str(Seconds(0)))
     self.assertEqual('24:00:00', str(Seconds(24 * 60 * 60)))
     self.assertEqual('12:34:56', str(Seconds(45296)))