Skip to content

Commit

Permalink
Refactor test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Songki Choi <songki.choi@intel.com>
  • Loading branch information
goodsong81 committed Jul 17, 2023
1 parent 2a400b3 commit b1afc61
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 184 deletions.
29 changes: 6 additions & 23 deletions tests/integration/cli/anomaly/test_anomaly_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest

from otx.api.entities.model_template import parse_model_template, ModelCategory, ModelStatus
from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -18,6 +18,7 @@
otx_eval_testing,
otx_export_testing,
otx_train_testing,
BaseTestModelTemplates,
)

args = {
Expand All @@ -34,36 +35,18 @@
templates_ids = [template.model_template_id for template in templates]


class TestAnomalyClassificationModelTemplates:
class TestAnomalyClassificationModelTemplates(BaseTestModelTemplates):
@e2e_pytest_component
def test_model_category(self):
stat = {
ModelCategory.SPEED: 0,
ModelCategory.BALANCE: 0,
ModelCategory.ACCURACY: 0,
ModelCategory.OTHER: 0,
}
for template in templates:
stat[template.model_category] += 1
assert stat[ModelCategory.SPEED] == 1
assert stat[ModelCategory.BALANCE] <= 1
assert stat[ModelCategory.ACCURACY] == 1
self.check_model_category(templates)

@e2e_pytest_component
def test_model_status(self):
for template in templates:
if template.model_status == ModelStatus.DEPRECATED:
assert template.model_category == ModelCategory.OTHER
self.check_model_status(templates)

@e2e_pytest_component
def test_default_for_task(self):
num_default_model = 0
for template in templates:
if template.is_default_for_task:
num_default_model += 1
assert template.model_category != ModelCategory.OTHER
assert template.model_status == ModelStatus.ACTIVE
assert num_default_model == 1
self.check_default_for_task(templates)


class TestToolsAnomalyClassification:
Expand Down
29 changes: 6 additions & 23 deletions tests/integration/cli/anomaly/test_anomaly_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest

from otx.api.entities.model_template import parse_model_template, ModelCategory, ModelStatus
from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -18,6 +18,7 @@
otx_eval_testing,
otx_export_testing,
otx_train_testing,
BaseTestModelTemplates
)

args = {
Expand All @@ -34,36 +35,18 @@
templates_ids = [template.model_template_id for template in templates]


class TestAnomalyDetectionModelTemplates:
class TestAnomalyDetectionModelTemplates(BaseTestModelTemplates):
@e2e_pytest_component
def test_model_category(self):
stat = {
ModelCategory.SPEED: 0,
ModelCategory.BALANCE: 0,
ModelCategory.ACCURACY: 0,
ModelCategory.OTHER: 0,
}
for template in templates:
stat[template.model_category] += 1
assert stat[ModelCategory.SPEED] == 1
assert stat[ModelCategory.BALANCE] <= 1
assert stat[ModelCategory.ACCURACY] == 1
self.check_model_category(templates)

@e2e_pytest_component
def test_model_status(self):
for template in templates:
if template.model_status == ModelStatus.DEPRECATED:
assert template.model_category == ModelCategory.OTHER
self.check_model_status(templates)

@e2e_pytest_component
def test_default_for_task(self):
num_default_model = 0
for template in templates:
if template.is_default_for_task:
num_default_model += 1
assert template.model_category != ModelCategory.OTHER
assert template.model_status == ModelStatus.ACTIVE
assert num_default_model == 1
self.check_default_for_task(templates)


class TestToolsAnomalyDetection:
Expand Down
29 changes: 6 additions & 23 deletions tests/integration/cli/anomaly/test_anomaly_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest

from otx.api.entities.model_template import parse_model_template, ModelCategory, ModelStatus
from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -18,6 +18,7 @@
otx_eval_testing,
otx_export_testing,
otx_train_testing,
BaseTestModelTemplates,
)

args = {
Expand All @@ -34,36 +35,18 @@
templates_ids = [template.model_template_id for template in templates]


class TestAnomalySegmentationModelTemplates:
class TestAnomalySegmentationModelTemplates(BaseTestModelTemplates):
@e2e_pytest_component
def test_model_category(self):
stat = {
ModelCategory.SPEED: 0,
ModelCategory.BALANCE: 0,
ModelCategory.ACCURACY: 0,
ModelCategory.OTHER: 0,
}
for template in templates:
stat[template.model_category] += 1
assert stat[ModelCategory.SPEED] == 1
assert stat[ModelCategory.BALANCE] <= 1
assert stat[ModelCategory.ACCURACY] == 1
self.check_model_category(templates)

@e2e_pytest_component
def test_model_status(self):
for template in templates:
if template.model_status == ModelStatus.DEPRECATED:
assert template.model_category == ModelCategory.OTHER
self.check_model_status(templates)

@e2e_pytest_component
def test_default_for_task(self):
num_default_model = 0
for template in templates:
if template.is_default_for_task:
num_default_model += 1
assert template.model_category != ModelCategory.OTHER
assert template.model_status == ModelStatus.ACTIVE
assert num_default_model == 1
self.check_default_for_task(templates)


class TestToolsAnomalySegmentation:
Expand Down
29 changes: 6 additions & 23 deletions tests/integration/cli/classification/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest
import torch

from otx.api.entities.model_template import parse_model_template, ModelCategory, ModelStatus
from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -30,6 +30,7 @@
otx_hpo_testing,
otx_resume_testing,
otx_train_testing,
BaseTestModelTemplates,
)

# Pre-train w/ 'label_0', 'label_1', 'label_2' classes
Expand Down Expand Up @@ -82,36 +83,18 @@
templates_ids = [template.model_template_id for template in templates]


