Skip to content

Commit

Permalink
Merge pull request #363 from Carreau/fix-import-db
Browse files Browse the repository at this point in the history
Fix ImportDB.get_default(None)
  • Loading branch information
Carreau authored Oct 21, 2024
2 parents 2ecdcc5 + f9186fc commit 4c8e092
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/python/pyflyby/_importdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def get_default(cls, target_filename: Union[Filename, str], /):
target_path = Path(target_filename).resolve()

parents: List[Path]
if not target_path.is_dir():
if target_path.is_dir():
parents = [target_path]
else:
parents = []
Expand Down
24 changes: 24 additions & 0 deletions tests/test_importdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import os
import sys
from shutil import rmtree
from tempfile import NamedTemporaryFile, mkdtemp
from textwrap import dedent
Expand All @@ -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'])
Expand Down

0 comments on commit 4c8e092

Please sign in to comment.