Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#77: Increase coverage, restore tests pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Jun 21, 2021
1 parent c5f8a76 commit 0a8d781
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 41 deletions.
78 changes: 39 additions & 39 deletions .github/workflows/test-and-release-rkd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
# 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 "[email protected]"
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:
Expand Down
28 changes: 28 additions & 0 deletions src/core/tests/test_api_syntax.py
Original file line number Diff line number Diff line change
@@ -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'
))
2 changes: 0 additions & 2 deletions src/core/tests/test_packaging.py
Original file line number Diff line number Diff line change
@@ -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__))
Expand Down
34 changes: 34 additions & 0 deletions src/core/tests/test_standardlib_createstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 20 additions & 0 deletions src/core/tests/test_syntax_task_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 24 additions & 0 deletions src/core/tests/test_syntax_taskaliasdeclaration.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 0a8d781

Please sign in to comment.