diff --git a/.gitignore b/.gitignore index c7b3d78..175152c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ config.conf *.DS_Store *.pyc +.coverage* .repo !addons/ diff --git a/Makefile b/Makefile index 4335718..f0baef1 100644 --- a/Makefile +++ b/Makefile @@ -555,6 +555,18 @@ test_full_fast: # TODO This test is broken in parallel ./script/make.sh test_code_generator_hello_world +.PHONY: test_full_fast_coverage +test_full_fast_coverage: + ./script/make.sh clean + ./.venv/bin/coverage erase + ./script/test/run_parallel_test.py --coverage + # TODO This test is broken in parallel + ./script/make.sh test_code_generator_hello_world + ./.venv/bin/coverage combine -a + ./.venv/bin/coverage report -m --include="addons/TechnoLibre_odoo-code-generator/*" + ./.venv/bin/coverage html --include="addons/TechnoLibre_odoo-code-generator/*" + # run: make open_test_coverage + .PHONY: test_base test_base: ./script/make.sh test_format @@ -675,6 +687,55 @@ test_code_generator_demo_mariadb_sql_example_1: #./script/addons/install_addons_dev.sh test_code_generator code_generator_demo_mariadb_sql_example_1 ./script/code_generator/install_and_test_code_generator.sh test_code_generator code_generator_demo_mariadb_sql_example_1 ./addons/TechnoLibre_odoo-code-generator-template demo_mariadb_sql_example_1 +############### +# Test addons # +############### +.PHONY: test_addons_sale +test_addons_sale: + ./.venv/bin/coverage erase + ./.venv/bin/python3 ./odoo/odoo-bin db --drop --database test_addons_sale + ./test.sh -d test_addons_sale --db-filter test_addons_sale -i sale + ./.venv/bin/coverage combine -a + ./.venv/bin/coverage report -m + ./.venv/bin/coverage html + +.PHONY: test_addons_helpdesk +test_addons_helpdesk: + ./.venv/bin/coverage erase + ./.venv/bin/python3 ./odoo/odoo-bin db --drop --database test_addons_helpdesk + ./test.sh -d test_addons_helpdesk --db-filter test_addons_helpdesk -i helpdesk_mgmt + ./.venv/bin/coverage combine -a + ./.venv/bin/coverage report -m + ./.venv/bin/coverage html + +.PHONY: test_addons_code_generator +test_addons_code_generator: + ./.venv/bin/coverage erase + ./.venv/bin/python3 ./odoo/odoo-bin db --drop --database test_addons_code_generator + # TODO missing test in code_generator + ./test.sh --dev all -d test_addons_code_generator --db-filter test_addons_code_generator -i code_generator + ./.venv/bin/coverage combine -a + ./.venv/bin/coverage report -m --include="addons/TechnoLibre_odoo-code-generator/*" + ./.venv/bin/coverage html --include="addons/TechnoLibre_odoo-code-generator/*" + # run: make open_test_coverage + +.PHONY: test_addons_code_generator_code_generator +test_addons_code_generator_code_generator: + # TODO this test only generation, not test + ./.venv/bin/coverage erase + ./script/db_restore.py --database test_addons_code_generator_code_generator + ./test.sh --dev all -d test_addons_code_generator_code_generator --db-filter test_addons_code_generator_code_generator -i code_generator_code_generator + ./.venv/bin/coverage combine -a + ./.venv/bin/coverage report -m --include="addons/TechnoLibre_odoo-code-generator/*" + ./.venv/bin/coverage html --include="addons/TechnoLibre_odoo-code-generator/*" + # run: make open_test_coverage + +.PHONY: open_test_coverage +open_test_coverage: + -$(BROWSER) htmlcov/index.html + +# TODO load specific test file : ./run.sh -d test_file --log-level=test --test-enable --stop-after-init --test-file ./.venv/test.py + ######### # tag # ######### diff --git a/coverage_run.sh b/coverage_run.sh new file mode 100755 index 0000000..5c79454 --- /dev/null +++ b/coverage_run.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +source ./.venv/bin/activate + +CONFIG_PATH="./config.conf" +ORIGIN_CONFIG_PATH=CONFIG_PATH +if [ ! -f "${CONFIG_PATH}" ]; then + CONFIG_PATH="/etc/odoo/odoo.conf" + if [ ! -f "${CONFIG_PATH}" ]; then + echo "Cannot find ERPLibre configuration ${ORIGIN_CONFIG_PATH}, did you install ERPLibre? > make install" + exit 1 + fi +fi + +coverage run -p ./odoo/odoo-bin -c ${CONFIG_PATH} --limit-time-real 99999 --limit-time-cpu 99999 $@ +retVal=$? +if [[ $retVal -ne 0 ]]; then + echo "Error coverage_run.sh" + exit 1 +fi diff --git a/poetry.lock b/poetry.lock index acda6bd..bc7e4ad 100644 --- a/poetry.lock +++ b/poetry.lock @@ -371,6 +371,17 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "coverage" +version = "6.3.2" +description = "Code coverage measurement for Python" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +toml = ["tomli"] + [[package]] name = "cryptography" version = "36.0.1" @@ -3148,7 +3159,7 @@ python-versions = "*" [metadata] lock-version = "1.1" python-versions = "^3.7.12" -content-hash = "3a75c2f6e62bbe624c58a7488212953db615b8260effb00d95bf7ffe6be66f7c" +content-hash = "9843e1be86c104cfe1e2aa6316baf8c5fe40834f65e29ac66c60f638a2e3cd77" [metadata.files] agithub = [ @@ -3342,6 +3353,49 @@ colorclass = [ compressed-rtf = [ {file = "compressed_rtf-1.0.6.tar.gz", hash = "sha256:c1c827f1d124d24608981a56e8b8691eb1f2a69a78ccad6440e7d92fde1781dd"}, ] +coverage = [ + {file = "coverage-6.3.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9b27d894748475fa858f9597c0ee1d4829f44683f3813633aaf94b19cb5453cf"}, + {file = "coverage-6.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:37d1141ad6b2466a7b53a22e08fe76994c2d35a5b6b469590424a9953155afac"}, + {file = "coverage-6.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f9987b0354b06d4df0f4d3e0ec1ae76d7ce7cbca9a2f98c25041eb79eec766f1"}, + {file = "coverage-6.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:26e2deacd414fc2f97dd9f7676ee3eaecd299ca751412d89f40bc01557a6b1b4"}, + {file = "coverage-6.3.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4dd8bafa458b5c7d061540f1ee9f18025a68e2d8471b3e858a9dad47c8d41903"}, + {file = "coverage-6.3.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:46191097ebc381fbf89bdce207a6c107ac4ec0890d8d20f3360345ff5976155c"}, + {file = "coverage-6.3.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:6f89d05e028d274ce4fa1a86887b071ae1755082ef94a6740238cd7a8178804f"}, + {file = "coverage-6.3.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:58303469e9a272b4abdb9e302a780072c0633cdcc0165db7eec0f9e32f901e05"}, + {file = "coverage-6.3.2-cp310-cp310-win32.whl", hash = "sha256:2fea046bfb455510e05be95e879f0e768d45c10c11509e20e06d8fcaa31d9e39"}, + {file = "coverage-6.3.2-cp310-cp310-win_amd64.whl", hash = "sha256:a2a8b8bcc399edb4347a5ca8b9b87e7524c0967b335fbb08a83c8421489ddee1"}, + {file = "coverage-6.3.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:f1555ea6d6da108e1999b2463ea1003fe03f29213e459145e70edbaf3e004aaa"}, + {file = "coverage-6.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e5f4e1edcf57ce94e5475fe09e5afa3e3145081318e5fd1a43a6b4539a97e518"}, + {file = "coverage-6.3.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7a15dc0a14008f1da3d1ebd44bdda3e357dbabdf5a0b5034d38fcde0b5c234b7"}, + {file = "coverage-6.3.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:21b7745788866028adeb1e0eca3bf1101109e2dc58456cb49d2d9b99a8c516e6"}, + {file = "coverage-6.3.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:8ce257cac556cb03be4a248d92ed36904a59a4a5ff55a994e92214cde15c5bad"}, + {file = "coverage-6.3.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:b0be84e5a6209858a1d3e8d1806c46214e867ce1b0fd32e4ea03f4bd8b2e3359"}, + {file = "coverage-6.3.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:acf53bc2cf7282ab9b8ba346746afe703474004d9e566ad164c91a7a59f188a4"}, + {file = "coverage-6.3.2-cp37-cp37m-win32.whl", hash = "sha256:8bdde1177f2311ee552f47ae6e5aa7750c0e3291ca6b75f71f7ffe1f1dab3dca"}, + {file = "coverage-6.3.2-cp37-cp37m-win_amd64.whl", hash = "sha256:b31651d018b23ec463e95cf10070d0b2c548aa950a03d0b559eaa11c7e5a6fa3"}, + {file = "coverage-6.3.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:07e6db90cd9686c767dcc593dff16c8c09f9814f5e9c51034066cad3373b914d"}, + {file = "coverage-6.3.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:2c6dbb42f3ad25760010c45191e9757e7dce981cbfb90e42feef301d71540059"}, + {file = "coverage-6.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c76aeef1b95aff3905fb2ae2d96e319caca5b76fa41d3470b19d4e4a3a313512"}, + {file = "coverage-6.3.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8cf5cfcb1521dc3255d845d9dca3ff204b3229401994ef8d1984b32746bb45ca"}, + {file = "coverage-6.3.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8fbbdc8d55990eac1b0919ca69eb5a988a802b854488c34b8f37f3e2025fa90d"}, + {file = "coverage-6.3.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:ec6bc7fe73a938933d4178c9b23c4e0568e43e220aef9472c4f6044bfc6dd0f0"}, + {file = "coverage-6.3.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:9baff2a45ae1f17c8078452e9e5962e518eab705e50a0aa8083733ea7d45f3a6"}, + {file = "coverage-6.3.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:fd9e830e9d8d89b20ab1e5af09b32d33e1a08ef4c4e14411e559556fd788e6b2"}, + {file = "coverage-6.3.2-cp38-cp38-win32.whl", hash = "sha256:f7331dbf301b7289013175087636bbaf5b2405e57259dd2c42fdcc9fcc47325e"}, + {file = "coverage-6.3.2-cp38-cp38-win_amd64.whl", hash = "sha256:68353fe7cdf91f109fc7d474461b46e7f1f14e533e911a2a2cbb8b0fc8613cf1"}, + {file = "coverage-6.3.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:b78e5afb39941572209f71866aa0b206c12f0109835aa0d601e41552f9b3e620"}, + {file = "coverage-6.3.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:4e21876082ed887baed0146fe222f861b5815455ada3b33b890f4105d806128d"}, + {file = "coverage-6.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:34626a7eee2a3da12af0507780bb51eb52dca0e1751fd1471d0810539cefb536"}, + {file = "coverage-6.3.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1ebf730d2381158ecf3dfd4453fbca0613e16eaa547b4170e2450c9707665ce7"}, + {file = "coverage-6.3.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd6fe30bd519694b356cbfcaca9bd5c1737cddd20778c6a581ae20dc8c04def2"}, + {file = "coverage-6.3.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:96f8a1cb43ca1422f36492bebe63312d396491a9165ed3b9231e778d43a7fca4"}, + {file = "coverage-6.3.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:dd035edafefee4d573140a76fdc785dc38829fe5a455c4bb12bac8c20cfc3d69"}, + {file = "coverage-6.3.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5ca5aeb4344b30d0bec47481536b8ba1181d50dbe783b0e4ad03c95dc1296684"}, + {file = "coverage-6.3.2-cp39-cp39-win32.whl", hash = "sha256:f5fa5803f47e095d7ad8443d28b01d48c0359484fec1b9d8606d0e3282084bc4"}, + {file = "coverage-6.3.2-cp39-cp39-win_amd64.whl", hash = "sha256:9548f10d8be799551eb3a9c74bbf2b4934ddb330e08a73320123c07f95cc2d92"}, + {file = "coverage-6.3.2-pp36.pp37.pp38-none-any.whl", hash = "sha256:18d520c6860515a771708937d2f78f63cc47ab3b80cb78e86573b0a760161faf"}, + {file = "coverage-6.3.2.tar.gz", hash = "sha256:03e2a7826086b91ef345ff18742ee9fc47a6839ccd517061ef8fa1976e652ce9"}, +] cryptography = [ {file = "cryptography-36.0.1-cp36-abi3-macosx_10_10_universal2.whl", hash = "sha256:73bc2d3f2444bcfeac67dd130ff2ea598ea5f20b40e36d19821b4df8c9c5037b"}, {file = "cryptography-36.0.1-cp36-abi3-macosx_10_10_x86_64.whl", hash = "sha256:2d87cdcb378d3cfed944dac30596da1968f88fb96d7fc34fdae30a99054b2e31"}, diff --git a/pyproject.toml b/pyproject.toml index 96dec0d..cd005e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -173,6 +173,7 @@ xmlformatter = "^0.2.4" xmltodict = "^0.12.0" zeep = "^4.1.0" zxcvbn = "^4.4.28" +coverage = "^6.3.2" [tool.poetry.dev-dependencies] websocket_client = "^1.1.0" diff --git a/requirements.txt b/requirements.txt index 7f5db66..a45dd9b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,6 +34,7 @@ python-git voicent-python python-swiftclient python-keystoneclient +coverage # For logical test docutils==0.17.1 diff --git a/script/addons/coverage_install_addons.sh b/script/addons/coverage_install_addons.sh new file mode 100755 index 0000000..ca2190a --- /dev/null +++ b/script/addons/coverage_install_addons.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Argument 3 is config +if [[ $# -eq 3 ]]; then + ./script/addons/check_addons_exist.py -m "$2" -c "$3" +else + ./script/addons/check_addons_exist.py -m "$2" +fi +retVal=$? +if [[ $retVal -ne 0 ]]; then + echo "Error check_addons_exist.py into coverage_install_addons.sh" + exit 1 +fi +if [[ $# -eq 3 ]]; then + ./coverage_run.sh --no-http --stop-after-init -d "$1" -i "$2" -u "$2" -c "$3" +else + ./coverage_run.sh --no-http --stop-after-init -d "$1" -i "$2" -u "$2" +fi + +retVal=$? +if [[ $retVal -ne 0 ]]; then + echo "Error coverage_run.sh into coverage_install_addons.sh" + exit 1 +fi diff --git a/script/addons/coverage_install_addons_dev.sh b/script/addons/coverage_install_addons_dev.sh new file mode 100755 index 0000000..89e813a --- /dev/null +++ b/script/addons/coverage_install_addons_dev.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Argument 3 is config +if [[ $# -eq 3 ]]; then + ./script/addons/check_addons_exist.py -m "$2" -c "$3" +else + ./script/addons/check_addons_exist.py -m "$2" +fi +retVal=$? +if [[ $retVal -ne 0 ]]; then + echo "Error check_addons_exist.py into coverage_install_addons_dev.sh" + exit 1 +fi +if [[ $# -eq 3 ]]; then + ./coverage_run.sh --no-http --stop-after-init --dev qweb -d "$1" -i "$2" -u "$2" -c "$3" +else + ./coverage_run.sh --no-http --stop-after-init --dev qweb -d "$1" -i "$2" -u "$2" +fi + +retVal=$? +if [[ $retVal -ne 0 ]]; then + echo "Error coverage_run.sh into coverage_install_addons_dev.sh" + exit 1 +fi diff --git a/script/code_generator/coverage_install_and_test_code_generator.sh b/script/code_generator/coverage_install_and_test_code_generator.sh new file mode 100755 index 0000000..c43f38e --- /dev/null +++ b/script/code_generator/coverage_install_and_test_code_generator.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# $1 is database name +# $2 is module name separate by , +# $3 is directory path to check +# $4 is generated module name separate by , +# $5 optional, the config path + +if [[ $# -lt 4 ]]; then + echo "ERROR, need 4 arguments: 1-database name, 2-list of module to install, 3-directory to check difference, 4-list of generated module" + exit 1 +fi + +INIT_DATETIME=$(date +%s) + +if [[ $# -eq 5 ]]; then + ./script/addons/coverage_install_addons_dev.sh "$1" "$2" "$5" + retVal=$? + if [[ $retVal -ne 0 ]]; then + echo "Error ./script/addons/coverage_install_addons_dev.sh ${1} ${2} ${5}" + exit 1 + fi +else + ./script/addons/coverage_install_addons_dev.sh "$1" "$2" + retVal=$? + if [[ $retVal -ne 0 ]]; then + echo "Error ./script/addons/coverage_install_addons_dev.sh ${1} ${2}" + exit 1 + fi +fi + +# Check if the code was updated +./script/code_generator/test_code_generator_update_module.py -m "$4" -d "$3" --datetime "${INIT_DATETIME}" +retVal=$? +if [[ $retVal -ne 0 ]]; then + echo "Error ./script/code_generator/test_code_generator_update_module.py ${4} ${3}" + exit 1 +fi + +# TODO check output when got warning +./script/repo_revert_git_diff_date_from_code_generator.py --repo "$3" +# Remove pot and po diff +cd "$3" || exit 1 +# git 2.22 and more, else use next command +#BRANCH=$(git branch --show-current) +#BRANCH=$(git rev-parse --abbrev-ref HEAD) + +# Support old version git < 2.23.0 +# git restore --source="${BRANCH}" "*.po*" +git checkout -- "*.po*" + +cd - || exit 1 +./script/maintenance/black.sh "$3" +echo "TEST ${2}" +./script/code_generator/check_git_change_code_generator.sh "$3" +retVal=$? +if [[ $retVal -ne 0 ]]; then + echo "Error ./script/code_generator/check_git_change_code_generator.sh" + exit 1 +fi diff --git a/script/code_generator/new_project.py b/script/code_generator/new_project.py index 19757be..ba7a8dc 100755 --- a/script/code_generator/new_project.py +++ b/script/code_generator/new_project.py @@ -57,6 +57,11 @@ def get_config(): "--directory_code_generator", help="The directory of the code_generator to use.", ) + parser.add_argument( + "--coverage", + action="store_true", + help="Execute coverage file.", + ) parser.add_argument( "--code_generator_name", help="The name of the code_generator to use.", @@ -100,8 +105,10 @@ class ProjectManagement: template_directory="", force=False, keep_bd_alive=False, + coverage=False, ): self.force = force + self._coverage = coverage self.keep_bd_alive = keep_bd_alive self.msg_error = "" self.has_config_update = False @@ -317,10 +324,17 @@ class ProjectManagement: _logger.info(cmd) os.system(cmd) _logger.info("========= GENERATE code_generator_demo =========") - cmd = ( - f"./script/addons/install_addons_dev.sh {bd_name_demo}" - f" code_generator_demo {config_path}" - ) + + if self._coverage: + cmd = ( + "./script/addons/coverage_install_addons_dev.sh" + f" {bd_name_demo} code_generator_demo {config_path}" + ) + else: + cmd = ( + f"./script/addons/install_addons_dev.sh {bd_name_demo}" + f" code_generator_demo {config_path}" + ) os.system(cmd) if not self.keep_bd_alive: @@ -370,17 +384,29 @@ class ProjectManagement: ) _logger.info(cmd) os.system(cmd) - cmd = ( - f"./script/addons/install_addons_dev.sh {bd_name_template}" - f" {self.module_name} {config_path}" - ) + if self._coverage: + cmd = ( + "./script/addons/coverage_install_addons_dev.sh" + f" {bd_name_template} {self.module_name} {config_path}" + ) + else: + cmd = ( + f"./script/addons/install_addons_dev.sh {bd_name_template}" + f" {self.module_name} {config_path}" + ) _logger.info(cmd) os.system(cmd) - cmd = ( - f"./script/addons/install_addons_dev.sh {bd_name_template}" - f" {self.template_name} {config_path}" - ) + if self._coverage: + cmd = ( + "./script/addons/coverage_install_addons_dev.sh" + f" {bd_name_template} {self.template_name} {config_path}" + ) + else: + cmd = ( + f"./script/addons/install_addons_dev.sh {bd_name_template}" + f" {self.template_name} {config_path}" + ) _logger.info(cmd) os.system(cmd) @@ -405,10 +431,16 @@ class ProjectManagement: os.system(cmd) _logger.info(f"========= GENERATE {self.cg_name} =========") - cmd = ( - f"./script/addons/install_addons_dev.sh {bd_name_generator}" - f" {self.cg_name} {config_path}" - ) + if self._coverage: + cmd = ( + "./script/addons/coverage_install_addons_dev.sh" + f" {bd_name_generator} {self.cg_name} {config_path}" + ) + else: + cmd = ( + f"./script/addons/install_addons_dev.sh {bd_name_generator}" + f" {self.cg_name} {config_path}" + ) _logger.info(cmd) os.system(cmd) @@ -476,6 +508,7 @@ def main(): template_name=config.template_name, force=config.force, keep_bd_alive=config.keep_bd_alive, + coverage=config.coverage, ) if project.msg_error: return -1 diff --git a/script/test/run_parallel_test.py b/script/test/run_parallel_test.py index 0add94e..b86224c 100755 --- a/script/test/run_parallel_test.py +++ b/script/test/run_parallel_test.py @@ -40,6 +40,11 @@ def get_config(): action="store_true", help="Will run in serial.", ) + parser.add_argument( + "--coverage", + action="store_true", + help="Execute coverage file.", + ) parser.add_argument( "--keep_cache", action="store_true", @@ -576,11 +581,18 @@ async def test_exec( if not test_status and lst_init_module_name: # Install required module str_test = ",".join(lst_init_module_name) - script_name = ( - "./script/addons/install_addons_dev.sh" - if tested_module - else "./script/addons/install_addons.sh" - ) + if config.coverage: + script_name = ( + "./script/addons/coverage_install_addons_dev.sh" + if tested_module + else "./script/addons/coverage_install_addons.sh" + ) + else: + script_name = ( + "./script/addons/install_addons_dev.sh" + if tested_module + else "./script/addons/install_addons.sh" + ) if new_config_path: res, status = await run_command( script_name, @@ -623,10 +635,15 @@ async def test_exec( # destination_path = install_path if not test_status and tested_module and generated_module: + cmd = ( + "./script/code_generator/coverage_install_and_test_code_generator.sh" + if config.coverage + else "./script/code_generator/install_and_test_code_generator.sh" + ) # Finally, the test if new_config_path: res, status = await run_command( - "./script/code_generator/install_and_test_code_generator.sh", + cmd, unique_database_name, tested_module, test_generated_path, @@ -636,7 +653,7 @@ async def test_exec( ) else: res, status = await run_command( - "./script/code_generator/install_and_test_code_generator.sh", + cmd, unique_database_name, tested_module, install_path, diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..85db1ad --- /dev/null +++ b/test.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Usage, ./test.sh -d test_addons_name -i module_name +source ./.venv/bin/activate + +CONFIG_PATH="./config.conf" +ORIGIN_CONFIG_PATH=CONFIG_PATH +if [ ! -f "${CONFIG_PATH}" ]; then + CONFIG_PATH="/etc/odoo/odoo.conf" + if [ ! -f "${CONFIG_PATH}" ]; then + echo "Cannot find ERPLibre configuration ${ORIGIN_CONFIG_PATH}, did you install ERPLibre? > make install" + exit 1 + fi +fi + +coverage run -p ./odoo/odoo-bin -c ${CONFIG_PATH} --limit-time-real 99999 --limit-time-cpu 99999 --log-level=test --test-enable --stop-after-init $@ +retVal=$? +if [[ $retVal -ne 0 ]]; then + echo "Error test.sh" + exit 1 +fi diff --git a/test/code_generator/coverage_hello_world.sh b/test/code_generator/coverage_hello_world.sh new file mode 100755 index 0000000..4b4bda2 --- /dev/null +++ b/test/code_generator/coverage_hello_world.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +Color_Off='\033[0m' # Text Reset +Red='\033[0;31m' # Red +Green='\033[0;32m' # Green + +tmp_dir=$(mktemp -d -t "erplibre_code_generator_helloworld-$(date +%Y-%m-%d-%H-%M-%S)-XXXXXXXXXX") + +./script/code_generator/new_project.py -m test -d "${tmp_dir}" + +MODULE_PATH="${tmp_dir}/test" +if [[ -d "${MODULE_PATH}" ]]; then + echo -e "${Green}SUCCESS${Color_Off} ${MODULE_PATH} exists." +else + echo -e "${Red}ERROR${Color_Off} ${MODULE_PATH} is missing." +fi + +rm -rf "${tmp_dir}"