Exemple #1
0
    def test_get_possible_time_formats(self):
        gen = ParseSimpleTime()._get_possible_time_formats("02-03-10")
        self.assertEqual(set(gen), set(["DD-MM-YY", "MM-DD-YY", "YY-MM-DD"]))

        gen = ParseSimpleTime()._get_possible_time_formats("02-03-2010")
        self.assertEqual(
            set(gen), set(["DD-MM-YYYY", "MM-DD-YYYY", "YY-MM-DDDD"]))
    def test_parse_time_case2_exceptions(self):
        params = load_parameters_case(2)

        last_time = arrow.get(2009, 12, 16)
        next_value = "18-12-09"

        with patch.object(ParseSimpleTime,
                          "_get_possible_time_formats",
                          return_value=["YY-MM-DD"]):
            value = "12-17.09"
            self.assertRaises(NoTimeValue,
                              ParseSimpleTime()._parse_time, params[0], value,
                              last_time, next_value)

        with patch.object(ParseSimpleTime,
                          "_get_possible_time_formats",
                          return_value=["MM-DD-YY"]):
            value = "17-12.09"
            self.assertRaises(NoTimeValue,
                              ParseSimpleTime()._parse_time, params[0], value,
                              last_time, next_value)
Exemple #3
0
    def run_pt(self, params, exp_value, value, last_time=None,
               next_value=None):
        new_value = ParseSimpleTime()._parse_time(params, value, last_time,
                                                  next_value)

        msg = " ".join([
            repr(new_value), "!=",
            repr(exp_value), "\n", "value:",
            repr(value), "last time:",
            repr(last_time), "next value:",
            repr(next_value)
        ])

        self.assertEqual(new_value, exp_value, msg)
Exemple #4
0
    def test_time_make_sense(self):

        params = load_parameters_case(2)
        time_value = arrow.get(2017, 12, 9)
        last_time = arrow.get(2009, 12, 16)
        next_value = "18-12-09"

        make_sense = ParseSimpleTime()._time_make_sense(
            params[0], time_value, last_time, next_value)
        self.assertFalse(make_sense)

        make_sense = ParseSimpleTime()._time_make_sense(
            params[0], time_value, None, next_value)
        self.assertFalse(make_sense)

        time_value = arrow.get(2002, 3, 10)
        last_time = arrow.get(2010, 3, 1)

        make_sense = ParseSimpleTime()._time_make_sense(
            params[0], time_value, last_time, next_value)
        self.assertFalse(make_sense)

        time_value = arrow.get(2010, 2, 3)
        last_time = arrow.get(2010, 3, 1)
        next_value = arrow.get(2010, 3, 3)

        make_sense = ParseSimpleTime()._time_make_sense(
            params[0], time_value, last_time, next_value)
        self.assertFalse(make_sense)

        time_value = arrow.get(2010, 3, 2)
        last_time = arrow.get(2010, 3, 1)
        next_value = arrow.get(2010, 3, 3)

        make_sense = ParseSimpleTime()._time_make_sense(
            params[0], time_value, last_time, next_value)
        self.assertTrue(make_sense)