From 6e7f19d9f6fb08e78d5ba22f41a353986b4ac0a1 Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Mon, 21 Oct 2024 14:23:25 +0200 Subject: [PATCH] test for 362 --- tests/test_importdb.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_importdb.py b/tests/test_importdb.py index 80bdb8a4..438f6ac4 100644 --- a/tests/test_importdb.py +++ b/tests/test_importdb.py @@ -6,6 +6,7 @@ import os +import sys from shutil import rmtree from tempfile import NamedTemporaryFile, mkdtemp from textwrap import dedent @@ -15,8 +16,31 @@ from pyflyby._importstmt import Import from pyflyby._util import EnvVarCtx +from contextlib import contextmanager +if sys.version_info > (3, 11): + from contextlib import chdir + +else: + + @contextmanager + def chdir(path): + old = os.getcwd() + try: + os.chdir(path) + yield + finally: + os.chdir(old) + + +def test_importDB_root(): + """ + See #362 + """ + with chdir("/"): + ImportDB.get_default(None) + def test_ImportDB_from_code_1(): db = ImportDB('from aa.bb import cc as dd, ee') expected_known = ImportSet(['from aa.bb import cc as dd, ee'])