(self)
| 364 | class TestCopyTo(tb.ConnectedTestCase): |
| 365 | |
| 366 | async def test_copy_to_table_basics(self): |
| 367 | await self.con.execute(''' |
| 368 | CREATE TABLE copytab(a text, "b~" text, i int); |
| 369 | ''') |
| 370 | |
| 371 | try: |
| 372 | f = io.BytesIO() |
| 373 | f.write( |
| 374 | '\n'.join([ |
| 375 | 'a1\tb1\t1', |
| 376 | 'a2\tb2\t2', |
| 377 | 'a3\tb3\t3', |
| 378 | 'a4\tb4\t4', |
| 379 | 'a5\tb5\t5', |
| 380 | '*\t\\N\t\\N', |
| 381 | '' |
| 382 | ]).encode('utf-8') |
| 383 | ) |
| 384 | f.seek(0) |
| 385 | |
| 386 | res = await self.con.copy_to_table('copytab', source=f) |
| 387 | self.assertEqual(res, 'COPY 6') |
| 388 | |
| 389 | output = await self.con.fetch(""" |
| 390 | SELECT * FROM copytab ORDER BY a |
| 391 | """) |
| 392 | self.assertEqual( |
| 393 | output, |
| 394 | [ |
| 395 | ('*', None, None), |
| 396 | ('a1', 'b1', 1), |
| 397 | ('a2', 'b2', 2), |
| 398 | ('a3', 'b3', 3), |
| 399 | ('a4', 'b4', 4), |
| 400 | ('a5', 'b5', 5), |
| 401 | ] |
| 402 | ) |
| 403 | |
| 404 | # Test parameters. |
| 405 | await self.con.execute('TRUNCATE copytab') |
| 406 | await self.con.execute('SET search_path=none') |
| 407 | |
| 408 | f.seek(0) |
| 409 | f.truncate() |
| 410 | |
| 411 | f.write( |
| 412 | '\n'.join([ |
| 413 | 'a|b~', |
| 414 | '*a1*|b1', |
| 415 | '*a2*|b2', |
| 416 | '*a3*|b3', |
| 417 | '*a4*|b4', |
| 418 | '*a5*|b5', |
| 419 | '*!**|*n-u-l-l*', |
| 420 | 'n-u-l-l|bb', |
| 421 | ]).encode('utf-8') |
| 422 | ) |
| 423 | f.seek(0) |
nothing calls this directly
no test coverage detected