|
| 1 | +import click |
1 | 2 | import json |
2 | 3 | import pytest |
3 | | -import sys |
4 | 4 | from click.testing import CliRunner |
5 | 5 |
|
6 | 6 | from sqlite_utils import Database, cli |
@@ -307,21 +307,14 @@ def test_memory_functions(): |
307 | 307 | assert result.output.strip() == '[{"hello()": "Hello"}]' |
308 | 308 |
|
309 | 309 |
|
310 | | -@pytest.mark.parametrize("enabled", (False, True)) |
311 | | -def test_memory_named_database_hack(enabled): |
| 310 | +def test_memory_return_db(tmpdir): |
312 | 311 | # https://github.com/simonw/sqlite-utils/issues/643 |
313 | | - sys._sqlite_utils_memory_test = enabled |
314 | | - try: |
315 | | - result = CliRunner().invoke( |
316 | | - cli.cli, |
317 | | - ["memory", "-", "--analyze"], |
318 | | - input="id,name\n1,Cleo\n2,Bants", |
319 | | - ) |
320 | | - assert result.exit_code == 0 |
321 | | - db = Database(memory_name="sqlite_utils_memory") |
322 | | - if enabled: |
323 | | - assert db.table_names() == ["stdin"] |
324 | | - else: |
325 | | - assert db.table_names() == [] |
326 | | - finally: |
327 | | - sys._sqlite_utils_memory_test = False |
| 312 | + from sqlite_utils.cli import cli |
| 313 | + |
| 314 | + path = str(tmpdir / "dogs.csv") |
| 315 | + open(path, "w").write("id,name\n1,Cleo") |
| 316 | + |
| 317 | + with click.Context(cli) as ctx: |
| 318 | + db = ctx.invoke(cli.commands["memory"], paths=(path,), return_db=True) |
| 319 | + |
| 320 | + assert db.table_names() == ["dogs"] |
0 commit comments