Ejemplo n.º 1
0
 def test_upgrademapper(self):
     "Tests updatemapper"
     import dateutil.parser
     import datetime
     dateparser = dateutil.parser.parse
     StringConverter.upgrade_mapper(dateparser, datetime.date(2000, 1, 1))
     convert = StringConverter(dateparser, datetime.date(2000, 1, 1))
     test = convert('2001-01-01')
     assert_equal(test, datetime.datetime(2001, 01, 01, 00, 00, 00))
Ejemplo n.º 2
0
 def test_upgrademapper(self):
     "Tests updatemapper"
     import dateutil.parser
     import datetime
     dateparser = dateutil.parser.parse
     StringConverter.upgrade_mapper(dateparser, datetime.date(2000,1,1))
     convert = StringConverter(dateparser, datetime.date(2000, 1, 1))
     test = convert('2001-01-01')
     assert_equal(test, datetime.datetime(2001, 01, 01, 00, 00, 00))
Ejemplo n.º 3
0
 def test_upgrademapper(self):
     "Tests updatemapper"
     dateparser = _bytes_to_date
     StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
     convert = StringConverter(dateparser, date(2000, 1, 1))
     test = convert(b'2001-01-01')
     assert_equal(test, date(2001, 1, 1))
     test = convert(b'2009-01-01')
     assert_equal(test, date(2009, 1, 1))
     test = convert(b'')
     assert_equal(test, date(2000, 1, 1))
Ejemplo n.º 4
0
 def test_upgrademapper(self):
     "Tests updatemapper"
     dateparser = _bytes_to_date
     StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
     convert = StringConverter(dateparser, date(2000, 1, 1))
     test = convert(asbytes('2001-01-01'))
     assert_equal(test, date(2001, 1, 1))
     test = convert(asbytes('2009-01-01'))
     assert_equal(test, date(2009, 1, 1))
     test = convert(asbytes(''))
     assert_equal(test, date(2000, 1, 1))
 def test_upgrade(self):
     "Tests the upgrade method."
     converter = StringConverter()
     assert_equal(converter._status, 0)
     converter.upgrade('0')
     assert_equal(converter._status, 1)
     converter.upgrade('0.')
     assert_equal(converter._status, 2)
     converter.upgrade('0j')
     assert_equal(converter._status, 3)
     converter.upgrade('a')
     assert_equal(converter._status, len(converter._mapper) - 1)
 def test_missing(self):
     "Tests the use of missing values."
     converter = StringConverter(missing_values=('missing', 'missed'))
     converter.upgrade('0')
     assert_equal(converter('0'), 0)
     assert_equal(converter(''), converter.default)
     assert_equal(converter('missing'), converter.default)
     assert_equal(converter('missed'), converter.default)
     try:
         converter('miss')
     except ValueError:
         pass
Ejemplo n.º 7
0
 def test_missing(self):
     "Tests the use of missing values."
     converter = StringConverter(missing_values=("missing", "missed"))
     converter.upgrade("0")
     assert_equal(converter("0"), 0)
     assert_equal(converter(""), converter.default)
     assert_equal(converter("missing"), converter.default)
     assert_equal(converter("missed"), converter.default)
     try:
         converter("miss")
     except ValueError:
         pass
Ejemplo n.º 8
0
 def test_missing(self):
     "Tests the use of missing values."
     converter = StringConverter(missing_values=("missing", "missed"))
     converter.upgrade("0")
     assert_equal(converter("0"), 0)
     assert_equal(converter(""), converter.default)
     assert_equal(converter("missing"), converter.default)
     assert_equal(converter("missed"), converter.default)
     try:
         converter("miss")
     except ValueError:
         pass
Ejemplo n.º 9
0
 def test_missing(self):
     "Tests the use of missing values."
     converter = StringConverter(missing_values=('missing','missed'))
     converter.upgrade('0')
     assert_equal(converter('0'), 0)
     assert_equal(converter(''), converter.default)
     assert_equal(converter('missing'), converter.default)
     assert_equal(converter('missed'), converter.default)
     try:
         converter('miss')
     except ValueError:
         pass
 def test_upgrademapper(self):
     "Tests updatemapper"
     from datetime import date
     import time
     dateparser = lambda s: date(*time.strptime(s, "%Y-%m-%d")[:3])
     StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
     convert = StringConverter(dateparser, date(2000, 1, 1))
     test = convert('2001-01-01')
     assert_equal(test, date(2001, 01, 01))
     test = convert('2009-01-01')
     assert_equal(test, date(2009, 01, 01))
     test = convert('')
     assert_equal(test, date(2000, 01, 01))
