Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
TLCFEM committed Mar 16, 2024
1 parent d43ada4 commit 5653783
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/msglc/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ def read(self, path: str | list | slice | None = None):

target = self._obj
for key in path_stack:
if "" == key:
continue
if isinstance(key, str) and isinstance(target, (list, LazyList)):
key = to_index(key, len(target))
target = target[key]
Expand All @@ -462,7 +464,7 @@ def visit(self, path: str = ""):
"""
target = self._obj
for key in path.split("/"):
if not key:
if "" == key:
continue
if isinstance(target, (list, LazyList)):
key = to_index(key, len(target))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_msglc.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_combine_archives(tmpdir, json_after, target):
target.seek(0)

with LazyReader(target) as reader:
assert reader.read("first_outer/second_inner/glossary/title") == "example glossary"
assert reader.read("first_outer//second_inner/glossary/title") == "example glossary"
assert reader.read("second_outer/first_inner/2") == 2
assert reader.read("second_outer/first_inner/-1") == 29
assert reader.read("second_outer/first_inner/0:2") == [0, 1]
Expand All @@ -178,7 +178,7 @@ def test_combine_archives(tmpdir, json_after, target):
assert reader.read("second_outer/first_inner/24:2:30") == [24, 26, 28]
assert reader.read("second_outer/first_inner/:2:5") == [0, 2, 4]
assert reader.read("second_outer/first_inner/24:2:") == [24, 26, 28]
assert reader.visit("first_outer/second_inner/glossary/title") == "example glossary"
assert reader.visit("first_outer//second_inner/glossary/title") == "example glossary"
assert reader.visit("second_outer/first_inner/2") == 2
assert reader.visit("second_outer/first_inner/-1") == 29
assert reader.visit("second_outer/first_inner/0:2") == [0, 1]
Expand Down

0 comments on commit 5653783

Please sign in to comment.