Exemplo n.º 1
0
  def test_validate_datetime(self):
    self.assertEqual(importer.validate_datetime("2010-01-01T00:00:00Z"),
                     datetime.datetime(2010, 1, 1, 0, 0, 0))
    self.assertEqual(importer.validate_datetime("2010-01-01T01:23:45Z"),
                     datetime.datetime(2010, 1, 1, 1, 23, 45))

    self.assertEqual(importer.validate_datetime(""), None)
    self.assertEqual(importer.validate_datetime(0), None)

    self.assertRaises(ValueError, importer.validate_datetime, " ")
    self.assertRaises(ValueError, importer.validate_datetime, "2010-02-28")
    self.assertRaises(ValueError,
                      importer.validate_datetime,
                      "2010-02-28 01:23:45")
    self.assertRaises(ValueError,
                      importer.validate_datetime,
                      "2010-02-28 01:23:45Z")
    self.assertRaises(ValueError,
                      importer.validate_datetime,
                      "2010-02-28 1:23:45")

    # Invalid format
    self.assertRaises(ValueError,
                      importer.validate_datetime,
                      "2010-02-28T1:23:45Z")
    # Invalid date
    self.assertRaises(ValueError,
                      importer.validate_datetime,
                      "2010-02-29T01:23:45Z")
    # Invalid time
    self.assertRaises(ValueError,
                      importer.validate_datetime,
                      "2010-01-01T25:00:00Z")
    def test_validate_datetime(self):
        assert importer.validate_datetime('2010-01-01T00:00:00Z') == \
            datetime.datetime(2010, 1, 1, 0, 0, 0)
        assert importer.validate_datetime('2010-01-01T01:23:45Z') == \
            datetime.datetime(2010, 1, 1, 1, 23, 45)

        assert importer.validate_datetime('') == None
        assert importer.validate_datetime(0) == None

        assert_raises(ValueError, importer.validate_datetime, ' ')
        assert_raises(ValueError, importer.validate_datetime, '2010-02-28')
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-28 01:23:45')
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-28 01:23:45Z')
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-28 1:23:45')

        # Invalid format
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-28T1:23:45Z')
        # Invalid date
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-29T01:23:45Z')
        # Invalid time
        assert_raises(
            ValueError, importer.validate_datetime, '2010-01-01T25:00:00Z')
Exemplo n.º 3
0
    def test_validate_datetime(self):
        assert importer.validate_datetime('2010-01-01T00:00:00Z') == \
            datetime.datetime(2010, 1, 1, 0, 0, 0)
        assert importer.validate_datetime('2010-01-01T01:23:45Z') == \
            datetime.datetime(2010, 1, 1, 1, 23, 45)

        assert importer.validate_datetime('') == None
        assert importer.validate_datetime(0) == None

        assert_raises(ValueError, importer.validate_datetime, ' ')
        assert_raises(ValueError, importer.validate_datetime, '2010-02-28')
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-28 01:23:45')
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-28 01:23:45Z')
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-28 1:23:45')

        # Invalid format
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-28T1:23:45Z')
        # Invalid date
        assert_raises(
            ValueError, importer.validate_datetime, '2010-02-29T01:23:45Z')
        # Invalid time
        assert_raises(
            ValueError, importer.validate_datetime, '2010-01-01T25:00:00Z')
Exemplo n.º 4
0
    def test_validate_datetime(self):
        assert importer.validate_datetime('2010-01-01T00:00:00Z') == \
            datetime.datetime(2010, 1, 1, 0, 0, 0)
        assert importer.validate_datetime('2010-01-01T01:23:45Z') == \
            datetime.datetime(2010, 1, 1, 1, 23, 45)

        assert importer.validate_datetime('') == None
        assert importer.validate_datetime(0) == None

        raises(ValueError, importer.validate_datetime, ' ')
        raises(ValueError, importer.validate_datetime, '2010-02-28')
        raises(ValueError, importer.validate_datetime, '2010-02-28 01:23:45')
        raises(ValueError, importer.validate_datetime, '2010-02-28 01:23:45Z')
        raises(ValueError, importer.validate_datetime, '2010-02-28 1:23:45')