Skip to content

Commit

Permalink
write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlopez-rod committed Oct 6, 2023
1 parent 5377baa commit 077bab4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
m/.m
.mypy_cache
__pycache__
.coverage
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ mypy:

action:
m github actions src/pkg/actions.py

tests:
./src/tests/run.sh
4 changes: 2 additions & 2 deletions src/pkg/actions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from m.github.actions import Action

from .inputs import GithubInputs
from .main import main_step
from pkg.inputs import GithubInputs
from pkg.main import main_step

actions = Action(
name='Square Number',
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from m.core import Good, Res
from m.github.actions import KebabModel, OutArg, RunStep, run_action

from .inputs import GithubInputs
from pkg.inputs import GithubInputs


class Outputs(KebabModel):
Expand Down
4 changes: 4 additions & 0 deletions src/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from m.testing import block_m_side_effects, block_network_access

block_m_side_effects()
block_network_access()
20 changes: 20 additions & 0 deletions src/tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -euo pipefail

export DEBUG_HTTP_INCLUDE_BODY=1

SINGLE=true
SINGLE=false

pyPath="src"
baseSrc="src/pkg"
if [ "$SINGLE" = 'false' ]; then
coverage run --source "$baseSrc" -m pytest -p no:logging
coverage report -m --fail-under 98
else
# To run specific tests:
filter="test_testing"
source="$baseSrc"
coverage run --source "$source" -m pytest -p no:logging "$pyPath" -vv -k "$filter"
coverage report -m
fi
29 changes: 29 additions & 0 deletions src/tests/test_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
from m.github.actions import Action
from m.testing import ActionStepTestCase as TCase
from m.testing import run_action_test_case
from pytest_mock import MockerFixture

from pkg.actions import actions


@pytest.mark.parametrize(
'tcase',
[
TCase(
name='square_number',
py_file=f'src/pkg/main.py',
inputs={'INPUT_NUM': '4'},
expected_stdout='Squaring the number\n',
outputs=['squared-num=16'],
),
],
ids=lambda tcase: tcase.name,
)
def test_m_gh_actions_api(tcase: TCase, mocker: MockerFixture) -> None:
run_action_test_case(mocker, tcase)


def test_actions_instance() -> None:
assert isinstance(actions, Action)
assert actions.name == 'Square Number'

0 comments on commit 077bab4

Please sign in to comment.