Esempio n. 1
0
 def test_raises_exception_when_instantiating_invalid_dates(self):
     with self.assertRaises(ValueError):
         XSDDate(2014, 2, 50)
     with self.assertRaises(ValueError):
         XSDDate(2014, 13, 10)
     with self.assertRaises(ValueError):
         XSDDate(2011, 2, 29)
Esempio n. 2
0
    def test_supports_very_distant_dates(self):
        raise SkipTest('XSDDate can currently only represent the value range of datetime.date')
        future = XSDDate(12345, 4, 21)
        assert_equals(12345, future.year)

        past = XSDDate(-12345, 4, 21)
        assert_equals(-12345, past.year)
Esempio n. 3
0
    def test_parsing(self):
        self.assert_parse(None, None)
        self.assert_parse(None, 'nil')
        self.assert_parse(XSDDate(2012, 10, 26), '2012-10-26')
        self.assert_parse(XSDDate(2016, 2, 29, tzinfo=UTC), '2016-02-29Z')
        parsed_date = self._parse('2012-02-29+01:00')
        assert_equals(date(2012, 2, 29), parsed_date.as_datetime_date())
        self.assert_same_tz(FixedOffset(1, 0, '+01:00'), parsed_date.tzinfo)

        parsed_date = self._parse('2012-02-29-02:30')
        assert_equals(date(2012, 2, 29), parsed_date.as_datetime_date())
        self.assert_same_tz(FixedOffset(-2, -30, '-02:30'), parsed_date.tzinfo)
Esempio n. 4
0
 def test_rendering_timezones(self):
     date_ = XSDDate(2001,
                     10,
                     26,
                     tzinfo=timezone(timedelta(hours=1, minutes=15)))
     rendered_xml = self.xsd_type().xmlvalue(date_)
     self.assertEqual('2001-10-26+01:15', rendered_xml)
Esempio n. 5
0
    def test_parsing(self):
        self.assert_parse(None, None)
        self.assert_parse(None, 'nil')
        self.assert_parse(XSDDate(2012, 10, 26), '2012-10-26')
        self.assert_parse(XSDDate(2016, 2, 29, tzinfo=timezone.utc),
                          '2016-02-29Z')
        parsed_date = self._parse('2012-02-29+01:00')
        self.assertEqual(date(2012, 2, 29), parsed_date.as_datetime_date())
        self.assertEqual(
            timezone(timedelta(hours=1)).utcoffset(None),
            parsed_date.tzinfo.utcoffset(None))

        parsed_date = self._parse('2012-02-29-02:30')
        self.assertEqual(date(2012, 2, 29), parsed_date.as_datetime_date())
        self.assertEqual(
            timezone(-timedelta(hours=2, minutes=30)).utcoffset(None),
            parsed_date.tzinfo.utcoffset(None))
Esempio n. 6
0
    def test_accepts_only_compatible_types(self):
        self.assert_can_set(None)
        self.assert_can_set(XSDDate(2012, 10, 26))
        self.assert_can_set(date(2013, 10, 26))

        self.assert_can_not_set(0)
        self.assert_can_not_set([])
        self.assert_can_not_set('invalid')
        self.assert_can_not_set(datetime(2013, 10, 26))
Esempio n. 7
0
 def test_can_instantiate_with_valid_dates(self):
     assert_equals(2014, XSDDate(2014, 11, 13).year)
     assert_equals(2012, XSDDate(2012, 2, 29).year)
Esempio n. 8
0
 def test_raises_exception_when_instantiating_invalid_dates(self):
     assert_raises(ValueError, lambda: XSDDate(2014, 2, 50))
     assert_raises(ValueError, lambda: XSDDate(2014, 13, 10))
     assert_raises(ValueError, lambda: XSDDate(2011, 2, 29))
Esempio n. 9
0
 def test_rendering_timezones(self):
     fake_tz = FixedOffset(1, 15, 'dummy zone')
     date_ = XSDDate(2001, 10, 26, tzinfo=fake_tz)
     rendered_xml = xsd.Date().xmlvalue(date_)
     assert_equals('2001-10-26+01:15', rendered_xml)
Esempio n. 10
0
 def test_rendering_timezones(self):
     date_ = XSDDate(2001, 10, 26, tzinfo=iso8601.FixedOffset(1, 15, 'dummy zone'))
     rendered_xml = self.xsd_type().xmlvalue(date_)
     assert_equals('2001-10-26+01:15', rendered_xml)
Esempio n. 11
0
 def test_can_instantiate_with_valid_dates(self):
     self.assertEqual(2014, XSDDate(2014, 11, 13).year)
     self.assertEqual(2012, XSDDate(2012, 2, 29).year)
Esempio n. 12
0
    def test_supports_very_distant_dates(self):
        future = XSDDate(12345, 4, 21)
        self.assertEqual(12345, future.year)

        past = XSDDate(-12345, 4, 21)
        self.assertEqual(-12345, past.year)