Ejemplo n.º 11
0
 def test_upgrademapper(self):
     "Tests updatemapper"
     from datetime import date
     import time
     dateparser = lambda s : date(*time.strptime(s, "%Y-%m-%d")[:3])
     StringConverter.upgrade_mapper(dateparser, date(2000,1,1))
     convert = StringConverter(dateparser, date(2000, 1, 1))
     test = convert('2001-01-01')
     assert_equal(test, date(2001, 01, 01))
     test = convert('2009-01-01')
     assert_equal(test, date(2009, 01, 01))
     test = convert('')
     assert_equal(test, date(2000, 01, 01))
Ejemplo n.º 12
0
    def test_upgrademapper(self):
        "Tests updatemapper"
        if hasattr(sys, 'gettotalrefcount'):
            # skip this test when Python was compiled using --with-pydebug
            return

        dateparser = _bytes_to_date
        StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
        convert = StringConverter(dateparser, date(2000, 1, 1))
        test = convert(asbytes('2001-01-01'))
        assert_equal(test, date(2001, 01, 01))
        test = convert(asbytes('2009-01-01'))
        assert_equal(test, date(2009, 01, 01))
        test = convert(asbytes(''))
        assert_equal(test, date(2000, 01, 01))
Ejemplo n.º 13
0
 def test_upgrademapper(self):
     "Tests updatemapper"
     dateparser = _bytes_to_date
     _original_mapper = StringConverter._mapper[:]
     try:
         StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
         convert = StringConverter(dateparser, date(2000, 1, 1))
         test = convert('2001-01-01')
         assert_equal(test, date(2001, 1, 1))
         test = convert('2009-01-01')
         assert_equal(test, date(2009, 1, 1))
         test = convert('')
         assert_equal(test, date(2000, 1, 1))
     finally:
         StringConverter._mapper = _original_mapper
Ejemplo n.º 14
0
    def test_upgrademapper(self):
        "Tests updatemapper"
        if hasattr(sys, 'gettotalrefcount'):
            # skip this test when Python was compiled using --with-pydebug
            return

        dateparser = _bytes_to_date
        StringConverter.upgrade_mapper(dateparser, date(2000, 1, 1))
        convert = StringConverter(dateparser, date(2000, 1, 1))
        test = convert(asbytes('2001-01-01'))
        assert_equal(test, date(2001, 01, 01))
        test = convert(asbytes('2009-01-01'))
        assert_equal(test, date(2009, 01, 01))
        test = convert(asbytes(''))
        assert_equal(test, date(2000, 01, 01))
Ejemplo n.º 15
0
 def test_upgrade(self):
     "Tests the upgrade method."
     converter = StringConverter()
     assert_equal(converter._status, 0)
     converter.upgrade("0")
     assert_equal(converter._status, 1)
     converter.upgrade("0.")
     assert_equal(converter._status, 2)
     converter.upgrade("0j")
     assert_equal(converter._status, 3)
     converter.upgrade("a")
     assert_equal(converter._status, len(converter._mapper) - 1)
Ejemplo n.º 16
0
 def test_upgrade(self):
     "Tests the upgrade method."
     converter = StringConverter()
     assert_equal(converter._status, 0)
     converter.upgrade(asbytes('0'))
     assert_equal(converter._status, 1)
     converter.upgrade(asbytes('0.'))
     assert_equal(converter._status, 2)
     converter.upgrade(asbytes('0j'))
     assert_equal(converter._status, 3)
     converter.upgrade(asbytes('a'))
     assert_equal(converter._status, len(converter._mapper) - 1)
