Beispiel #1
0
    def test_to_csv__dict(self):
        # Empty set
        source = {}
        self.assertEqual('[]', sl.to_csv(source))

        # One element
        source = {'key1': 1}
        self.assertEqual('[key1]', sl.to_csv(source))

        # Multiple, mixed elements
        source = {
            'keyNone': None,
            'keyTrue': True,
            'keyFalse': False,
            'key2': 2,
            'key3p4': 3.4,
            'keyFoobar': "foobar"
        }
        self.assertEqual('[key2,key3p4,keyFalse,keyFoobar,keyNone,keyTrue]',
                         sl.to_csv(source))

        # Alternate Brackets and Separator
        source = {
            'keyNone': None,
            'keyTrue': True,
            'keyFalse': False,
            'key2': 2,
            'key3p4': 3.4,
            'keyFoobar': "foobar"
        }
        self.assertEqual('<key2:key3p4:keyFalse:keyFoobar:keyNone:keyTrue>',
                         sl.to_csv(source, '<', '>', ':'))

        # With context
        source = {
            'keyNone': None,
            'keyTrue': True,
            'keyFalse': False,
            'key2': 2,
            'key3p4': 3.4,
            'keyFoobar': "foobar"
        }
        self.assertEqual(
            '["key2","key3p4","keyFalse","keyFoobar","keyNone","keyTrue"]',
            sl.to_csv(source, show_context=True))
Beispiel #2
0
    def test_to_csv__set(self):
        # Empty set
        source = set()
        self.assertEqual('[]', sl.to_csv(source))

        # One element
        source = {1}
        self.assertEqual('[1]', sl.to_csv(source))

        # Multiple, mixed elements
        source = {None, True, False, 2, 3.4, "foobar"}
        self.assertEqual('[2,3.4,false,foobar,null,true]', sl.to_csv(source))

        # Alternate Brackets and Separator
        source = {None, True, False, 2, 3.4, "foobar"}
        self.assertEqual('<2:3.4:false:foobar:null:true>',
                         sl.to_csv(source, '<', '>', ':'))

        # With context
        source = {None, True, False, 2, 3.4, "foobar"}
        self.assertEqual('["foobar",2,3.4,false,null,true]',
                         sl.to_csv(source, show_context=True))
Beispiel #3
0
    def test_to_csv__list(self):
        # Empty list
        source = []
        self.assertEqual('[]', sl.to_csv(source))

        # One element
        source = [1]
        self.assertEqual('[1]', sl.to_csv(source))

        # Multiple, mixed elements
        source = [None, True, False, 1, 2.3, "foobar"]
        self.assertEqual('[null,true,false,1,2.3,foobar]', sl.to_csv(source))

        # Alternate Brackets and Separator
        source = [None, True, False, 1, 2.3, "foobar"]
        self.assertEqual('<null:true:false:1:2.3:foobar>',
                         sl.to_csv(source, '<', '>', ':'))

        # With context
        source = [None, True, False, 1, 2.3, "foobar"]
        self.assertEqual('[null,true,false,1,2.3,"foobar"]',
                         sl.to_csv(source, show_context=True))
Beispiel #4
0
 def test_to_csv__object(self):
     source = HardException('foobar')
     self.assertEqual('[HardException: foobar]', sl.to_csv(source))
Beispiel #5
0
 def test_to_csv__none(self):
     source = None
     self.assertEqual('[]', sl.to_csv(source))