Skip to content

Commit

Permalink
Tests fixes (#46)
Browse files Browse the repository at this point in the history
* Fixed tests: KiCad template path was missing a directory and `results.tgz` containing search results was uncompressed to wrong directory
* Simplified build process
* Drop Python 3.6 official support (it's getting old!)
  • Loading branch information
eeintech authored Jul 14, 2021
1 parent 68e7b4f commit 7c229b1
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 72 deletions.
11 changes: 4 additions & 7 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
omit =
# Do not run coverage on virtual environment files
env-kintree/*
/home/travis/virtualenv/*
# Do not run coverage on submodules
database/inventree-python/*
search/digikey_api/digikey/*
.venv/*
# Skip KiCad library tool
kicad/schlib.py
kintree/kicad/schlib.py
# Skip UI coverage
kintree_gui.py
common/progress.py
kintree/kintree_gui.py
kintree/common/progress.py
# Skip wrapt_timeout_decorator
kintree/wrapt_timeout_decorator/*
10 changes: 8 additions & 2 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Style Checks

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
style:
Expand All @@ -9,7 +15,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
python-version: [3.6, 3.9]
python-version: [3.7, 3.9]

steps:
- name: Checkout code
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Ki-nTree Tests

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
tests:
Expand All @@ -16,7 +22,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
python-version: [3.6, 3.9]
python-version: [3.7, 3.9]

steps:
- name: Checkout code
Expand Down Expand Up @@ -61,8 +67,9 @@ jobs:
invoke build
- name: Push Digi-Key Token
run: |
cp ~/.config/kintree/cache/token_storage.json digikey-token/
cd digikey-token
cd digikey-token/
git pull
cp ~/.config/kintree/cache/token_storage.json .
git config --global user.email "kintree@github.actions"
git config --global user.name "Ki-nTree Github Actions"
git add -u
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ build/
*__pycache__*
*.bck
# Test files
tests/TEST.*
kintree/tests/*
.coverage
htmlcov/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### Fast part creation in [KiCad](https://kicad-pcb.org/) and [InvenTree](https://inventree.github.io/)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
![Python Versions](images/python_versions.svg)
[![Build Status](https://travis-ci.com/sparkmicro/Ki-nTree.svg?branch=master)](https://travis-ci.com/sparkmicro/Ki-nTree)
[![Build Status](https://github.com/sparkmicro/Ki-nTree/actions/workflows/tests.yaml/badge.svg)](https://github.com/sparkmicro/Ki-nTree/actions)
[![Coverage Status](https://coveralls.io/repos/github/sparkmicro/Ki-nTree/badge.svg?branch=master&service=github)](https://coveralls.io/github/sparkmicro/Ki-nTree?branch=master)

## Demo Videos :fast_forward: [Full Demo](https://youtu.be/haSAu926BOI) :fast_forward: [KiCad Demo](https://youtu.be/NSMfCCD0uVw)
Expand Down
2 changes: 1 addition & 1 deletion images/python_versions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion kintree/config/kicad/kicad.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KICAD_SYMBOLS_PATH: ''
KICAD_TEMPLATES_PATH: kicad/templates/
KICAD_TEMPLATES_PATH: kintree/kicad/templates/
KICAD_FOOTPRINTS_PATH: ''
KICAD_ENABLE: true
2 changes: 1 addition & 1 deletion kintree/config/version.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MAJOR_REVISION: 0
MINOR_REVISION: 3
# Digit means stable version
RELEASE_STATE: 6
RELEASE_STATE: 10
4 changes: 4 additions & 0 deletions kintree_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from kintree import kintree_gui

if __name__ == '__main__':
kintree_gui.main()
4 changes: 4 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ def check_result(status: str, new_part: bool) -> bool:
else:
cprint('[ FAIL ]')
exit_code = -1
if ENABLE_KICAD:
cprint(f'[DBUG]\tkicad_result = {kicad_result}')
cprint(f'[DBUG]\tkicad_new_part = {kicad_new_part}')
if ENABLE_INVENTREE:
cprint(f'[DBUG]\tinventree_result = {inventree_result}')
cprint(f'[DBUG]\tnew_part = {new_part}')
cprint(f'[DBUG]\tpart_pk = {part_pk}')

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ignore =
E501, E722,
# - C901 - function is too complex
C901,
# - N802 - function name should be lowercase (In the future, we should conform to this!)
# - N802 - function name should be lowercase
N802,
# - N806 - variable should be lowercase
N806,
Expand Down
77 changes: 24 additions & 53 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,64 +28,39 @@ def install(c, is_install=True):

@task
def update(c):
"""
Update Ki-nTree dependencies
"""

install(c, is_install=False)


@task
def clean(c):
"""
Clean project folder
"""

cprint('[MAIN]\tCleaning project directory')
c.run('find . -name __pycache__ | xargs rm -r')
try:
c.run('rm .coverage', hide='err')
c.run('find . -name __pycache__ | xargs rm -r', hide='err')
except UnexpectedExit:
pass
try:
c.run('rm .coverage.*', hide='err')
c.run('rm .coverage', hide='err')
except UnexpectedExit:
pass
try:
c.run('rm -r dist build htmlcov', hide='err')
except UnexpectedExit:
pass


@task
def package(c):
import os
import shutil

cdir = os.getcwd()
dist = os.path.join(cdir, 'dist')

cprint('[MAIN]\tPackaging Ki-nTree')

# Delete previous files
try:
c.run('rm dist/kintree.tgz', hide='err')
c.run('rm .coverage.*', hide='err')
except UnexpectedExit:
pass
try:
c.run('rm dist/kintree.zip', hide='err')
c.run('rm -r dist/ build/ htmlcov', hide='err')
except UnexpectedExit:
pass


# Create ZIP
shutil.make_archive(os.path.join(cdir, 'kintree'), 'zip', dist)
# Create TGZ
c.run(f'cd {dist} && tar -czvf kintree.tgz * && cd {cdir}', hide=True)
# Move ZIP file into dist folder
c.run(f'mv kintree.zip {dist}', hide=False)


@task
def exec(c):
cprint('[MAIN]\tBuilding Ki-nTree into "dist" directory')
c.run('pyinstaller --clean --onefile '
'-p search/digikey_api/ -p kicad/ -p database/inventree-python/ '
'kintree_gui.py', hide=True)


@task(pre=[clean], post=[package])
@task(pre=[clean])
def build(c):
"""
Build Ki-nTree into executable file
Expand All @@ -98,7 +73,9 @@ def build(c):

# Uninstall typing
c.run('pip uninstall typing -y', hide=True)
exec(c)

cprint('[MAIN]\tBuilding Ki-nTree GUI into "dist" directory')
c.run('pyinstaller --clean --onefile -p kintree/kicad kintree_gui.py', hide=True)


@task
Expand All @@ -112,24 +89,17 @@ def setup_inventree(c):

@task
def coverage_report(c, open_browser=True):
"""
Show coverage report
"""

cprint('[MAIN]\tBuilding coverage report')
c.run('coverage report')
c.run('coverage html')
if open_browser:
webbrowser.open('htmlcov/index.html', new=2)


@task
def refresh_api_token(c):
from search.digikey_api import test_digikey_api_connect
test_digikey_api_connect()


@task
def save_api_token(c):
c.run('cp search/token_storage.json tests/files/', hide=True)


@task
def test(c, setup=True):
"""
Expand Down Expand Up @@ -168,7 +138,7 @@ def make_python_badge(c):
cprint('[MAIN]\tInstall pybadges')
c.run('pip install pybadges pip-autoremove', hide=True)
cprint('[MAIN]\tCreate badge')
c.run('python -m pybadges --left-text="Python" --right-text="3.6 - 3.9" '
c.run('python -m pybadges --left-text="Python" --right-text="3.7 - 3.9" '
'--whole-link="https://www.python.org/" --browser --embed-logo '
'--logo="https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/python.svg"')
cprint('[MAIN]\tUninstall pybadges')
Expand All @@ -184,4 +154,5 @@ def style(c):

c.run('pip install -U flake8', hide=True)
print("Running PEP style checks...")
c.run('flake8 tasks.py kintree_gui.py run_tests.py setup_inventree.py common/ config/ database/ kicad/*.py search/*.py')
c.run('flake8 tasks.py run_tests.py kintree_gui.py kintree/kintree_gui.py kintree/setup_inventree.py \
kintree/common/ kintree/config/ kintree/database/ kintree/kicad/*.py kintree/search/*.py')
Binary file modified tests/files/inventree_default_db.sqlite3
Binary file not shown.
Binary file modified tests/files/results.tgz
Binary file not shown.

0 comments on commit 7c229b1

Please sign in to comment.