|  | 
|  | 1 | +import unittest | 
|  | 2 | +from janrain_datalib.utils import to_csv | 
|  | 3 | + | 
|  | 4 | +class TestUtils(unittest.TestCase): | 
|  | 5 | + | 
|  | 6 | +    def test_to_csv_with_no_delimiter(self): | 
|  | 7 | +        # setup | 
|  | 8 | +        input = ['first', '2nd,with,commas', 'lasty'] | 
|  | 9 | +        expected = 'first,"2nd,with,commas",lasty\r\n' | 
|  | 10 | +        # call | 
|  | 11 | +        result = to_csv(input) | 
|  | 12 | +        # test | 
|  | 13 | +        self.assertEqual(result, expected) | 
|  | 14 | + | 
|  | 15 | +    def test_to_csv_with_None_as_delimiter(self): | 
|  | 16 | +        # setup | 
|  | 17 | +        input = ['first', '2nd,with,commas', 'lasty'] | 
|  | 18 | +        expected = 'first,"2nd,with,commas",lasty\r\n' | 
|  | 19 | +        delimiter = None | 
|  | 20 | +        # call | 
|  | 21 | +        result = to_csv(input, delimiter=delimiter) | 
|  | 22 | +        # test | 
|  | 23 | +        self.assertEqual(result, expected) | 
|  | 24 | + | 
|  | 25 | +    def test_to_csv_with_bar_delimiter(self): | 
|  | 26 | +        # setup | 
|  | 27 | +        input = ['first', '2nd,with,commas', 'lasty'] | 
|  | 28 | +        expected = 'first|2nd,with,commas|lasty\r\n' | 
|  | 29 | +        delimiter = '|' | 
|  | 30 | +        # call | 
|  | 31 | +        result = to_csv(input, delimiter=delimiter) | 
|  | 32 | +        # test | 
|  | 33 | +        self.assertEqual(result, expected) | 
|  | 34 | + | 
|  | 35 | +    def test_to_csv_with_semicolon_delimiter(self): | 
|  | 36 | +        # setup | 
|  | 37 | +        input = ['first', '2nd,with,commas', 'lasty'] | 
|  | 38 | +        expected = 'first;2nd,with,commas;lasty\r\n' | 
|  | 39 | +        delimiter = ';' | 
|  | 40 | +        # call | 
|  | 41 | +        result = to_csv(input, delimiter=delimiter) | 
|  | 42 | +        # test | 
|  | 43 | +        self.assertEqual(result, expected) | 
0 commit comments