Ejemplo n.º 17
0
 def test_keep_missing_values(self):
     "Check that we're not losing missing values"
     converter = StringConverter(int,
                                 default=0,
                                 missing_values=asbytes("N/A"))
     assert_equal(converter.missing_values, set(asbytes_nested(['',
                                                                'N/A'])))
 def test_string_to_object(self):
     "Make sure that string-to-object functions are properly recognized"
     from datetime import date
     import time
     conv = StringConverter(lambda s: date(*(time.strptime(s)[:3])))
     assert_equal(conv._mapper[-2][0](0), 0j)
     assert (hasattr(conv, 'default'))
Ejemplo n.º 19
0
 def test_upgrade(self):
     "Tests the upgrade method."
     converter = StringConverter()
     assert_equal(converter._status, 0)
     # test int
     assert_equal(converter.upgrade(asbytes('0')), 0)
     assert_equal(converter._status, 1)
     # test float
     assert_allclose(converter.upgrade(asbytes('0.')), 0.0)
     assert_equal(converter._status, 2)
     # test complex
     assert_equal(converter.upgrade(asbytes('0j')), complex('0j'))
     assert_equal(converter._status, 3)
     # test str
     assert_equal(converter.upgrade(asbytes('a')), asbytes('a'))
     assert_equal(converter._status, len(converter._mapper) - 1)
Ejemplo n.º 20
0
 def test_int64_dtype(self):
     "Check that int64 integer types can be specified"
     converter = StringConverter(np.int64, default=0)
     val = "-9223372036854775807"
     assert_(converter(val) == -9223372036854775807)
     val = "9223372036854775807"
     assert_(converter(val) == 9223372036854775807)
Ejemplo n.º 21
0
    def test_upgrade(self):
        "Tests the upgrade method."

        converter = StringConverter()
        assert_equal(converter._status, 0)

        # test int
        assert_equal(converter.upgrade(b'0'), 0)
        assert_equal(converter._status, 1)

        # On systems where integer defaults to 32-bit, the statuses will be
        # offset by one, so we check for this here.
        import numpy.core.numeric as nx
        status_offset = int(nx.dtype(nx.integer).itemsize < nx.dtype(nx.int64).itemsize)

        # test int > 2**32
        assert_equal(converter.upgrade(b'17179869184'), 17179869184)
        assert_equal(converter._status, 1 + status_offset)

        # test float
        assert_allclose(converter.upgrade(b'0.'), 0.0)
        assert_equal(converter._status, 2 + status_offset)

        # test complex
        assert_equal(converter.upgrade(b'0j'), complex('0j'))
        assert_equal(converter._status, 3 + status_offset)

        # test str
        assert_equal(converter.upgrade(b'a'), b'a')
        assert_equal(converter._status, len(converter._mapper) - 1)
Ejemplo n.º 22
0
 def test_keep_default(self):
     "Make sure we don't lose an explicit default"
     converter = StringConverter(None, missing_values="", default=-999)
     converter.upgrade("3.14159265")
     assert_equal(converter.default, -999)
     assert_equal(converter.type, np.dtype(float))
     #
     converter = StringConverter(None, missing_values="", default=0)
     converter.upgrade("3.14159265")
     assert_equal(converter.default, 0)
     assert_equal(converter.type, np.dtype(float))
Ejemplo n.º 23
0
 def test_keep_default(self):
     "Make sure we don't lose an explicit default"
     converter = StringConverter(None, missing_values="", default=-999)
     converter.upgrade("3.14159265")
     assert_equal(converter.default, -999)
     assert_equal(converter.type, np.dtype(float))
     #
     converter = StringConverter(None, missing_values="", default=0)
     converter.upgrade("3.14159265")
     assert_equal(converter.default, 0)
     assert_equal(converter.type, np.dtype(float))
Ejemplo n.º 24
0
 def test_upgrade(self):
     "Tests the upgrade method."
     converter = StringConverter()
     assert_equal(converter._status, 0)
     # test int
     assert_equal(converter.upgrade(asbytes('0')), 0)
     assert_equal(converter._status, 1)
     # test float
     assert_allclose(converter.upgrade(asbytes('0.')), 0.0)
     assert_equal(converter._status, 2)
     # test complex
     assert_equal(converter.upgrade(asbytes('0j')), complex('0j'))
     assert_equal(converter._status, 3)
     # test str
     assert_equal(converter.upgrade(asbytes('a')), asbytes('a'))
     assert_equal(converter._status, len(converter._mapper) - 1)
