Skip to content

Commit 216f1ed

Browse files
committed
Unit tests for _get_only_item_in_dir()
Signed-off-by: Bram Stoeller <bram.stoeller@alliander.com>
1 parent a0930d3 commit 216f1ed

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

tests/unit/utils/test_zip.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010
import structlog.testing
1111

12-
from power_grid_model_io.utils.zip import extract
12+
from power_grid_model_io.utils.zip import _get_only_item_in_dir, extract
1313

1414
from ...utils import MockTqdm, assert_log_exists
1515

@@ -123,3 +123,36 @@ def test_extract__return_subdir_path(mock_tqdm: MagicMock, temp_dir: Path):
123123
# Assert
124124
assert extract_dir_path == temp_dir / "foo" / "foo"
125125
assert (temp_dir / "foo" / "foo" / "foo.txt").is_file()
126+
127+
128+
def test_get_only_item_in_dir__no_items(temp_dir):
129+
# Act / Assert
130+
assert _get_only_item_in_dir(temp_dir) == None
131+
132+
133+
def test_get_only_item_in_dir__one_file(temp_dir):
134+
# Arrange
135+
with open(temp_dir / "file.txt", "wb"):
136+
pass
137+
138+
# Act / Assert
139+
assert _get_only_item_in_dir(temp_dir) == temp_dir / "file.txt"
140+
141+
142+
def test_get_only_item_in_dir__one_dir(temp_dir):
143+
# Arrange
144+
(temp_dir / "subdir").mkdir()
145+
146+
# Act / Assert
147+
assert _get_only_item_in_dir(temp_dir) == temp_dir / "subdir"
148+
149+
150+
def test_get_only_item_in_dir__two_files(temp_dir):
151+
# Arrange
152+
with open(temp_dir / "file_1.txt", "wb"):
153+
pass
154+
with open(temp_dir / "file_2.txt", "wb"):
155+
pass
156+
157+
# Act / Assert
158+
assert _get_only_item_in_dir(temp_dir) == None

0 commit comments

Comments
 (0)