Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Landy committed Nov 17, 2024
1 parent 9a17b18 commit 09e95f2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
46 changes: 32 additions & 14 deletions tests/test_module_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,66 @@

ROOT_PATH = Path(twv.__file__).parent.parent
TWV = 'traceback_with_variables'
OS = 'os'
ALIAS = 'alias'


def test_module_name_to_path():
assert module_name_to_path('os') == Path(os.__file__)
assert module_name_to_path(OS) == Path(os.__file__)
assert module_name_to_path(TWV) == ROOT_PATH / TWV
with pytest.raises(NoModuleError):
module_name_to_path('nonexistant_module')


def test_create_and_rm_alias():
# problems before we have the alias

with pytest.raises(ValueError) as e:
create_alias('', TWV)
assert str(e.value) == 'the alias must be non-empty'

with pytest.raises(ValueError) as e:
create_alias('bad name', TWV)
assert str(e.value) == 'the alias must have only ascii lowecases, digits and underscores'

with pytest.raises(NoModuleError):
create_alias('alias1', 'nonexistant_module')
create_alias(ALIAS, 'nonexistant_module')

with pytest.raises(ValueError) as e:
create_alias('os', TWV)
assert str(e.value) == 'a module with the alias name already exists'
create_alias(OS, TWV)
assert str(e.value) == 'a module with the alias name already exists'

with pytest.raises(NoModuleError):
rm_alias('alias1')
rm_alias(ALIAS)

with pytest.raises(ValueError) as e:
rm_alias(TWV)

assert str(e.value) == 'the module is not an alias'

create_alias('alias1', TWV)
create_alias(ALIAS, TWV)

# problems once we have the alias

with pytest.raises(ValueError) as e:
create_alias('alias1', TWV)
create_alias(ALIAS, TWV)
assert str(e.value) == 'a module with the alias name already exists'

with pytest.raises(ValueError) as e:
create_alias('alias1', 'os')
create_alias(ALIAS, OS)
assert str(e.value) == 'a module with the alias name already exists'

rm_alias('alias1')
rm_alias(ALIAS)

# problems after we rm the alias

with pytest.raises(NoModuleError):
rm_alias('alias1')
rm_alias(ALIAS)

# rare case of garbage in the lib dir

os.symlink(str(ROOT_PATH / 'nonexistant'), str(ROOT_PATH / 'alias1'))
os.symlink(str(ROOT_PATH / 'nonexistant'), str(ROOT_PATH / ALIAS))
with pytest.raises(ValueError) as e:
create_alias('alias1', 'os')
create_alias(ALIAS, TWV)
assert str(e.value) == 'the needed file system location already occupied'
os.remove(str(ROOT_PATH / 'alias1'))

os.remove(str(ROOT_PATH / ALIAS))
4 changes: 4 additions & 0 deletions tests/test_tb_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
def test_create_and_rm_tb_alias(tmp_path, tb_reg):
tb_reg(run_code(tmp_path, [], ['import tb.a', dummies_code, 'f()'], [], True), 'run 1 without tb')

import traceback_with_variables as T # noqa
create_tb_alias()
p1 = T.__file__ # noqa
from pathlib import Path # noqa
ds = list(Path(T.__file__).parent.parent.glob('*')) # noqa
tb_reg(run_code(tmp_path, [], ['import tb.a', dummies_code, 'f()'], [], True), 'run with tb')

rm_tb_alias()
Expand Down

0 comments on commit 09e95f2

Please sign in to comment.