From a72dd0dc2e9edc355159253537da4e916f0d3424 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 26 May 2022 15:29:49 +0200 Subject: [PATCH] Improved tests --- cpl-workspace.json | 11 +++++++++++ src/tests/unittests/application.py | 1 - src/tests/unittests_cli/cli_test_suite.py | 14 +++++++------- src/tests/unittests_cli/constants.py | 3 ++- src/tests/unittests_cli/generate_test_case.py | 7 ++----- src/tests/unittests_shared/cli_commands.py | 4 +++- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/cpl-workspace.json b/cpl-workspace.json index 3413e861..cf6608bf 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -15,14 +15,20 @@ }, "Scripts": { "hello-world": "echo 'Hello World'", + "sv": "cpl set-version", "set-version": "cpl run set-version $ARGS; echo '';", + "spu": "cpl set-pip-urls", "set-pip-urls": "cpl run set-pip-urls $ARGS; echo '';", + "docs-build": "echo 'Build Documentation'; cd docs/; sphinx-apidoc -o source/ ../src/cpl_core; sphinx-apidoc -o source/ ../src/cpl_query; make clean; make html; rm source/cpl_query.tests.rst;", "db": "cpl build-docs", "docs-open": "xdg-open $PWD/docs/build/html/index.html &", "do": "cpl docs-open", + + "test": "cpl run unittests", + "pre-build-all": "cpl sv $ARGS; cpl spu $ARGS;", "build-all": "cpl build-cli; cpl build-core; cpl build-query; cpl build-set-pip-urls; cpl build-set-version", "ba": "cpl build-all $ARGS", @@ -31,12 +37,14 @@ "build-query": "echo 'Build cpl-query'; cd ./src/cpl_query; cpl build; cd ../../;", "build-set-pip-urls": "echo 'Build set-pip-urls'; cd ./tools/set_pip_urls; cpl build; cd ../../;", "build-set-version": "echo 'Build set-version'; cd ./tools/set_version; cpl build; cd ../../;", + "pre-publish-all": "cpl sv $ARGS; cpl spu $ARGS;", "publish-all": "cpl publish-cli; cpl publish-core; cpl publish-query;", "pa": "cpl build-all $ARGS", "publish-cli": "echo 'Publish cpl-cli'; cd ./src/cpl_cli; cpl publish; cd ../../;", "publish-core": "echo 'Publish cpl-core'; cd ./src/cpl_core; cpl publish; cd ../../;", "publish-query": "echo 'Publish cpl_query'; cd ./src/cpl_query; cpl publish; cd ../../;", + "upload-prod-cli": "echo 'PROD Upload cpl-cli'; cpl upl-prod-cli;", "upl-prod-cli": "twine upload -r pip.sh-edraft.de dist/cpl-cli/publish/setup/*", "upload-prod-core": "echo 'PROD Upload cpl-core'; cpl upl-prod-core;", @@ -55,18 +63,21 @@ "upl-dev-core": "twine upload -r pip-dev.sh-edraft.de dist/cpl-core/publish/setup/*", "upload-dev-query": "echo 'DEV Upload cpl_query'; cpl upl-dev-query;", "upl-dev-query": "twine upload -r pip-dev.sh-edraft.de dist/cpl-query/publish/setup/*", + "pre-deploy-prod": "cpl sv $ARGS; cpl spu --environment=production;", "deploy-prod": "cpl deploy-prod-cli; cpl deploy-prod-core; cpl deploy-prod-query;", "dp": "cpl deploy-prod $ARGS", "deploy-prod-cli": "cpl publish-cli; cpl upload-prod-cli", "deploy-prod-core": "cpl publish-core; cpl upload-prod-core", "deploy-prod-query": "cpl publish-query; cpl upload-prod-query", + "pre-deploy-exp": "cpl sv $ARGS; cpl spu --environment=staging;", "deploy-exp": "cpl deploy-exp-cli; cpl deploy-exp-core; cpl deploy-exp-query;", "de": "cpl deploy-exp $ARGS", "deploy-exp-cli": "cpl publish-cli; cpl upload-exp-cli", "deploy-exp-core": "cpl publish-core; cpl upload-exp-core", "deploy-exp-query": "cpl publish-query; cpl upload-exp-query", + "pre-deploy-dev": "cpl sv $ARGS; cpl spu --environment=development;", "deploy-dev": "cpl deploy-dev-cli; cpl deploy-dev-core; cpl deploy-dev-query;", "dd": "cpl deploy-dev $ARGS", diff --git a/src/tests/unittests/application.py b/src/tests/unittests/application.py index 2b7af5c8..9af5ad57 100644 --- a/src/tests/unittests/application.py +++ b/src/tests/unittests/application.py @@ -1,4 +1,3 @@ -import time import unittest from cpl_core.application import ApplicationABC diff --git a/src/tests/unittests_cli/cli_test_suite.py b/src/tests/unittests_cli/cli_test_suite.py index eb82349a..9532fe0c 100644 --- a/src/tests/unittests_cli/cli_test_suite.py +++ b/src/tests/unittests_cli/cli_test_suite.py @@ -5,7 +5,7 @@ import unittest from unittests_cli.add_test_case import AddTestCase from unittests_cli.build_test_case import BuildTestCase -from unittests_cli.constants import PLAYGROUND +from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.generate_test_case import GenerateTestCase from unittests_cli.install_test_case import InstallTestCase from unittests_cli.new_test_case import NewTestCase @@ -45,19 +45,19 @@ class CLITestSuite(unittest.TestSuite): def _setup(self): print(f'Setup {__name__}') try: - if os.path.exists(PLAYGROUND): - shutil.rmtree(PLAYGROUND) + if os.path.exists(PLAYGROUND_PATH): + shutil.rmtree(PLAYGROUND_PATH) - os.mkdir(PLAYGROUND) - os.chdir(PLAYGROUND) + os.mkdir(PLAYGROUND_PATH) + os.chdir(PLAYGROUND_PATH) except Exception as e: print(f'Setup of {__name__} failed: {traceback.format_exc()}') def _cleanup(self): print(f'Cleanup {__name__}') try: - if os.path.exists(PLAYGROUND): - shutil.rmtree(PLAYGROUND) + if os.path.exists(PLAYGROUND_PATH): + shutil.rmtree(PLAYGROUND_PATH) except Exception as e: print(f'Cleanup of {__name__} failed: {traceback.format_exc()}') diff --git a/src/tests/unittests_cli/constants.py b/src/tests/unittests_cli/constants.py index 272a19e0..bcaa9d93 100644 --- a/src/tests/unittests_cli/constants.py +++ b/src/tests/unittests_cli/constants.py @@ -1,3 +1,4 @@ import os -PLAYGROUND = os.path.abspath(os.path.join(os.getcwd(), '../generated/test_cli_playground')) \ No newline at end of file +PLAYGROUND_PATH = os.path.abspath(os.path.join(os.getcwd(), '../generated/test_cli_playground')) +CLI_PATH = os.path.abspath(os.path.join(os.getcwd(), '../../cpl_cli/main.py')) diff --git a/src/tests/unittests_cli/generate_test_case.py b/src/tests/unittests_cli/generate_test_case.py index 5530ccba..ecc11e68 100644 --- a/src/tests/unittests_cli/generate_test_case.py +++ b/src/tests/unittests_cli/generate_test_case.py @@ -1,18 +1,15 @@ import os.path import unittest -from unittests_cli.constants import PLAYGROUND +from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands class GenerateTestCase(unittest.TestCase): - def setUp(self): - pass - def _test_file(self, schematic: str, suffix: str): CLICommands.generate(schematic, 'GeneratedFile') - file_path = os.path.abspath(os.path.join(PLAYGROUND, f'generated_file{suffix}.py')) + file_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, f'generated_file{suffix}.py')) file_exists = os.path.exists(file_path) self.assertTrue(file_exists) os.remove(file_path) diff --git a/src/tests/unittests_shared/cli_commands.py b/src/tests/unittests_shared/cli_commands.py index 23cb5589..8903bf28 100644 --- a/src/tests/unittests_shared/cli_commands.py +++ b/src/tests/unittests_shared/cli_commands.py @@ -1,13 +1,15 @@ import os import subprocess +from unittests_cli.constants import CLI_PATH + class CLICommands: @staticmethod def _run(cmd: str, *args): env_vars = os.environ - command = ['python', os.path.abspath(os.path.join(os.getcwd(), '../../../cpl_cli/main.py')), cmd] + command = ['python', CLI_PATH, cmd] for arg in args: command.append(arg)