class TestClassificationModelTemplates:
class TestClassificationModelTemplates(BaseTestModelTemplates):
@e2e_pytest_component
def test_model_category(self):
stat = {
ModelCategory.SPEED: 0,
ModelCategory.BALANCE: 0,
ModelCategory.ACCURACY: 0,
ModelCategory.OTHER: 0,
}
for template in templates:
stat[template.model_category] += 1
assert stat[ModelCategory.SPEED] == 1
assert stat[ModelCategory.BALANCE] <= 1
assert stat[ModelCategory.ACCURACY] == 1
self.check_model_category(templates)

@e2e_pytest_component
def test_model_status(self):
for template in templates:
if template.model_status == ModelStatus.DEPRECATED:
assert template.model_category == ModelCategory.OTHER
self.check_model_status(templates)

@e2e_pytest_component
def test_default_for_task(self):
num_default_model = 0
for template in templates:
if template.is_default_for_task:
num_default_model += 1
assert template.model_category != ModelCategory.OTHER
assert template.model_status == ModelStatus.ACTIVE
assert num_default_model == 1
self.check_default_for_task(templates)


class TestMultiClassClassificationCLI:
Expand Down
29 changes: 6 additions & 23 deletions tests/integration/cli/detection/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
import torch

from otx.api.entities.model_template import parse_model_template, ModelCategory, ModelStatus
from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -28,6 +28,7 @@
otx_hpo_testing,
otx_resume_testing,
otx_train_testing,
BaseTestModelTemplates,
)

args = {
Expand Down Expand Up @@ -81,36 +82,18 @@
templates_ids_w_experimental = templates_ids + experimental_template_ids


class TestDetectionModelTemplates:
class TestDetectionModelTemplates(BaseTestModelTemplates):
@e2e_pytest_component
def test_model_category(self):
stat = {
ModelCategory.SPEED: 0,
ModelCategory.BALANCE: 0,
ModelCategory.ACCURACY: 0,
ModelCategory.OTHER: 0,
}
for template in templates:
stat[template.model_category] += 1
assert stat[ModelCategory.SPEED] == 1
assert stat[ModelCategory.BALANCE] <= 1
assert stat[ModelCategory.ACCURACY] == 1
self.check_model_category(templates)

@e2e_pytest_component
def test_model_status(self):
for template in templates:
if template.model_status == ModelStatus.DEPRECATED:
assert template.model_category == ModelCategory.OTHER
self.check_model_status(templates)

@e2e_pytest_component
def test_default_for_task(self):
num_default_model = 0
for template in templates:
if template.is_default_for_task:
num_default_model += 1
assert template.model_category != ModelCategory.OTHER
assert template.model_status == ModelStatus.ACTIVE
assert num_default_model == 1
self.check_default_for_task(templates)


class TestDetectionCLI:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
import torch

from otx.api.entities.model_template import parse_model_template, ModelCategory, ModelStatus
from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -24,6 +24,7 @@
otx_hpo_testing,
otx_resume_testing,
otx_train_testing,
BaseTestModelTemplates,
)

args = {
Expand Down Expand Up @@ -67,36 +68,18 @@
templates_ids_inc_convnext.extend([template_experimental.model_template_id])


class TestInstanceSegmentationModelTemplates:
class TestInstanceSegmentationModelTemplates(BaseTestModelTemplates):
@e2e_pytest_component
def test_model_category(self):
stat = {
ModelCategory.SPEED: 0,
ModelCategory.BALANCE: 0,
ModelCategory.ACCURACY: 0,
ModelCategory.OTHER: 0,
}
for template in templates:
stat[template.model_category] += 1
assert stat[ModelCategory.SPEED] == 1
assert stat[ModelCategory.BALANCE] <= 1
assert stat[ModelCategory.ACCURACY] == 1
self.check_model_category(templates)

@e2e_pytest_component
def test_model_status(self):
for template in templates:
if template.model_status == ModelStatus.DEPRECATED:
assert template.model_category == ModelCategory.OTHER
self.check_model_status(templates)

@e2e_pytest_component
def test_default_for_task(self):
num_default_model = 0
for template in templates:
if template.is_default_for_task:
num_default_model += 1
assert template.model_category != ModelCategory.OTHER
assert template.model_status == ModelStatus.ACTIVE
assert num_default_model == 1
self.check_default_for_task(templates)


class TestInstanceSegmentationCLI:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import pytest
import torch

from otx.api.entities.model_template import parse_model_template, ModelCategory, ModelStatus
from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import BaseTestModelTemplates


otx_dir = os.getcwd()
Expand All @@ -21,33 +22,15 @@
templates_ids = [template.model_template_id for template in templates]


class TestRotatedDetectionModelTemplates:
class TestRotatedDetectionModelTemplates(BaseTestModelTemplates):
@e2e_pytest_component
def test_model_category(self):
stat = {
ModelCategory.SPEED: 0,
ModelCategory.BALANCE: 0,
ModelCategory.ACCURACY: 0,
ModelCategory.OTHER: 0,
}
for template in templates:
stat[template.model_category] += 1
assert stat[ModelCategory.SPEED] == 1
assert stat[ModelCategory.BALANCE] <= 1
assert stat[ModelCategory.ACCURACY] == 1
self.check_model_category(templates)

@e2e_pytest_component
def test_model_status(self):
for template in templates:
if template.model_status == ModelStatus.DEPRECATED:
assert template.model_category == ModelCategory.OTHER
self.check_model_status(templates)

@e2e_pytest_component
def test_default_for_task(self):
num_default_model = 0
for template in templates:
if template.is_default_for_task:
num_default_model += 1
assert template.model_category != ModelCategory.OTHER
assert template.model_status == ModelStatus.ACTIVE
assert num_default_model == 1
self.check_default_for_task(templates)
Loading

0 comments on commit b1afc61

Please sign in to comment.