Skip to content

Commit

Permalink
Merge pull request #33 from brainelectronics/feature/create-test-fram…
Browse files Browse the repository at this point in the history
…ework

Create test framework
  • Loading branch information
brainelectronics authored Dec 11, 2022
2 parents c45d6cc + 1a9e020 commit eee18c2
Show file tree
Hide file tree
Showing 46 changed files with 4,377 additions and 985 deletions.
4 changes: 3 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ignore = D107, D400, E501, W504, D204
# Specify a list of mappings of files and the codes that should be ignored for the entirety of the file.
per-file-ignores =
tests/*:D101,D102,D104
umodbus/const.py:F821

# Provide a comma-separated list of glob patterns to exclude from checks.
exclude =
Expand All @@ -32,7 +33,7 @@ exclude =
# There's no value in checking cache directories
__pycache__,
# The conf file is mostly autogenerated, ignore it
docs/source/conf.py,
docs/conf.py,
# This contains our built documentation
build,
# This contains builds that we don't want to check
Expand All @@ -42,6 +43,7 @@ exclude =
# example testing folder before going live
thinking
.idea
.bak
# custom scripts, not being part of the distribution
libs_external
modules
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ jobs:
run: |
python -m pip install --upgrade pip
if [ -f requirements-deploy.txt ]; then pip install -r requirements-deploy.txt; fi
- name: Execute tests
run: |
docker build --tag micropython-test --file Dockerfile.tests .
- name: Run Client/Host TCP example
run: |
docker compose up --build --exit-code-from micropython-host
- name: Run Client/Host TCP test
run: |
docker compose -f docker-compose-tcp-test.yaml up --build --exit-code-from micropython-host
- name: Build package
run: |
changelog2version \
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.DS_Store
.DS_Store?
pymakr.conf
tests/
config/config*.py
thinking/
*.bin
Expand Down
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "modules"]
path = modules
url = [email protected]:brainelectronics/python-modules.git
# changed to https due to RTD build issue
# see https://github.com/readthedocs/readthedocs.org/issues/4043
# url = [email protected]:brainelectronics/python-modules.git
url = https://github.com/brainelectronics/python-modules.git
20 changes: 20 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.9"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt
16 changes: 16 additions & 0 deletions Dockerfile.client
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build image
# $ docker build -t micropython-client -f Dockerfile.client .
#
# Run image
# $ docker run -it --rm --name micropython-client micropython-client

FROM micropython/unix:v1.18

# use "volumes" in docker-compose file to remove need of rebuilding
# COPY ./ /home
# COPY umodbus /root/.micropython/lib/umodbus

RUN micropython-dev -m upip install micropython-ulogging
RUN micropython-dev -m upip install micropython-urequests

CMD [ "micropython-dev", "-m", "examples/tcp_client_example.py" ]
16 changes: 16 additions & 0 deletions Dockerfile.host
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build image
# $ docker build -t micropython-host -f Dockerfile.host .
#
# Run image
# $ docker run -it --rm --name micropython-host micropython-host

FROM micropython/unix:v1.18

# use "volumes" in docker-compose file to remove need of rebuilding
# COPY ./ /home
# COPY umodbus /root/.micropython/lib/umodbus

RUN micropython-dev -m upip install micropython-ulogging
RUN micropython-dev -m upip install micropython-urequests

CMD [ "micropython-dev", "-m", "examples/tcp_host_example.py" ]
16 changes: 16 additions & 0 deletions Dockerfile.test_tcp_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build image
# $ docker build -t micropython-tcp-example -f Dockerfile.test_tcp_example .
# if a command fails, it will exit with non-zero code
#
# Run image, only possible if all tests passed
# $ docker run -it --rm --name micropython-tcp-example micropython-tcp-example

FROM micropython/unix:v1.18

# use "volumes" in docker-compose file to remove need of rebuilding
# COPY ./ /home
# COPY umodbus /root/.micropython/lib/umodbus
# COPY mpy_unittest.py /root/.micropython/lib/mpy_unittest.py

RUN micropython-dev -m upip install micropython-ulogging
RUN micropython-dev -m upip install micropython-urequests
20 changes: 20 additions & 0 deletions Dockerfile.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Build image
# $ docker build -t micropython-test -f Dockerfile.tests .
# if a unittest fails, it will exit with non-zero code
#
# Run image, only possible if all tests passed
# $ docker run -it --rm --name micropython-test micropython-test

FROM micropython/unix:v1.18

COPY ./ /home
# keep examples and tests registers JSON file easily in sync
COPY registers/example.json /home/tests/test-registers.json
COPY umodbus /root/.micropython/lib/umodbus
COPY mpy_unittest.py /root/.micropython/lib/mpy_unittest.py

RUN micropython-dev -m upip install micropython-ulogging
RUN micropython-dev -m upip install micropython-urequests
RUN micropython-dev -c "import mpy_unittest as unittest; unittest.main('tests')"

ENTRYPOINT ["/bin/bash"]
Loading

0 comments on commit eee18c2

Please sign in to comment.