diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/__init__.py | 0 | ||||
-rw-r--r-- | tests/unit/base/error_test.py | 48 | ||||
-rw-r--r-- | tests/unit/cli/__init__.py | 0 | ||||
-rw-r--r-- | tests/unit/cli/cmd_metric_test.py (renamed from tests/unit/cli/test_metric.py) | 0 | ||||
-rw-r--r-- | tests/unit/cli/cmd_plan_test.py (renamed from tests/unit/cli/test_plan.py) | 0 | ||||
-rw-r--r-- | tests/unit/cli/cmd_qpi_test.py (renamed from tests/unit/cli/test_qpi.py) | 0 | ||||
-rw-r--r-- | tests/unit/cli/options_test.py (renamed from tests/unit/cli/test_options.py) | 0 | ||||
-rw-r--r-- | tests/unit/collector/grep_test.py | 4 | ||||
-rw-r--r-- | tests/unit/collector/transformer/__init__.py | 0 | ||||
-rw-r--r-- | tests/unit/loader/__init__.py | 0 | ||||
-rw-r--r-- | tests/unit/loader/metric_test.py | 6 | ||||
-rw-r--r-- | tests/unit/loader/plan_test.py | 5 | ||||
-rw-r--r-- | tests/unit/loader/qpi_test.py | 5 | ||||
-rw-r--r-- | tests/unit/loader/yaml_file_test.py | 4 | ||||
-rw-r--r-- | tests/unit/runner/__init__.py | 0 | ||||
-rw-r--r-- | tests/unit/util/dev_test.py | 32 |
16 files changed, 91 insertions, 13 deletions
diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/tests/unit/__init__.py +++ /dev/null diff --git a/tests/unit/base/error_test.py b/tests/unit/base/error_test.py new file mode 100644 index 00000000..2be6d695 --- /dev/null +++ b/tests/unit/base/error_test.py @@ -0,0 +1,48 @@ +############################################################### +# Copyright (c) 2017 ZTE Corporation +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import pytest + +from qtip.base.error import InvalidContentError +from qtip.base.error import NotFoundError +from qtip.base.error import ToBeDoneError + + +def test_invalid_content(faker): + filename = faker.file_name() + error = InvalidContentError(filename) + assert error.filename == filename + + +def test_not_found(faker): + package = faker.pystr() + module = faker.pystr() + error = NotFoundError(module) + assert error.needle == module + assert error.heystack == 'qtip' + + error = NotFoundError(module, package) + assert error.needle == module + assert error.heystack == package + + +@pytest.fixture +def method(faker): + return faker.pystr() + + +@pytest.fixture +def module(faker): + return faker.pystr() + + +def test_to_be_done(method, module): + error = ToBeDoneError(method, module) + assert error.method == method + assert error.module == module diff --git a/tests/unit/cli/__init__.py b/tests/unit/cli/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/tests/unit/cli/__init__.py +++ /dev/null diff --git a/tests/unit/cli/test_metric.py b/tests/unit/cli/cmd_metric_test.py index 239da96e..239da96e 100644 --- a/tests/unit/cli/test_metric.py +++ b/tests/unit/cli/cmd_metric_test.py diff --git a/tests/unit/cli/test_plan.py b/tests/unit/cli/cmd_plan_test.py index 3ce3766e..3ce3766e 100644 --- a/tests/unit/cli/test_plan.py +++ b/tests/unit/cli/cmd_plan_test.py diff --git a/tests/unit/cli/test_qpi.py b/tests/unit/cli/cmd_qpi_test.py index 992c85d7..992c85d7 100644 --- a/tests/unit/cli/test_qpi.py +++ b/tests/unit/cli/cmd_qpi_test.py diff --git a/tests/unit/cli/test_options.py b/tests/unit/cli/options_test.py index f9472814..f9472814 100644 --- a/tests/unit/cli/test_options.py +++ b/tests/unit/cli/options_test.py diff --git a/tests/unit/collector/grep_test.py b/tests/unit/collector/grep_test.py index e5d5f8c6..2d4079af 100644 --- a/tests/unit/collector/grep_test.py +++ b/tests/unit/collector/grep_test.py @@ -21,7 +21,9 @@ def logfile(data_root): @pytest.mark.parametrize("regex,expected", [ ('not exist', []), ('Lorem (\S+)', [{'groups': ('ipsum',), 'groupdict': {}}]), - ('nisi ut (?P<name>\S+)', [{'groups': ('aliquip',), 'groupdict': {'name': 'aliquip'}}]) + ('nisi ut (?P<name>\S+)', [{'groups': ('aliquip',), 'groupdict': {'name': 'aliquip'}}]), + ('Lorem\s(\w+)\s.+\nconsectetur\s(\w+)\s.+\n', + [{'groups': ('ipsum', 'adipiscing',), 'groupdict': {}}]) ]) def test_grep_in_file(logfile, regex, expected): matches = grep_in_file(logfile, regex) diff --git a/tests/unit/collector/transformer/__init__.py b/tests/unit/collector/transformer/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/tests/unit/collector/transformer/__init__.py +++ /dev/null diff --git a/tests/unit/loader/__init__.py b/tests/unit/loader/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/tests/unit/loader/__init__.py +++ /dev/null diff --git a/tests/unit/loader/metric_test.py b/tests/unit/loader/metric_test.py index 26f144af..619d5e00 100644 --- a/tests/unit/loader/metric_test.py +++ b/tests/unit/loader/metric_test.py @@ -28,11 +28,10 @@ def init_test(metric_spec): def list_all_test(benchmarks_root): - metric_list = MetricSpec.list_all(paths=[benchmarks_root]) - assert len(list(metric_list)) is 6 + metric_list = list(MetricSpec.list_all(paths=[benchmarks_root])) + assert len(metric_list) is 6 for desc in metric_list: assert BaseProp.NAME in desc - assert BaseProp.DESCRIPTION in desc assert BaseProp.ABSPATH in desc assert BaseProp.ABSPATH is not None @@ -40,6 +39,5 @@ def list_all_test(benchmarks_root): def content_test(metric_spec): content = metric_spec.content assert BaseProp.NAME in content - assert BaseProp.DESCRIPTION in content assert BaseProp.WORKLOADS in content assert isinstance(content[BaseProp.WORKLOADS], list) diff --git a/tests/unit/loader/plan_test.py b/tests/unit/loader/plan_test.py index 4872b4cd..70ae2ad5 100644 --- a/tests/unit/loader/plan_test.py +++ b/tests/unit/loader/plan_test.py @@ -29,11 +29,10 @@ def test_init(plan): def test_list_all(benchmarks_root): - plan_list = Plan.list_all(paths=[benchmarks_root]) - assert len(list(plan_list)) is 1 + plan_list = list(Plan.list_all(paths=[benchmarks_root])) + assert len(plan_list) is 2 for desc in plan_list: assert PlanProp.NAME in desc - assert PlanProp.CONTENT in desc assert PlanProp.ABSPATH in desc assert PlanProp.ABSPATH is not None diff --git a/tests/unit/loader/qpi_test.py b/tests/unit/loader/qpi_test.py index 3328b43a..b53030d4 100644 --- a/tests/unit/loader/qpi_test.py +++ b/tests/unit/loader/qpi_test.py @@ -30,11 +30,10 @@ def test_init(qpi_spec): def test_list_all(benchmarks_root): - qpi_spec_list = QPISpec.list_all(paths=[benchmarks_root]) - assert len(list(qpi_spec_list)) is 2 + qpi_spec_list = list(QPISpec.list_all(paths=[benchmarks_root])) + assert len(qpi_spec_list) is 2 for item in qpi_spec_list: assert SpecProp.NAME in item - assert SpecProp.CONTENT in item assert SpecProp.ABSPATH in item assert SpecProp.ABSPATH is not None diff --git a/tests/unit/loader/yaml_file_test.py b/tests/unit/loader/yaml_file_test.py index 17836946..0f0632c4 100644 --- a/tests/unit/loader/yaml_file_test.py +++ b/tests/unit/loader/yaml_file_test.py @@ -10,7 +10,7 @@ import os import pytest -from qtip.base.error import InvalidContent +from qtip.base.error import InvalidContentError from qtip.loader.yaml_file import YamlFileLoader @@ -28,6 +28,6 @@ def test_init(yaml_root, filename, expected): def test_invalid_content(yaml_root): - with pytest.raises(InvalidContent) as excinfo: + with pytest.raises(InvalidContentError) as excinfo: YamlFileLoader('invalid.yaml', [yaml_root]) assert 'invalid.yaml' in excinfo.value.filename diff --git a/tests/unit/runner/__init__.py b/tests/unit/runner/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/tests/unit/runner/__init__.py +++ /dev/null diff --git a/tests/unit/util/dev_test.py b/tests/unit/util/dev_test.py new file mode 100644 index 00000000..021b1004 --- /dev/null +++ b/tests/unit/util/dev_test.py @@ -0,0 +1,32 @@ +############################################################### +# Copyright (c) 2017 ZTE Corporation +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import pytest + +from qtip.base.error import ToBeDoneError +from qtip.util.dev import create_to_be_done + + +def test_create_to_be_done(faker): + method = faker.pystr() + module = faker.pystr() + + tbd = create_to_be_done(method) + assert callable(tbd) + with pytest.raises(ToBeDoneError) as excinfo: + tbd() + assert excinfo.value.method == method + assert excinfo.value.module == 'qtip' + + tbd = create_to_be_done(method, module) + assert callable(tbd) + with pytest.raises(ToBeDoneError) as excinfo: + tbd() + assert excinfo.value.method == method + assert excinfo.value.module == module |