Skip to content

Commit

Permalink
Add tests for dataset, and output pageMXL
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanklut committed Jan 10, 2024
1 parent 2e7211d commit 51d2660
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ jobs:
if: always()
run: |
python tests/test_input_utils.py
- name: Test dataset
if: always()
run: |
python tests/test_dataset.py
- name: Test output pageMXL
if: always()
run: |
python tests/test_output_pageMXL.py
72 changes: 72 additions & 0 deletions test/test_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import sys
import unittest
from pathlib import Path
from unittest.mock import mock_open, patch

sys.path.append(str(Path(__file__).resolve().parent.joinpath("..")))
from datasets.dataset import create_data


class TestCreateData(unittest.TestCase):
@patch("json.load")
@patch.object(Path, "open", new_callable=mock_open, read_data="test")
def test_create_data(self, mock_path_open, mock_json):
mock_json.return_value = {"annotations": "test", "segments_info": "test"}
input_data = {
"image_paths": Path("image.jpg"),
"original_image_paths": Path("original_image.jpg"),
"sem_seg_paths": Path("sem_seg.jpg"),
"instances_paths": Path("instances.json"),
"pano_paths": Path("pano.jpg"),
"segments_info_paths": Path("segments_info.json"),
}
expected_output = {
"file_name": "image.jpg",
"original_file_name": "original_image.jpg",
"image_id": "image",
"sem_seg_file_name": "sem_seg.jpg",
"annotations": "test",
"pan_seg_file_name": "pano.jpg",
"segments_info": "test",
}
with patch("pathlib.Path.is_file", return_value=True):
self.assertEqual(create_data(input_data), expected_output)

def test_create_data_missing_image(self):
input_data = {
"original_image_paths": Path("original_image.jpg"),
"sem_seg_paths": Path("sem_seg.jpg"),
"instances_paths": Path("instances.json"),
"pano_paths": Path("pano.jpg"),
"segments_info_paths": Path("segments_info.json"),
}
with self.assertRaises(ValueError):
create_data(input_data)

def test_create_data_missing_original_image(self):
input_data = {
"image_paths": Path("image.jpg"),
"sem_seg_paths": Path("sem_seg.jpg"),
"instances_paths": Path("instances.json"),
"pano_paths": Path("pano.jpg"),
"segments_info_paths": Path("segments_info.json"),
}
with self.assertRaises(ValueError):
create_data(input_data)

def test_create_data_file_not_found(self):
input_data = {
"image_paths": Path("image.jpg"),
"original_image_paths": Path("original_image.jpg"),
"sem_seg_paths": Path("sem_seg.jpg"),
"instances_paths": Path("instances.json"),
"pano_paths": Path("pano.jpg"),
"segments_info_paths": Path("segments_info.json"),
}
with patch("pathlib.Path.is_file", return_value=False):
with self.assertRaises(FileNotFoundError):
create_data(input_data)


if __name__ == "__main__":
unittest.main()

0 comments on commit 51d2660

Please sign in to comment.