Skip to content

Commit

Permalink
Unit test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-nn committed Nov 4, 2024
1 parent 00cfeae commit ae19699
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
test:
name: Unit Tests
strategy:
fail-fast: false
matrix:
python: [3.8, 3.12]
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion degirum_tools/clip_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ def custom_serializer(obj):
# save the clip in a separate thread
threading.Thread(target=save, args=(context,), name=self._thread_name).start()

def join_all_saver_threads(self):
def join_all_saver_threads(self) -> int:
"""
Join all threads started by this instance
"""
nthreads = 0
for thread in threading.enumerate():
if thread.name == self._thread_name:
thread.join()
nthreads += 1
return nthreads
9 changes: 0 additions & 9 deletions degirum_tools/video_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,8 @@ def release(self):
if self._writer is None:
return

if self._use_ffmpeg:
print("video writer: ", self._writer.process)

self._writer.release()

if self._use_ffmpeg:
import psutil

for p in psutil.process_iter(["name"]):
print(p)

def __enter__(self):
pass

Expand Down
8 changes: 5 additions & 3 deletions test/test_clip_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ def apply_analyzer(analyzer, results):

def verify_results(case, clip_saver, triggers, results):
case_name = f"Case '{case.name}'"
clip_saver.join_all_saver_threads()
nthreads = clip_saver.join_all_saver_threads()
assert nthreads == len(triggers)
dir_path = clip_saver._dir_path
assert os.path.exists(
clip_saver._dir_path
), f"{case_name}: directory {clip_saver._dir_path} does not exist."

file_count = len(os.listdir(dir_path))
files = os.listdir(dir_path)
file_count = len(files)
expected_file_count = len(triggers) * (
2 if clip_saver._save_ai_result_json else 1
)
assert (
file_count == expected_file_count
), f"{case_name}: expected {expected_file_count} files, but found {file_count}."
), f"{case_name}: expected {expected_file_count} files, but found {file_count}\n({files})."

for t in triggers:
start = t - clip_saver._pre_trigger_delay
Expand Down

0 comments on commit ae19699

Please sign in to comment.