Exemple #1
0
    def test_id_field_is_not_in_output(self):
        csv_in1 = csv_reader('a,b,id')
        csv_in2 = csv_reader('c,d,id')
        csv_out = ReaderWriter()

        m.csvzip(csv_in1, csv_in2, csv_out)

        self.assertNotIn('id', csv_out.rows[0])
Exemple #2
0
    def test_id_field_is_not_in_output(self):
        csv_in1 = csv_reader('a,b,id')
        csv_in2 = csv_reader('c,d,id')
        csv_out = ReaderWriter()

        m.csvzip(csv_in1, csv_in2, csv_out)

        self.assertNotIn('id', csv_out.rows[0])
 def _reader(self):
     return csv_reader('''\
         b,a,c
         b1,a1,c1
         b2,a2,c2
         b1,a1,c3
         ''')
 def _reader(self):
     return csv_reader('''\
         b,a,c
         b1,a1,c1
         b2,a2,c2
         b1,a1,c3
         ''')
Exemple #5
0
    def test_mismatch_in_id_values_raises_error(self):
        csv_in1 = csv_reader('''\
            a,b,id
            a,b,1
            aa,bb,2''')
        csv_in2 = csv_reader('''\
            c,d,id
            c,d,1
            cc,dd,3''')
        csv_out = ReaderWriter()

        with self.assertRaises(m.IdMismatch):
            m.csvzip(csv_in1, csv_in2, csv_out)

        self.assertEqual(2, len(csv_out.rows))
        self.assertEqual('a b c d'.split(), csv_out.rows[0])
        self.assertEqual('a b c d'.split(), csv_out.rows[1])
Exemple #6
0
    def test_keep_id_id_field_is_in_output(self):
        csv_in1 = csv_reader('''\
            a,b,id
            a,b,1
            aa,bb,2''')
        csv_in2 = csv_reader('''\
            c,d,id
            c,d,1
            cc,dd,2''')
        csv_out = ReaderWriter()

        m.csvzip(csv_in1, csv_in2, csv_out, keep_id=True)

        self.assertEqual(3, len(csv_out.rows))
        self.assertEqual('id a b c d'.split(), csv_out.rows[0])
        self.assertEqual('1 a b c d'.split(), csv_out.rows[1])
        self.assertEqual('2 aa bb cc dd'.split(), csv_out.rows[2])
Exemple #7
0
    def test_normal_case(self):
        csv_in1 = csv_reader('''\
            a,b,id
            a,b,1
            aa,bb,2''')
        csv_in2 = csv_reader('''\
            c,d,id
            c,d,1
            cc,dd,2''')
        csv_out = ReaderWriter()

        m.csvzip(csv_in1, csv_in2, csv_out)

        self.assertEqual(3, len(csv_out.rows))
        self.assertEqual('a b c d'.split(), csv_out.rows[0])
        self.assertEqual('a b c d'.split(), csv_out.rows[1])
        self.assertEqual('aa bb cc dd'.split(), csv_out.rows[2])
Exemple #8
0
    def test_keep_id_id_field_is_in_output(self):
        csv_in1 = csv_reader('''\
            a,b,id
            a,b,1
            aa,bb,2''')
        csv_in2 = csv_reader('''\
            c,d,id
            c,d,1
            cc,dd,2''')
        csv_out = ReaderWriter()

        m.csvzip(csv_in1, csv_in2, csv_out, keep_id=True)

        self.assertEqual(3, len(csv_out.rows))
        self.assertEqual('id a b c d'.split(), csv_out.rows[0])
        self.assertEqual('1 a b c d'.split(), csv_out.rows[1])
        self.assertEqual('2 aa bb cc dd'.split(), csv_out.rows[2])
Exemple #9
0
    def test_normal_case(self):
        csv_in1 = csv_reader('''\
            a,b,id
            a,b,1
            aa,bb,2''')
        csv_in2 = csv_reader('''\
            c,d,id
            c,d,1
            cc,dd,2''')
        csv_out = ReaderWriter()

        m.csvzip(csv_in1, csv_in2, csv_out)

        self.assertEqual(3, len(csv_out.rows))
        self.assertEqual('a b c d'.split(), csv_out.rows[0])
        self.assertEqual('a b c d'.split(), csv_out.rows[1])
        self.assertEqual('aa bb cc dd'.split(), csv_out.rows[2])