Ejemplo n.º 25
0
    def test_upgrade(self):
        "Tests the upgrade method."

        converter = StringConverter()
        assert_equal(converter._status, 0)

        # test int
        assert_equal(converter.upgrade("0"), 0)
        assert_equal(converter._status, 1)

        # On systems where long defaults to 32-bit, the statuses will be
        # offset by one, so we check for this here.
        import numpy.core.numeric as nx

        status_offset = int(
            nx.dtype(nx.int_).itemsize < nx.dtype(nx.int64).itemsize)

        # test int > 2**32
        assert_equal(converter.upgrade("17179869184"), 17179869184)
        assert_equal(converter._status, 1 + status_offset)

        # test float
        assert_allclose(converter.upgrade("0."), 0.0)
        assert_equal(converter._status, 2 + status_offset)

        # test complex
        assert_equal(converter.upgrade("0j"), complex("0j"))
        assert_equal(converter._status, 3 + status_offset)

        # test str
        # note that the longdouble type has been skipped, so the
        # _status increases by 2. Everything should succeed with
        # unicode conversion (8).
        for s in ["a", b"a"]:
            res = converter.upgrade(s)
            assert_(type(res) is str)
            assert_equal(res, "a")
            assert_equal(converter._status, 8 + status_offset)
Ejemplo n.º 26
0
    def test_upgrade(self):
        "Tests the upgrade method."

        converter = StringConverter()
        assert_equal(converter._status, 0)

        # test int
        assert_equal(converter.upgrade('0'), 0)
        assert_equal(converter._status, 1)

        # On systems where long defaults to 32-bit, the statuses will be
        # offset by one, so we check for this here.
        import numpy.core.numeric as nx
        status_offset = int(nx.dtype(nx.int_).itemsize < nx.dtype(nx.int64).itemsize)

        # test int > 2**32
        assert_equal(converter.upgrade('17179869184'), 17179869184)
        assert_equal(converter._status, 1 + status_offset)

        # test float
        assert_allclose(converter.upgrade('0.'), 0.0)
        assert_equal(converter._status, 2 + status_offset)

        # test complex
        assert_equal(converter.upgrade('0j'), complex('0j'))
        assert_equal(converter._status, 3 + status_offset)

        # test str
        # note that the longdouble type has been skipped, so the
        # _status increases by 2. Everything should succeed with
        # unicode conversion (5).
        for s in ['a', u'a', b'a']:
            res = converter.upgrade(s)
            assert_(type(res) is unicode)
            assert_equal(res, u'a')
            assert_equal(converter._status, 5 + status_offset)
Ejemplo n.º 27
0
 def test_uint64_dtype(self):
     "Check that uint64 integer types can be specified"
     converter = StringConverter(np.uint64, default=0)
     val = "9223372043271415339"
     assert_(converter(val) == 9223372043271415339)
Ejemplo n.º 28
0
 def test_keep_missing_values(self):
     "Check that we're not losing missing values"
     converter = StringConverter(int, default=0,
                                 missing_values="N/A")
     assert_equal(
         converter.missing_values, {'', 'N/A'})
Ejemplo n.º 29
0
 def test_keep_default_zero(self):
     "Check that we don't lose a default of 0"
     converter = StringConverter(int, default=0,
                                 missing_values="N/A")
     assert_equal(converter.default, 0)
Ejemplo n.º 30
0
 def test_string_to_object(self):
     "Make sure that string-to-object functions are properly recognized"
     old_mapper = StringConverter._mapper[:]  # copy of list
     conv = StringConverter(_bytes_to_date)
     assert_equal(conv._mapper, old_mapper)
     assert_(hasattr(conv, 'default'))
Ejemplo n.º 31
0
 def test_creation(self):
     "Test creation of a StringConverter"
     converter = StringConverter(int, -99999)
     assert_equal(converter._status, 1)
     assert_equal(converter.default, -99999)
Ejemplo n.º 32
0
 def test_string_to_object(self):
     "Make sure that string-to-object functions are properly recognized"
     conv = StringConverter(_bytes_to_date)
     assert_equal(conv._mapper[-2][0](0), 0j)
     assert_(hasattr(conv, 'default'))