File: test_cleanup.py

package info (click to toggle)
csvkit 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,664 kB
  • sloc: python: 4,924; perl: 1,000; makefile: 131; sql: 4
file content (36 lines) | stat: -rw-r--r-- 1,360 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import unittest

from csvkit.cleanup import join_rows


class TestCleanup(unittest.TestCase):

    def test_fix_rows(self):
        """Test to ensure that row merging yields correct results."""
        start = [['1', '2', '3'],
                 [''],
                 ['abc'],
                 ['4', '5'],
                 ]
        fixed = join_rows(start, ' ')
        self.assertEqual(4, len(fixed))
        self.assertEqual(start[0][0], fixed[0])
        self.assertEqual(start[0][1], fixed[1])
        self.assertEqual(" ".join([start[0][-1], start[1][0], start[2][0], start[3][0]]), fixed[2])
        self.assertEqual(start[3][1], fixed[3])

    def test_real_world_join_fail(self):
        start = [['168772', '1102', '$0.23 TO $0.72', 'HOUR', '1.5%'],
                 ['GROSS', '1.5% '],
                 ['GROSS', '430938']]
        fixed = join_rows(start, ' ')
        self.assertEqual(7, len(fixed))
        self.assertEqual(start[0][0], fixed[0])
        self.assertEqual(start[0][1], fixed[1])
        self.assertEqual(start[0][2], fixed[2])
        self.assertEqual(start[0][3], fixed[3])
        expected4 = " ".join([start[0][-1], start[1][0]])
        self.assertEqual(expected4, fixed[4])
        expected5 = " ".join([start[1][1], start[2][0]])
        self.assertEqual(expected5, fixed[5])
        self.assertEqual(start[2][1], fixed[6])