Skip to content

Commit

Permalink
Fix/tests redesign (Blazemeter#1412)
Browse files Browse the repository at this point in the history
* reorganize files

* and fix imports

* unify test path constants

* ignore tests/build

* fix

* fix class specs

* fix tests

* fix cloud paths checker

* refactoring

* fix import order
  • Loading branch information
greyfenrir authored Oct 21, 2020
1 parent f98b68b commit 1725500
Show file tree
Hide file tree
Showing 69 changed files with 127 additions and 152 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
node_modules
.npm

/tests/build/
/examples/BOOTH1/converted/

bzt/resources/NUnitRunner/*
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ matrix:
- PYTHON=python3
- PIP_INSTALL="sudo pip3 install"
- RVM_KEY="409B6B1796C275462A1703113804BB82D39DC0E3"
- OSX_EXCLUDE="--exclude-test=tests.modules.selenium.test_csharp"
- OSX_EXCLUDE="--exclude-test=tests.unit.modules.selenium.test_csharp"

addons:
firefox: latest
Expand Down
2 changes: 1 addition & 1 deletion profiled-test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash -x
python -m cProfile -o /tmp/taurus.profile `which nosetests` --nologcapture tests.modules.test_external:TestExternalResultsLoader.test_errors_jtl2
python -m cProfile -o /tmp/taurus.profile `which nosetests` --nologcapture tests.unit.modules.test_external:TestExternalResultsLoader.test_errors_jtl2
python -m gprof2dot -f pstats /tmp/taurus.profile | dot -Tpng -o /tmp/profile.png
5 changes: 0 additions & 5 deletions tests/__init__.py

This file was deleted.

16 changes: 8 additions & 8 deletions tests/resources/apiritif/transactions.ldjson

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/resources/json/mock_end_err.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"provisioning": "mock1",
"modules": {
"mock1": {
"class": "tests.mocks.ModuleMock",
"shutdown": "tests.mocks.KeyboardInterrupt"
"class": "tests.unit.mocks.ModuleMock",
"shutdown": "tests.unit.mocks.KeyboardInterrupt"
}
}
}
8 changes: 4 additions & 4 deletions tests/resources/json/mock_normal.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
}
],
"modules": {
"mock1": {"class": "tests.mocks.ModuleMock"},
"mock2": "tests.mocks.ModuleMock",
"mock3": "tests.mocks.ModuleMock",
"mock4": "tests.mocks.ModuleMock"
"mock1": {"class": "tests.unit.mocks.ModuleMock"},
"mock2": "tests.unit.mocks.ModuleMock",
"mock3": "tests.unit.mocks.ModuleMock",
"mock4": "tests.unit.mocks.ModuleMock"
},
"test": [
1,
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/json/mock_postproc_err.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"provisioning": "mock1",
"modules": {
"mock1": {
"class": "tests.mocks.ModuleMock",
"class": "tests.unit.mocks.ModuleMock",
"postproc": "bzt.AutomatedShutdown"
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/resources/json/mock_prepare_err.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"provisioning": "mock1",
"modules": {
"mock1": {
"class": "tests.mocks.ModuleMock",
"prepare": "tests.mocks.KeyboardInterrupt"
"class": "tests.unit.mocks.ModuleMock",
"prepare": "tests.unit.mocks.KeyboardInterrupt"
}
}
}
4 changes: 2 additions & 2 deletions tests/resources/json/mock_start_err.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"provisioning": "mock1",
"modules": {
"mock1": {
"class": "tests.mocks.ModuleMock",
"startup": "tests.mocks.KeyboardInterrupt"
"class": "tests.unit.mocks.ModuleMock",
"startup": "tests.unit.mocks.KeyboardInterrupt"
}
}
}
4 changes: 2 additions & 2 deletions tests/resources/json/mock_wait_err.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"provisioning": "mock",
"modules": {
"mock": {
"class": "tests.mocks.ModuleMock",
"check": "tests.mocks.KeyboardInterrupt"
"class": "tests.unit.mocks.ModuleMock",
"check": "tests.unit.mocks.KeyboardInterrupt"
}
}
}
2 changes: 1 addition & 1 deletion tests/resources/json/reporting.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"modules": {
"mock": {
"class": "tests.mocks.ModuleMock",
"class": "tests.unit.mocks.ModuleMock",
"check_iterations": 30
},
"console": {
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/yaml/singletone-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ reporting:

modules:
singletone-mock:
class: tests.mocks.SingletoneServiceMock
class: tests.unit.mocks.SingletoneServiceMock
5 changes: 5 additions & 0 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
""" unit test """
from tests.unit.base import TEST_DIR, BUILD_DIR, RESOURCES_DIR, BASE_CONFIG, ROOT_LOGGER, BZT_DIR
from tests.unit.base import close_reader_file, local_paths_config
from tests.unit.mocks import random_datapoint, EngineEmul, BZMock
from tests.unit.cases import BZTestCase, ExecutorTestCase
22 changes: 10 additions & 12 deletions tests/base.py → tests/unit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
import os
import logging

from bzt.utils import temp_file
from bzt.cli import CLI
from bzt.utils import EXE_SUFFIX, run_once, temp_file, get_full_path

ROOT_LOGGER = logging.getLogger("")


def get_cwd():
def _get_dir():
filename = inspect.getouterframes(inspect.currentframe())[1][1]
return os.path.dirname(filename)
return get_full_path(filename, step_up=1)


# execute tests regardless of working directory
root_dir = get_cwd() + '/../'
os.chdir(root_dir)

RESOURCES_DIR = os.path.join(get_cwd(), 'resources') + os.path.sep
BUILD_DIR = get_cwd() + "/../build/tmp/"
TEST_DIR = get_cwd() + "/../build/test/"
BASE_CONFIG = get_cwd() + "/../bzt/resources/10-base-config.yml"
BZT_DIR = get_full_path(_get_dir(), step_up=2)
RESOURCES_DIR = os.path.join(BZT_DIR, 'tests', 'resources') + os.path.sep # we need this sep cos a lot of
BUILD_DIR = os.path.join(BZT_DIR, 'tests', 'build', 'tmp') + os.path.sep # wrong sting joining in tests
TEST_DIR = os.path.join(BZT_DIR, 'tests', 'build', 'test') + os.path.sep
BASE_CONFIG = os.path.join(BZT_DIR, 'bzt', 'resources', '10-base-config.yml')

from bzt.cli import CLI
from bzt.utils import EXE_SUFFIX, run_once
os.chdir(BZT_DIR)


@run_once
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions tests/cases.py → tests/unit/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from bzt.engine import ScenarioExecutor, EXEC
from bzt.engine import SelfDiagnosable
from bzt.utils import get_full_path
from tests import ROOT_LOGGER
from tests.mocks import EngineEmul
from tests.unit import ROOT_LOGGER, EngineEmul

TestCase.shortDescription = lambda self: None # suppress nose habit to show docstring instead of method name

Expand Down
2 changes: 1 addition & 1 deletion tests/mocks.py → tests/unit/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from bzt.modules.functional import FunctionalResultsReader, FunctionalAggregatorListener
from bzt.utils import b, load_class, to_json, get_full_path, get_uniq_name, FileReader, is_windows, temp_file

from tests.base import TEST_DIR, ROOT_LOGGER
from tests.unit.base import TEST_DIR, ROOT_LOGGER

try:
from exceptions import KeyboardInterrupt
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from . import MockJMeterExecutor
from bzt.engine import Provisioning
from bzt.jmx import JMX, LoadSettingsProcessor
from tests import BZTestCase, RESOURCES_DIR
from tests.mocks import EngineEmul
from tests.unit import BZTestCase, RESOURCES_DIR, EngineEmul


class TestLoadSettingsProcessor(BZTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from bzt.modules.jmeter import JTLReader, FuncJTLReader, JMeter
from bzt.modules.provisioning import Local
from bzt.utils import EXE_SUFFIX, get_full_path, BetterDict, is_windows, JavaVM, etree
from tests import RESOURCES_DIR, BUILD_DIR, close_reader_file, ExecutorTestCase
from tests.unit import RESOURCES_DIR, BUILD_DIR, close_reader_file, ExecutorTestCase
from . import MockJMeterExecutor, MockHTTPClient

_jvm = JavaVM()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from bzt.utils import EXE_SUFFIX

from . import MockJMeter
from tests import BZTestCase, RESOURCES_DIR
from tests.unit import BZTestCase, RESOURCES_DIR


class TestJMeterTool(BZTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from bzt.modules.aggregator import DataPoint, KPISet
from bzt.modules.jmeter import JTLErrorsReader, JTLReader, FuncJTLReader
from bzt.utils import to_json
from tests import BZTestCase, RESOURCES_DIR, close_reader_file, ROOT_LOGGER
from tests.mocks import EngineEmul
from tests.unit import BZTestCase, RESOURCES_DIR, close_reader_file, ROOT_LOGGER, EngineEmul


class TestFuncJTLReader(BZTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from bzt.jmx.http import HTTPProtocolHandler
from bzt.modules.jmeter import JMeterScenarioBuilder
from bzt.utils import etree, temp_file
from tests import BZTestCase, RESOURCES_DIR
from tests.mocks import EngineEmul
from tests.unit import BZTestCase, RESOURCES_DIR, EngineEmul
from . import MockJMeterExecutor


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tests import local_paths_config, ExecutorTestCase
from tests.unit import local_paths_config, ExecutorTestCase
from bzt.modules.selenium import SeleniumExecutor
from bzt.modules.services import VirtualDisplay

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from bzt.modules.aggregator import DataPoint, KPISet
from bzt.modules.apiritif import ApiritifNoseExecutor
from bzt.modules.apiritif.executor import ApiritifLoadReader, ApiritifFuncReader
from tests import RESOURCES_DIR, ExecutorTestCase
from tests.mocks import EngineEmul
from tests.unit import RESOURCES_DIR, ExecutorTestCase, EngineEmul


class TestApiritifScriptGeneration(ExecutorTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from bzt.modules.csharp import NUnitExecutor
from bzt.utils import is_windows
from tests import RESOURCES_DIR
from tests.modules.selenium import SeleniumTestCase
from tests.unit import RESOURCES_DIR
from tests.unit.modules.selenium import SeleniumTestCase


RUNNER_EXECUTABLE = "runner-mock" + (".bat" if is_windows() else ".sh")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
from bzt.modules.jmeter import JTLReader
from bzt.modules.selenium import SeleniumExecutor
from bzt.utils import ToolError
from tests import BZTestCase, local_paths_config, RESOURCES_DIR, BUILD_DIR, ExecutorTestCase
from tests.mocks import EngineEmul
from tests.modules.selenium import SeleniumTestCase
from tests.unit import BZTestCase, local_paths_config, RESOURCES_DIR, BUILD_DIR, ExecutorTestCase, EngineEmul
from tests.unit.modules.selenium import SeleniumTestCase


class TestTestNGTester(ExecutorTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from bzt.modules.javascript import NPMPackage, WebdriverIOExecutor, JavaScriptExecutor, NewmanExecutor, Mocha, JSSeleniumWebdriver
from bzt.utils import get_full_path, EXE_SUFFIX

from tests import BUILD_DIR, RESOURCES_DIR, BZTestCase
from tests.mocks import EngineEmul
from tests.modules.selenium import SeleniumTestCase
from tests.unit import RESOURCES_DIR, BZTestCase, EngineEmul
from tests.unit.modules.selenium import SeleniumTestCase


class TestSeleniumMochaRunner(SeleniumTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from bzt.modules.apiritif import ApiritifNoseExecutor
from bzt.modules.pytest import PyTestExecutor
from bzt.modules.robot import RobotExecutor
from tests import RESOURCES_DIR, ExecutorTestCase, BZTestCase
from tests.modules.selenium import SeleniumTestCase
from tests.unit import RESOURCES_DIR, ExecutorTestCase, BZTestCase
from tests.unit.modules.selenium import SeleniumTestCase
from bzt.resources.selenium_extras import get_locator, BYS
from bzt.utils import EXE_SUFFIX

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import bzt
from bzt.utils import EXE_SUFFIX
from tests import RESOURCES_DIR
from tests.modules.selenium import SeleniumTestCase
from tests.unit import RESOURCES_DIR
from tests.unit.modules.selenium import SeleniumTestCase


class TestSeleniumRSpecRunner(SeleniumTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import os

from bzt import TaurusConfigError
from tests import RESOURCES_DIR
from tests.modules.selenium import SeleniumTestCase
from tests.unit import RESOURCES_DIR
from tests.unit.modules.selenium import SeleniumTestCase


class TestSeleniumScriptGeneration(SeleniumTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from bzt.modules.provisioning import Local
from bzt.modules.selenium import SeleniumExecutor
from bzt.utils import LDJSONReader, FileReader
from tests import BZTestCase, RESOURCES_DIR, ROOT_LOGGER
from tests.mocks import EngineEmul, DummyListener
from tests.modules.selenium import SeleniumTestCase
from tests.unit import BZTestCase, RESOURCES_DIR, ROOT_LOGGER, EngineEmul
from tests.unit.mocks import DummyListener
from tests.unit.modules.selenium import SeleniumTestCase


class LDJSONReaderEmul(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

from bzt.modules.ab import ApacheBenchmarkExecutor, TSVDataReader
from tests import BZTestCase, ExecutorTestCase, RESOURCES_DIR, close_reader_file, ROOT_LOGGER
from tests.unit import BZTestCase, ExecutorTestCase, RESOURCES_DIR, close_reader_file, ROOT_LOGGER
from bzt.utils import EXE_SUFFIX
from bzt import ToolError, TaurusConfigError

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from bzt.modules.functional import ResultsTree, FunctionalSample
from bzt.modules.reporting import FinalStatus
from bzt.utils import BetterDict
from tests import BZTestCase, random_datapoint
from tests.mocks import EngineEmul
from tests.unit import BZTestCase, random_datapoint, EngineEmul


class TestFinalStatusReporter(BZTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from bzt import ManualShutdown
from bzt.modules.console import TaurusConsole
from bzt.utils import is_linux
from tests import BZTestCase
from tests.unit import BZTestCase

from bzt.modules.screen import GUIScreen as Screen

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bzt.modules.gatling import GatlingExecutor, DataLogReader, is_gatling2
from bzt.modules.provisioning import Local
from bzt.utils import EXE_SUFFIX, get_full_path, is_windows
from tests import ExecutorTestCase, BZTestCase, get_cwd, RESOURCES_DIR, BUILD_DIR, close_reader_file, ROOT_LOGGER
from tests.unit import ExecutorTestCase, BZTestCase, RESOURCES_DIR, BUILD_DIR, close_reader_file, ROOT_LOGGER


class TestGatlingExecutor(ExecutorTestCase):
Expand Down Expand Up @@ -452,7 +452,6 @@ def test_script_jar(self):
def test_files_find_file(self):
curdir = get_full_path(os.curdir)
try:
os.chdir(get_cwd() + "/../")
self.obj.engine.file_search_paths.append(RESOURCES_DIR + "gatling/")
self.obj.engine.config.merge({
"execution": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
from bzt import ToolError
from tests import BZTestCase, RESOURCES_DIR, BUILD_DIR, close_reader_file, ROOT_LOGGER, ExecutorTestCase
from tests.unit import BZTestCase, RESOURCES_DIR, BUILD_DIR, close_reader_file, ROOT_LOGGER, ExecutorTestCase

from bzt.modules.aggregator import DataPoint, KPISet
from bzt.modules.grinder import GrinderExecutor, DataLogReader, Grinder, GrinderMirrorsManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from bzt.modules.passfail import PassFailStatus, DataCriterion, CriteriaProcessor
from bzt.modules.reporting import JUnitXMLReporter
from bzt.utils import etree, BetterDict
from tests import BZTestCase, RESOURCES_DIR, ROOT_LOGGER
from tests.mocks import EngineEmul
from tests.unit import BZTestCase, RESOURCES_DIR, ROOT_LOGGER, EngineEmul


class TestJUnitXML(BZTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from bzt import ToolError
from bzt.engine import EXEC
from bzt.modules.provisioning import Local
from tests import BZTestCase
from tests.mocks import EngineEmul
from tests.unit import BZTestCase, EngineEmul


class ScenarioExecutorEmul(object):
Expand Down
Loading

0 comments on commit 1725500

Please sign in to comment.