Beispiel #1
0
    def test_format_string_parsing(self):
        expected_date = date(2013, 5, 10)

        STRING_FORMAT_PAIRS = (
            ("2013-5-10", "%Y-%m-%d"),
            ("2013-05-10", "%Y-%m-%d"),
            ("5-10-2013", "%m-%d-%Y"),
            ("5/10/2013", "%m/%d/%Y"),
        )

        for string, format_string in STRING_FORMAT_PAIRS:
            produced_date = dates.date_from_string(string, format_string)
            T.assert_equal(produced_date, expected_date)

        BAD_FORMAT_PAIRS = (
            ("2013-5-10", "%m/%d/%Y"),
        )

        for string, format_string in BAD_FORMAT_PAIRS:
            with T.assert_raises(ValueError):
                dates.date_from_string(string, format_string)
Beispiel #2
0
    def test_format_string_parsing(self):
        expected_date = date(2013, 5, 10)

        STRING_FORMAT_PAIRS = (
            ("2013-5-10", "%Y-%m-%d"),
            ("2013-05-10", "%Y-%m-%d"),
            ("5-10-2013", "%m-%d-%Y"),
            ("5/10/2013", "%m/%d/%Y"),
        )

        for string, format_string in STRING_FORMAT_PAIRS:
            produced_date = dates.date_from_string(string, format_string)
            assert produced_date == expected_date

        BAD_FORMAT_PAIRS = (
            ("2013-5-10", "%m/%d/%Y"),
        )

        for string, format_string in BAD_FORMAT_PAIRS:
            with pytest.raises(ValueError):
                dates.date_from_string(string, format_string)
Beispiel #3
0
    def test_default_formats(self):
        expected_date = date(2013, 5, 15)

        ENABLED_DEFAULTS = (
            "2013-5-15",
            "2013-05-15",
            "5-15-2013",
            "5/15/2013",
            "15/5/2013",
        )

        for string in ENABLED_DEFAULTS:
            produced_date = dates.date_from_string(string)
            T.assert_equal(produced_date, expected_date)
Beispiel #4
0
    def test_default_formats(self):
        expected_date = date(2013, 5, 15)

        ENABLED_DEFAULTS = (
            "2013-5-15",
            "2013-05-15",
            "5-15-2013",
            "5/15/2013",
            "15/5/2013",
        )

        for string in ENABLED_DEFAULTS:
            produced_date = dates.date_from_string(string)
            assert produced_date == expected_date