Exemple #10
0
    def test_mismatch_in_id_values_raises_error(self):
        csv_in1 = csv_reader('''\
            a,b,id
            a,b,1
            aa,bb,2''')
        csv_in2 = csv_reader('''\
            c,d,id
            c,d,1
            cc,dd,3''')
        csv_out = ReaderWriter()

        with self.assertRaises(m.IdMismatch):
            m.csvzip(csv_in1, csv_in2, csv_out)

        self.assertEqual(2, len(csv_out.rows))
        self.assertEqual('a b c d'.split(), csv_out.rows[0])
        self.assertEqual('a b c d'.split(), csv_out.rows[1])
    def test_map_with_different_field_order_read_in_properly(self):
        reader = csv_reader('''\
            b,id,a
            b,1,a
            ''')
        appender = ReaderWriter()
        mapper = m.Mapper('id', ['a', 'b'], reader, appender)

        mapped_id = mapper.map(('a', 'b'))

        self.assertEqual(1, mapped_id)
    def test_map_with_different_field_order_read_in_properly(self):
        reader = csv_reader('''\
            b,id,a
            b,1,a
            ''')
        appender = ReaderWriter()
        mapper = m.Mapper('id', ['a', 'b'], reader, appender)

        mapped_id = mapper.map(('a', 'b'))

        self.assertEqual(1, mapped_id)
    def test_unsorted_map_with_gaps_works_correctly(self):
        reader = csv_reader('''\
            id,a,b
            5,aaa,bbb
            1,aa,bb
            ''')
        appender = ReaderWriter()
        mapper = m.Mapper('id', ['a', 'b'], reader, appender)

        mapped_id = mapper.map(('a3', 'b3'))

        self.assertEqual(6, mapped_id)
    def test_map_with_different_field_order_is_written_properly(self):
        reader = csv_reader('''\
            b,id,a
            b,1,a
            ''')
        appender = ReaderWriter()
        mapper = m.Mapper('id', ['a', 'b'], reader, appender)

        mapped_id = mapper.map(('aa', 'bb'))

        self.assertEqual(2, mapped_id)
        self.assertListEqual([['bb', 2, 'aa']], appender.rows)
    def test_unsorted_map_with_gaps_works_correctly(self):
        reader = csv_reader('''\
            id,a,b
            5,aaa,bbb
            1,aa,bb
            ''')
        appender = ReaderWriter()
        mapper = m.Mapper('id', ['a', 'b'], reader, appender)

        mapped_id = mapper.map(('a3', 'b3'))

        self.assertEqual(6, mapped_id)
    def test_map_with_different_field_order_is_written_properly(self):
        reader = csv_reader('''\
            b,id,a
            b,1,a
            ''')
        appender = ReaderWriter()
        mapper = m.Mapper('id', ['a', 'b'], reader, appender)

        mapped_id = mapper.map(('aa', 'bb'))

        self.assertEqual(2, mapped_id)
        self.assertListEqual([['bb', 2, 'aa']], appender.rows)
 def map_reader(self):
     return csv_reader('''\
         id,a,b
         1,aa,bb
         ''')
Exemple #18
0
 def test_two_common_fields_zip_raises_error(self):
     csv_in1 = csv_reader('a,b')
     csv_in2 = csv_reader('a,b')
     csv_out = ReaderWriter()
     with self.assertRaises(m.BadInput):
         m.csvzip(csv_in1, csv_in2, csv_out)
 def _mapper_reader(self):
     return csv_reader('''\
         other,id,a
         b1,1,a1
         b3,3,a3
         ''')
Exemple #20
0
 def test_two_common_fields_zip_raises_error(self):
     csv_in1 = csv_reader('a,b')
     csv_in2 = csv_reader('a,b')
     csv_out = ReaderWriter()
     with self.assertRaises(m.BadInput):
         m.csvzip(csv_in1, csv_in2, csv_out)
 def _mapper_reader(self):
     return csv_reader('''\
         other,id,a
         b1,1,a1
         b3,3,a3
         ''')
 def map_reader(self):
     return csv_reader('''\
         id,a,b
         1,aa,bb
         ''')