Skip to content

Commit

Permalink
Sms/pytest marking cityscapes and zip (cvat-ai#298)
Browse files Browse the repository at this point in the history
* Updated pytest marking for cityscapes and imagezip.
  • Loading branch information
sstrehlk authored Jun 18, 2021
1 parent 11484ed commit e8e305b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ cover/
docs/_build/

#Pycharm config files
.idea/
.idea/
user_config.py
8 changes: 4 additions & 4 deletions tests/cli/test_image_zip_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from datumaro.components.dataset import Dataset, DatasetItem
from datumaro.util.test_utils import TestDir, compare_datasets

from ..requirements import Requirements
from ..requirements import Requirements, mark_requirement


def run(test, *args, expected_code=0):
Expand All @@ -24,7 +24,7 @@ def make_zip_archive(src_path, dst_path):
archive.write(path, osp.relpath(path, src_path))

class ImageZipIntegrationScenarios(TestCase):
@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_save_and_load(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='1', image=np.ones((5, 5, 3))),
Expand All @@ -48,7 +48,7 @@ def test_can_save_and_load(self):
parsed_dataset = Dataset.import_from(export_path, format='image_zip')
compare_datasets(self, source_dataset, parsed_dataset)

@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_export_zip_images_from_coco_dataset(self):
with TestDir() as test_dir:
coco_dir = osp.join(__file__[:__file__.rfind(osp.join('tests', ''))],
Expand All @@ -67,7 +67,7 @@ def test_can_export_zip_images_from_coco_dataset(self):
images = {f.filename for f in zf.filelist}
self.assertTrue(images == {'a.jpg', 'b.jpg'})

@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_change_extension_for_images_in_zip(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='1', image=np.ones((5, 5, 3))),
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cityscapes_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
from datumaro.util.image import Image
from datumaro.util.test_utils import (TestDir, compare_datasets,
test_save_and_load)
from .requirements import Requirements, mark_requirement

DUMMY_DATASET_DIR = osp.join(osp.dirname(__file__), 'assets',
'cityscapes_dataset')

class CityscapesFormatTest(TestCase):
@mark_requirement(Requirements.DATUM_267)
def test_can_write_and_parse_labelmap(self):
src_label_map = Cityscapes.CityscapesLabelMap

Expand All @@ -30,6 +32,7 @@ def test_can_write_and_parse_labelmap(self):
self.assertEqual(src_label_map, dst_label_map)

class CityscapesImportTest(TestCase):
@mark_requirement(Requirements.DATUM_267)
def test_can_import(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='defaultcity/defaultcity_000001_000031',
Expand Down Expand Up @@ -82,6 +85,7 @@ def test_can_import(self):

compare_datasets(self, source_dataset, parsed_dataset)

@mark_requirement(Requirements.DATUM_267)
def test_can_detect_cityscapes(self):
self.assertTrue(CityscapesImporter.detect(DUMMY_DATASET_DIR))

Expand All @@ -100,6 +104,7 @@ def _test_save_and_load(self, source_dataset, converter, test_dir,
importer='cityscapes',
target_dataset=target_dataset, importer_args=importer_args, **kwargs)

@mark_requirement(Requirements.DATUM_267)
def test_can_save_cityscapes_segm(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
Expand All @@ -126,6 +131,7 @@ def __iter__(self):
partial(CityscapesConverter.convert, label_map='cityscapes',
save_images=True), test_dir)

@mark_requirement(Requirements.DATUM_267)
def test_can_save_cityscapes_segm_unpainted(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
Expand All @@ -146,6 +152,7 @@ def __iter__(self):
partial(CityscapesConverter.convert, label_map='cityscapes',
save_images=True, apply_colormap=False), test_dir)

@mark_requirement(Requirements.DATUM_267)
def test_can_save_cityscapes_dataset_with_no_subsets(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
Expand All @@ -172,6 +179,7 @@ def __iter__(self):
partial(CityscapesConverter.convert, label_map='cityscapes',
save_images=True), test_dir)

@mark_requirement(Requirements.DATUM_267)
def test_can_save_cityscapes_dataset_without_frame_and_sequence(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
Expand All @@ -189,6 +197,7 @@ def __iter__(self):
partial(CityscapesConverter.convert, label_map='cityscapes',
save_images=True), test_dir)

@mark_requirement(Requirements.DATUM_267)
def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
Expand All @@ -207,6 +216,7 @@ def __iter__(self):
partial(CityscapesConverter.convert, label_map='cityscapes',
save_images=True), test_dir)

@mark_requirement(Requirements.DATUM_267)
def test_can_save_cityscapes_dataset_with_strange_id(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
Expand All @@ -225,6 +235,7 @@ def __iter__(self):
partial(CityscapesConverter.convert, label_map='cityscapes',
save_images=True), test_dir)

@mark_requirement(Requirements.DATUM_267)
def test_can_save_with_no_masks(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
Expand All @@ -239,6 +250,7 @@ def __iter__(self):
partial(CityscapesConverter.convert, label_map='cityscapes',
save_images=True), test_dir)

@mark_requirement(Requirements.DATUM_267)
def test_dataset_with_source_labelmap_undefined(self):
class SrcExtractor(TestExtractorBase):
def __iter__(self):
Expand Down Expand Up @@ -281,6 +293,7 @@ def categories(self):
partial(CityscapesConverter.convert, label_map='source',
save_images=True), test_dir, target_dataset=DstExtractor())

@mark_requirement(Requirements.DATUM_267)
def test_dataset_with_source_labelmap_defined(self):
class SrcExtractor(TestExtractorBase):
def __iter__(self):
Expand Down Expand Up @@ -321,6 +334,7 @@ def categories(self):
partial(CityscapesConverter.convert, label_map='source',
save_images=True), test_dir, target_dataset=DstExtractor())

