MCPcopy
hub / github.com/MagicStack/asyncpg / test_copy_to_table_from_file_path

Method test_copy_to_table_from_file_path

tests/test_copy.py:584–624  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

582 await self.con.execute('DROP TABLE copytab')
583
584 async def test_copy_to_table_from_file_path(self):
585 await self.con.execute('''
586 CREATE TABLE copytab(a text, "b~" text, i int);
587 ''')
588
589 f = tempfile.NamedTemporaryFile(delete=False)
590 try:
591 f.write(
592 '\n'.join([
593 'a1\tb1\t1',
594 'a2\tb2\t2',
595 'a3\tb3\t3',
596 'a4\tb4\t4',
597 'a5\tb5\t5',
598 '*\t\\N\t\\N',
599 ''
600 ]).encode('utf-8')
601 )
602 f.close()
603
604 res = await self.con.copy_to_table('copytab', source=f.name)
605 self.assertEqual(res, 'COPY 6')
606
607 output = await self.con.fetch("""
608 SELECT * FROM copytab ORDER BY a
609 """)
610 self.assertEqual(
611 output,
612 [
613 ('*', None, None),
614 ('a1', 'b1', 1),
615 ('a2', 'b2', 2),
616 ('a3', 'b3', 3),
617 ('a4', 'b4', 4),
618 ('a5', 'b5', 5),
619 ]
620 )
621
622 finally:
623 await self.con.execute('DROP TABLE public.copytab')
624 os.unlink(f.name)
625
626 async def test_copy_records_to_table_1(self):
627 await self.con.execute('''

Callers

nothing calls this directly

Calls 4

executeMethod · 0.45
closeMethod · 0.45
copy_to_tableMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected