コード例 #1
0
    def _validate(val, val_exp, field_type, driver):

        if field_type == 'date':
            return val == val_exp.isoformat()

        elif field_type == 'datetime':

            # some drivers do not support timezones. In this case, Fiona converts datetime fields with a timezone other
            # than UTC to UTC. Thus, both the datetime read by Fiona, as well as expected value are first converted to
            # UTC before compared.

            # Milliseconds
            if _driver_supports_milliseconds(driver):
                y, m, d, hh, mm, ss, ms, tz = parse_datetime(val)
                if tz is not None:
                    tz = TZ(tz)
                val_d = datetime.datetime(y, m, d, hh, mm, ss, ms, tz)
                return compare_datetimes_utc(val_d, val_exp)
            else:
                # No Milliseconds
                y, m, d, hh, mm, ss, ms, tz = parse_datetime(val)
                if tz is not None:
                    tz = TZ(tz)
                val_d = datetime.datetime(y, m, d, hh, mm, ss, ms, tz)
                return compare_datetimes_utc(val_d,
                                             val_exp.replace(microsecond=0))

        elif field_type == 'time':

            # some drivers do not support timezones. In this case, Fiona converts datetime fields with a timezone other
            # than UTC to UTC. Thus, both the time read by Fiona, as well as expected value are first converted to UTC
            # before compared.

            # Milliseconds
            if _driver_supports_milliseconds(driver):
                y, m, d, hh, mm, ss, ms, tz = parse_time(val)
                if tz is not None:
                    tz = TZ(tz)
                val_d = datetime.time(hh, mm, ss, ms, tz)
                return compare_times_utc(val_d, val_exp)
            else:
                # No Milliseconds
                y, m, d, hh, mm, ss, ms, tz = parse_time(val)
                if tz is not None:
                    tz = TZ(tz)
                val_d = datetime.time(hh, mm, ss, ms, tz)
                return compare_times_utc(val_d, val_exp.replace(microsecond=0))
        return False
コード例 #2
0
ファイル: test_rfc3339.py プロジェクト: olt/Fiona
 def test_yyyymmdd(self):
     y, m, d, hh, mm, ss, ff = parse_datetime("2012-01-29T10:11:12")
     self.failUnlessEqual(y, 2012)
     self.failUnlessEqual(m, 1)
     self.failUnlessEqual(d, 29)
     self.failUnlessEqual(hh, 10)
     self.failUnlessEqual(mm, 11)
     self.failUnlessEqual(ss, 12)
     self.failUnlessEqual(ff, 0.0)
コード例 #3
0
 def test_yyyymmdd(self):
     self.assertEqual(parse_datetime("2012-01-29T10:11:12"),
                      (2012, 1, 29, 10, 11, 12, 0.0))
コード例 #4
0
ファイル: test_rfc3339.py プロジェクト: jlivni/Fiona
 def test_yyyymmdd(self):
     self.failUnlessEqual(
         parse_datetime("2012-01-29T10:11:12"),
         (2012, 1, 29, 10, 11, 12, 0.0))
コード例 #5
0
 def test_error(self):
     with pytest.raises(ValueError):
         parse_datetime("xxx")
コード例 #6
0
 def test_yyyymmdd(self):
     assert (parse_datetime("2012-01-29T10:11:12") == (2012, 1, 29, 10, 11,
                                                       12, 0.0))
コード例 #7
0
ファイル: test_rfc3339.py プロジェクト: Toblerity/Fiona
 def test_error(self):
     with pytest.raises(ValueError):
         parse_datetime("xxx")
コード例 #8
0
ファイル: test_rfc3339.py プロジェクト: Toblerity/Fiona
 def test_yyyymmdd(self):
     assert (
         parse_datetime("2012-01-29T10:11:12") ==
         (2012, 1, 29, 10, 11, 12, 0.0))
コード例 #9
0
ファイル: test_rfc3339.py プロジェクト: vishalbelsare/Fiona
 def test_yyyymmddTZ(self):
     assert (parse_datetime("2012-01-29T10:11:12+01:30") == (2012, 1, 29,
                                                             10, 11, 12,
                                                             0.0, 90))