@mark_requirement(Requirements.DATUM_267)
def test_can_save_and_load_image_with_arbitrary_extension(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
Expand Down
18 changes: 9 additions & 9 deletions tests/test_image_zip_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from datumaro.util.image import Image, save_image
from datumaro.util.test_utils import TestDir, compare_datasets

from .requirements import Requirements
from .requirements import Requirements, mark_requirement


class ImageZipConverterTest(TestCase):
@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def _test_can_save_and_load(self, source_dataset, test_dir,
**kwargs):
archive_path = osp.join(test_dir, kwargs.get('name',
Expand All @@ -24,7 +24,7 @@ def _test_can_save_and_load(self, source_dataset, test_dir,

compare_datasets(self, source_dataset, parsed_dataset)

@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_save_and_load(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='1', image=np.ones((10, 6, 3))),
Expand All @@ -34,7 +34,7 @@ def test_can_save_and_load(self):
with TestDir() as test_dir:
self._test_can_save_and_load(source_dataset, test_dir)

@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_save_and_load_with_custom_archive_name(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='img_1', image=np.ones((10, 10, 3))),
Expand All @@ -44,7 +44,7 @@ def test_can_save_and_load_with_custom_archive_name(self):
self._test_can_save_and_load(source_dataset, test_dir,
name='my_archive.zip')

@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_relative_paths(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='1', image=np.ones((10, 10, 3))),
Expand All @@ -55,7 +55,7 @@ def test_relative_paths(self):
with TestDir() as test_dir:
self._test_can_save_and_load(source_dataset, test_dir)

@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_save_and_load_custom_compresion_method(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='1', image=np.ones((5, 5, 3))),
Expand All @@ -66,7 +66,7 @@ def test_can_save_and_load_custom_compresion_method(self):
self._test_can_save_and_load(source_dataset, test_dir,
compression='ZIP_DEFLATED')

@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_save_and_load_with_arbitrary_extensions(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='subset/1',
Expand All @@ -87,7 +87,7 @@ def test_can_save_and_load_with_arbitrary_extensions(self):
DUMMY_DATASET_DIR = osp.join(osp.dirname(__file__), 'assets', 'image_zip_dataset')

class ImageZipImporterTest(TestCase):
@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_import(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='1', image=np.ones((10, 10, 3)))
Expand All @@ -98,7 +98,7 @@ def test_can_import(self):
compare_datasets(self, source_dataset, parsed_dataset)


@pytest.mark.reqids(Requirements.DATUM_267)
@mark_requirement(Requirements.DATUM_267)
def test_can_import_from_directory(self):
source_dataset = Dataset.from_iterable([
DatasetItem(id='1', image=np.ones((10, 10, 3))),
Expand Down

0 comments on commit e8e305b

Please sign in to comment.