コード例 #1
0
    def test_keep_fields(self):
        with open('map.csv', 'w') as f:
            f.write('id,a\n5,a')
        reader = ReaderWriter()
        reader.rows = [('a', 'b'), ('a', 'b'), ('c', 'd')]
        writer = ReaderWriter()

        m.extract_map(reader, writer, 'map.csv', 'a', 'id', keep_fields=True)

        self.assertEqual(
            [('a', 'b', 'id'), ('a', 'b', 5), ('c', 'd', 6)],
            writer.rows)
コード例 #2
0
    def test_existing_map_used(self):
        with open('map.csv', 'w') as f:
            f.write('id,a\n5,a')
        reader = ReaderWriter()
        reader.rows = [('a', 'b'), ('a', 'b'), ('c', 'd')]
        writer = ReaderWriter()

        m.extract_map(reader, writer, 'map.csv', 'a', 'id')

        self.assertEqual(
            sorted([('b', 5), ('d', 6)]),
            sorted(writer.rows[1:]))
コード例 #3
0
    def test_changed_map_is_written_out(self):
        with open('map.csv', 'w') as f:
            f.write('id,a\n5,a')
        reader = ReaderWriter()
        reader.rows = [('a', 'b'), ('a', 'b'), ('c', 'd')]
        writer = ReaderWriter()

        m.extract_map(reader, writer, 'map.csv', 'a', 'id')

        with open('map.csv') as f:
            items = tuple(csv.reader(f))

        self.assertEqual(
            sorted((('id', 'a'), ('5', 'a'), ('6', 'c'))),
            map(tuple, sorted(items)))