(self)
| 19 | class TestCopyFrom(tb.ConnectedTestCase): |
| 20 | |
| 21 | async def test_copy_from_table_basics(self): |
| 22 | await self.con.execute(''' |
| 23 | CREATE TABLE copytab(a text, "b~" text, i int); |
| 24 | INSERT INTO copytab (a, "b~", i) ( |
| 25 | SELECT 'a' || i::text, 'b' || i::text, i |
| 26 | FROM generate_series(1, 5) AS i |
| 27 | ); |
| 28 | INSERT INTO copytab (a, "b~", i) VALUES('*', NULL, NULL); |
| 29 | ''') |
| 30 | |
| 31 | try: |
| 32 | f = io.BytesIO() |
| 33 | |
| 34 | # Basic functionality. |
| 35 | res = await self.con.copy_from_table('copytab', output=f) |
| 36 | |
| 37 | self.assertEqual(res, 'COPY 6') |
| 38 | |
| 39 | output = f.getvalue().decode().split('\n') |
| 40 | self.assertEqual( |
| 41 | output, |
| 42 | [ |
| 43 | 'a1\tb1\t1', |
| 44 | 'a2\tb2\t2', |
| 45 | 'a3\tb3\t3', |
| 46 | 'a4\tb4\t4', |
| 47 | 'a5\tb5\t5', |
| 48 | '*\t\\N\t\\N', |
| 49 | '' |
| 50 | ] |
| 51 | ) |
| 52 | |
| 53 | # Test parameters. |
| 54 | await self.con.execute('SET search_path=none') |
| 55 | |
| 56 | f.seek(0) |
| 57 | f.truncate() |
| 58 | |
| 59 | res = await self.con.copy_from_table( |
| 60 | 'copytab', output=f, columns=('a', 'b~'), |
| 61 | schema_name='public', format='csv', |
| 62 | delimiter='|', null='n-u-l-l', header=True, |
| 63 | quote='*', escape='!', force_quote=('a',)) |
| 64 | |
| 65 | output = f.getvalue().decode().split('\n') |
| 66 | |
| 67 | self.assertEqual( |
| 68 | output, |
| 69 | [ |
| 70 | 'a|b~', |
| 71 | '*a1*|b1', |
| 72 | '*a2*|b2', |
| 73 | '*a3*|b3', |
| 74 | '*a4*|b4', |
| 75 | '*a5*|b5', |
| 76 | '*!**|n-u-l-l', |
| 77 | '' |
| 78 | ] |
nothing calls this directly
no test coverage detected