Beispiel #1
0
 def test_bool_arg(self):
     # boolean arguments take *any* object and use its truth-value
     import _csv
     _csv.register_dialect('foo1', doublequote=[])
     assert _csv.get_dialect('foo1').doublequote == False
     _csv.register_dialect('foo1', skipinitialspace=2)
     assert _csv.get_dialect('foo1').skipinitialspace == True
     _csv.register_dialect('foo1', strict=_csv)    # :-/
     assert _csv.get_dialect('foo1').strict == True
Beispiel #2
0
 def test_bool_arg(self):
     # boolean arguments take *any* object and use its truth-value
     import _csv
     _csv.register_dialect('foo1', doublequote=[])
     assert _csv.get_dialect('foo1').doublequote == False
     _csv.register_dialect('foo1', skipinitialspace=2)
     assert _csv.get_dialect('foo1').skipinitialspace == True
     _csv.register_dialect('foo1', strict=_csv)    # :-/
     assert _csv.get_dialect('foo1').strict == True
Beispiel #3
0
 def test_register_dialect_base_1(self):
     import _csv
     _csv.register_dialect('foo1', escapechar='!')
     _csv.register_dialect('foo2', 'foo1', strict=True)
     d1 = _csv.get_dialect('foo1')
     assert d1.escapechar == '!'
     assert d1.strict == False
     d2 = _csv.get_dialect('foo2')
     assert d2.escapechar == '!'
     assert d2.strict == True
Beispiel #4
0
 def test_register_dialect_base_1(self):
     import _csv
     _csv.register_dialect('foo1', escapechar='!')
     _csv.register_dialect('foo2', 'foo1', strict=True)
     d1 = _csv.get_dialect('foo1')
     assert d1.escapechar == '!'
     assert d1.strict == False
     d2 = _csv.get_dialect('foo2')
     assert d2.escapechar == '!'
     assert d2.strict == True
Beispiel #5
0
    def test_register_dialect(self):
        import _csv

        attrs = [('delimiter', ','),
                 ('doublequote', True),
                 ('escapechar', None),
                 ('lineterminator', '\r\n'),
                 ('quotechar', '"'),
                 ('quoting', _csv.QUOTE_MINIMAL),
                 ('skipinitialspace', False),
                 ('strict', False),
                 ]

        for changeattr, newvalue in [('delimiter', ':'),
                                     ('doublequote', False),
                                     ('escapechar', '/'),
                                     ('lineterminator', '---\n'),
                                     ('quotechar', '%'),
                                     ('quoting', _csv.QUOTE_NONNUMERIC),
                                     ('skipinitialspace', True),
                                     ('strict', True)]:
            kwargs = {changeattr: newvalue}
            _csv.register_dialect('foo1', **kwargs)
            d = _csv.get_dialect('foo1')
            assert d.__class__.__name__ == 'Dialect'
            for attr, default in attrs:
                if attr == changeattr:
                    expected = newvalue
                else:
                    expected = default
                assert getattr(d, attr) == expected
Beispiel #6
0
    def test_register_dialect(self):
        import _csv

        attrs = [('delimiter', ','),
                 ('doublequote', True),
                 ('escapechar', None),
                 ('lineterminator', '\r\n'),
                 ('quotechar', '"'),
                 ('quoting', _csv.QUOTE_MINIMAL),
                 ('skipinitialspace', False),
                 ('strict', False),
                 ]

        for changeattr, newvalue in [('delimiter', ':'),
                                     ('doublequote', False),
                                     ('escapechar', '/'),
                                     ('lineterminator', '---\n'),
                                     ('quotechar', '%'),
                                     ('quoting', _csv.QUOTE_NONNUMERIC),
                                     ('skipinitialspace', True),
                                     ('strict', True)]:
            kwargs = {changeattr: newvalue}
            _csv.register_dialect('foo1', **kwargs)
            d = _csv.get_dialect('foo1')
            assert d.__class__.__name__ == 'Dialect'
            for attr, default in attrs:
                if attr == changeattr:
                    expected = newvalue
                else:
                    expected = default
                assert getattr(d, attr) == expected
Beispiel #7
0
 def test_register_dialect_base_2(self):
     import _csv
     class Foo1:
         escapechar = '?'
     _csv.register_dialect('foo2', Foo1, strict=True)
     d2 = _csv.get_dialect('foo2')
     assert d2.escapechar == '?'
     assert d2.strict == True
Beispiel #8
0
 def test_register_dialect_base_2(self):
     import _csv
     class Foo1:
         escapechar = '?'
     _csv.register_dialect('foo2', Foo1, strict=True)
     d2 = _csv.get_dialect('foo2')
     assert d2.escapechar == '?'
     assert d2.strict == True
Beispiel #9
0
 def test_pickle_dialect(self):
     import _csv
     import copy
     _csv.register_dialect('foo')
     raises(TypeError, copy.copy, _csv.get_dialect('foo'))
Beispiel #10
0
 def test_line_terminator(self):
     # lineterminator can be the empty string
     import _csv
     _csv.register_dialect('foo1', lineterminator='')
     assert _csv.get_dialect('foo1').lineterminator == ''
Beispiel #11
0
 def test_line_terminator(self):
     # lineterminator can be the empty string
     import _csv
     _csv.register_dialect('foo1', lineterminator='')
     assert _csv.get_dialect('foo1').lineterminator == ''