Skip to content

Commit

Permalink
misc: optimize by avoiding repetitive code
Browse files Browse the repository at this point in the history
Added a list of testcases to iterate over and to avoid repetition.
Also removed unnecessary print statement.
This also improves readability.

Signed-off-by: Shwetha K Acharya <[email protected]>
  • Loading branch information
Shwetha-Acharya committed Jan 18, 2024
1 parent 6c0a4ee commit 5742b8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 4 additions & 3 deletions testcases/misc/test_dbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ def _check_dbm_consistency(base: Path, nrecs: int) -> None:
def _run_dbm_consistency_checks(base_path: Path) -> None:
base_path.mkdir(parents=True, exist_ok=True)
try:
_check_dbm_consistency(base_path, 10)
_check_dbm_consistency(base_path, 100)
_check_dbm_consistency(base_path, 10000)
test_sizes = [10, 100, 10000]

for size in test_sizes:
_check_dbm_consistency(base_path, size)
finally:
shutil.rmtree(base_path, ignore_errors=True)

Expand Down
20 changes: 11 additions & 9 deletions testcases/misc/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,19 @@ def _run_checks(dsets: typing.List[DataPath]) -> None:
def _check_io_consistency(test_dir: Path) -> None:
base = None
try:
print("\n")
base = test_dir / "test_io_consistency"
base.mkdir(parents=True)
# Case-1: single 4K file
_run_checks(_make_datasets(base, 4096, 1))
# Case-2: single 16M file
_run_checks(_make_datasets(base, 2**24, 1))
# Case-3: few 1M files
_run_checks(_make_datasets(base, 2**20, 10))
# Case-4: many 1K files
_run_checks(_make_datasets(base, 1024, 100))

test_cases = [
(4096, 1), # Case-1: single 4K file
(2**24, 1), # Case-2: single 16M file
(2**20, 10), # Case-3: few 1M files
(1024, 100), # Case-4: many 1K files
]

for size, count in test_cases:
datasets = _make_datasets(base, size, count)
_run_checks(datasets)
except Exception as ex:
print("Error while executing test_io_consistency: %s", ex)
raise
Expand Down

0 comments on commit 5742b8a

Please sign in to comment.