From 0a8d781ccd8046b3cab5cbc76bee88f4aa8373f8 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 21 Jun 2021 08:27:34 +0200 Subject: [PATCH] #77: Increase coverage, restore tests pipeline --- .github/workflows/test-and-release-rkd.yaml | 78 +++++++++---------- src/core/tests/test_api_syntax.py | 28 +++++++ src/core/tests/test_packaging.py | 2 - .../tests/test_standardlib_createstructure.py | 34 ++++++++ .../tests/test_syntax_task_declaration.py | 20 +++++ .../tests/test_syntax_taskaliasdeclaration.py | 24 ++++++ 6 files changed, 145 insertions(+), 41 deletions(-) create mode 100644 src/core/tests/test_api_syntax.py create mode 100644 src/core/tests/test_syntax_taskaliasdeclaration.py diff --git a/.github/workflows/test-and-release-rkd.yaml b/.github/workflows/test-and-release-rkd.yaml index b7446165..ec605ee5 100644 --- a/.github/workflows/test-and-release-rkd.yaml +++ b/.github/workflows/test-and-release-rkd.yaml @@ -2,47 +2,47 @@ name: Test and release a package on: [push] jobs: -# test: -# runs-on: ubuntu-20.04 -# strategy: -# matrix: -# python-version: ["3.8", "3.9", "3.7"] -# steps: -# - name: Set GIT identity -# run: | -# git config --global user.email "riotkit@example.org" -# git config --global user.name "Buenaventura Durruti" -# -# - name: Checkout -# uses: actions/checkout@v2 -# -# - name: Setup Python ${{ matrix.python-version }} -# uses: actions/setup-python@v2 -# with: -# python-version: ${{ matrix.python-version }} -# -# - name: Install dependencies -# run: "make deps" -# -# - name: Build project -# run: "make package" -# -# - name: Run RKD tests on Python ${{ matrix.python-version }} -# run: "make tests" -# -# - name: Archive RKD tests results -# uses: dorny/test-reporter@v1 -# if: always() -# with: -# name: "[${{ matrix.python-version }}] RKD tests" -# path: src/*/build/tests.xml -# reporter: java-junit -# -# - name: Run rkd_python tests on Python ${{ matrix.python-version }} -# run: "cd subpackages/rkd_python && make tests" + test: + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: ["3.8", "3.9", "3.7"] + steps: + - name: Set GIT identity + run: | + git config --global user.email "riotkit@example.org" + git config --global user.name "Buenaventura Durruti" + + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: "make deps" + + - name: Build project + run: "make package" + + - name: Run RKD tests on Python ${{ matrix.python-version }} + run: "make tests" + + - name: Archive RKD tests results + uses: dorny/test-reporter@v1 + if: always() + with: + name: "[${{ matrix.python-version }}] RKD tests" + path: src/*/build/tests.xml + reporter: java-junit + + - name: Run rkd_python tests on Python ${{ matrix.python-version }} + run: "cd subpackages/rkd_python && make tests" release: -# needs: [test] + needs: [test] runs-on: ubuntu-20.04 if: always() steps: diff --git a/src/core/tests/test_api_syntax.py b/src/core/tests/test_api_syntax.py new file mode 100644 index 00000000..85b10391 --- /dev/null +++ b/src/core/tests/test_api_syntax.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +from rkd.core.api.testing import BasicTestingCase +from rkd.core.api.syntax import parse_path_into_subproject_prefix, merge_workdir + + +class TestApiSyntax(BasicTestingCase): + def test_parse_path_into_subproject_prefix(self): + self.assertEqual(':subproject1:subproject2:subproject3', + parse_path_into_subproject_prefix('subproject1/subproject2/subproject3')) + + def test_merge_workdir_leaves_task_workdir_if_not_in_subproject(self): + self.assertEqual('build/', merge_workdir( + task_workdir='build/', + subproject_workdir='' + )) + + def test_merge_workdir_leaves_absolute_path_for_task_even_if_in_subproject(self): + self.assertEqual('/var/www/html', merge_workdir( + task_workdir='/var/www/html', + subproject_workdir='docs' + )) + + def test_merge_workdir_concatenates_workdir_when_task_has_workdir_and_in_subproject(self): + self.assertEqual('infrastructure/docs', merge_workdir( + task_workdir='docs', + subproject_workdir='infrastructure' + )) diff --git a/src/core/tests/test_packaging.py b/src/core/tests/test_packaging.py index b4a36374..085e4562 100644 --- a/src/core/tests/test_packaging.py +++ b/src/core/tests/test_packaging.py @@ -1,11 +1,9 @@ #!/usr/bin/env python3 -import glob import os import subprocess import tempfile from unittest import mock from rkd.core.api.testing import BasicTestingCase -from rkd.process import check_call import rkd.core.packaging TESTS_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/src/core/tests/test_standardlib_createstructure.py b/src/core/tests/test_standardlib_createstructure.py index dffae29b..bc4d96a2 100644 --- a/src/core/tests/test_standardlib_createstructure.py +++ b/src/core/tests/test_standardlib_createstructure.py @@ -234,3 +234,37 @@ def test_pipenv_is_supported(self): finally: os.chdir(cwd) + + def test_local_directory_install(self): + """ + Checks if with pipenv RKD is installed as local package in "editable" mode + :return: + """ + + with TemporaryDirectory() as tempdir: + cwd = os.getcwd() + + try: + os.chdir(tempdir) + + # action + self._execute_mocked_task( + params={ + '--commit': False, + '--no-venv': False, + '--pipenv': True, + '--latest': True, + '--rkd-dev': NAMESPACE_DIR + }, + envs={} + ) + + # assertions + with open(tempdir + '/Pipfile', 'r') as f: + pipfile = f.read() + + self.assertIn('"rkd.process" = {editable = true, path = "', pipfile) + self.assertIn('"rkd.core" = {editable = true, path = "', pipfile) + + finally: + os.chdir(cwd) diff --git a/src/core/tests/test_syntax_task_declaration.py b/src/core/tests/test_syntax_task_declaration.py index 1165f2f5..72b94947 100644 --- a/src/core/tests/test_syntax_task_declaration.py +++ b/src/core/tests/test_syntax_task_declaration.py @@ -43,3 +43,23 @@ def test_get_full_description_allows_empty_doc(self): declaration.get_task_to_execute().__doc__ = None self.assertEqual('', declaration.get_full_description()) + + def test_to_full_name_includes_subproject(self): + declaration = get_test_declaration() + declaration._project_name = ':docs' + + # :rkd:test comes from get_test_declaration() + self.assertEqual(':docs:rkd:test', declaration.to_full_name()) + + def test_as_part_of_subproject_appends_required_attributes(self): + declaration = get_test_declaration() + + subproject_declaration = declaration.as_part_of_subproject('/tmp', ':docs') + + # new declaration + self.assertEqual(':docs:rkd:test', subproject_declaration.to_full_name()) + self.assertEqual('/tmp/', subproject_declaration.workdir) + + # old should be NOT TOUCHED + self.assertEqual(':rkd:test', declaration.to_full_name()) + self.assertEqual('.', declaration.workdir) diff --git a/src/core/tests/test_syntax_taskaliasdeclaration.py b/src/core/tests/test_syntax_taskaliasdeclaration.py new file mode 100644 index 00000000..5ea7d7c5 --- /dev/null +++ b/src/core/tests/test_syntax_taskaliasdeclaration.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +from rkd.core.api.testing import BasicTestingCase +from rkd.core.api.syntax import TaskAliasDeclaration + + +class TestTaskAliasDeclaration(BasicTestingCase): + def test_get_name(self): + ta = TaskAliasDeclaration(':bakunin', [':list']) + self.assertEqual(':bakunin', ta.get_name()) + + def test_get_name_includes_subproject(self): + ta = TaskAliasDeclaration(':bakunin', [':list']) + ta_subproject = ta.as_part_of_subproject('books', ':books') + + self.assertEqual(':books:bakunin', ta_subproject.get_name()) + self.assertNotEqual(ta, ta_subproject) + + def test_is_part_of_subproject(self): + ta = TaskAliasDeclaration(':bakunin', [':list']) + ta_subproject = ta.as_part_of_subproject('books', ':books') + + self.assertTrue(ta_subproject.is_part_of_subproject()) + self.assertFalse(ta.is_part_of_subproject())