From aadbf26eb175034cbd20e621d0cdccb7f71cd170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20S=C3=A1nchez=20de=20Le=C3=B3n=20Peque?= Date: Thu, 12 Dec 2019 20:04:38 +0100 Subject: [PATCH 1/4] Remove unused requirements files --- requirements-dev.txt | 3 --- requirements.txt | 0 2 files changed, 3 deletions(-) delete mode 100644 requirements-dev.txt delete mode 100644 requirements.txt diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 872a66d2..00000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,3 +0,0 @@ -sphinx-rtd-theme==0.1.9 -travis-sphinx==1.1.0 -Sphinx==1.3.1 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e69de29b..00000000 From 5069483aefea518ce8e467eb2c88e1d1ed8a4edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20S=C3=A1nchez=20de=20Le=C3=B3n=20Peque?= Date: Thu, 12 Dec 2019 19:51:08 +0100 Subject: [PATCH 2/4] Use pytest to run the test suite --- .travis.yml | 9 ++++---- appveyor.yml | 6 ++--- environment.yml | 7 ++---- runtests.py | 22 ------------------- setup.py | 11 ++++++++++ ...{TestCadObjects.py => test_cad_objects.py} | 0 tests/{TestCadQuery.py => test_cadquery.py} | 0 tests/{TestCQGI.py => test_cqgi.py} | 0 tests/{TestExporters.py => test_exporters.py} | 0 tests/{TestImporters.py => test_importers.py} | 0 tests/{TestJupyter.py => test_jupyter.py} | 0 .../{TestCQSelectors.py => test_selectors.py} | 0 .../{TestWorkplanes.py => test_workplanes.py} | 0 13 files changed, 20 insertions(+), 35 deletions(-) delete mode 100644 runtests.py rename tests/{TestCadObjects.py => test_cad_objects.py} (100%) rename tests/{TestCadQuery.py => test_cadquery.py} (100%) rename tests/{TestCQGI.py => test_cqgi.py} (100%) rename tests/{TestExporters.py => test_exporters.py} (100%) rename tests/{TestImporters.py => test_importers.py} (100%) rename tests/{TestJupyter.py => test_jupyter.py} (100%) rename tests/{TestCQSelectors.py => test_selectors.py} (100%) rename tests/{TestWorkplanes.py => test_workplanes.py} (100%) diff --git a/.travis.yml b/.travis.yml index c6a7ba09..2f963664 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,26 +51,25 @@ before_install: - hash -r; - conda config --set always_yes yes --set changeps1 no; - conda create -y -q -n test_cq -c cadquery -c conda-forge pythonocc-core=0.18.2 oce=0.18.2 python=$TRAVIS_PYTHON_VERSION - pyparsing mock; - source ~/miniconda/bin/activate test_cq; +- pip install .[dev] - python -c 'import OCC.gp as gp; print(gp.gp_Vec())' -- pip install codecov install: - python setup.py install before_script: -- ulimit -c unlimited -S +- ulimit -c unlimited -S - sudo rm -f /cores/core.* script: -- coverage run runtests.py +- pytest -v --cov after_success: - codecov after_failure: -- ls /cores/core.* +- ls /cores/core.* - lldb --core `ls /cores/core.*` --batch --one-line "bt" diff --git a/appveyor.yml b/appveyor.yml index 0f62ef51..6715e5b6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,14 +19,14 @@ install: - conda update -q conda - conda create --quiet --name cqtest -c cadquery -c conda-forge -c dlr-sc pythonocc-core=0.18.2 python=%PYTHON_VERSION% pyparsing mock coverage codecov - activate cqtest - - pip install codecov + - pip install .[dev] - python setup.py install build: false test_script: - - coverage run runtests.py - + - pytest -v --cov + on_success: - codecov diff --git a/environment.yml b/environment.yml index dfc98e17..924a4972 100644 --- a/environment.yml +++ b/environment.yml @@ -6,9 +6,6 @@ dependencies: - python=3.6 - pythonocc-core=0.18.2 - oce=0.18.2 - - pyparsing + - pip - pip: - - "--editable=." - # Documentation - - sphinx - - sphinx_rtd_theme + - "--editable=.[dev]" diff --git a/runtests.py b/runtests.py deleted file mode 100644 index f1052ca9..00000000 --- a/runtests.py +++ /dev/null @@ -1,22 +0,0 @@ -import sys -from tests import * -import cadquery -import unittest - -#if you are on python 2.7, you can use -m uniitest discover. -#but this is required for python 2.6.6 on windows. FreeCAD0.12 will not load -#on py 2.7.x on win -suite = unittest.TestSuite() - -suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCadObjects.TestCadObjects)) -suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCadQuery.TestCadQuery)) -suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCQGI.TestCQGI)) -suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCQSelectors.TestCQSelectors)) -suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestExporters.TestExporters)) -suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestImporters.TestImporters)) -suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestJupyter.TestJupyter)) -suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestWorkplanes.TestWorkplanes)) - -if __name__ == '__main__': - result = unittest.TextTestRunner().run(suite) - sys.exit(not result.wasSuccessful()) diff --git a/setup.py b/setup.py index 24d2a8e1..a2873e33 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,17 @@ setup( long_description=open('README.md').read(), packages=['cadquery','cadquery.contrib','cadquery.occ_impl','cadquery.plugins','tests'], install_requires=['pyparsing'], + extras_require={ + 'dev': [ + # Documentation + 'sphinx', + 'sphinx_rtd_theme', + # Testing + 'codecov', + 'pytest', + 'pytest-cov', + ], + }, include_package_data=True, zip_safe=False, platforms='any', diff --git a/tests/TestCadObjects.py b/tests/test_cad_objects.py similarity index 100% rename from tests/TestCadObjects.py rename to tests/test_cad_objects.py diff --git a/tests/TestCadQuery.py b/tests/test_cadquery.py similarity index 100% rename from tests/TestCadQuery.py rename to tests/test_cadquery.py diff --git a/tests/TestCQGI.py b/tests/test_cqgi.py similarity index 100% rename from tests/TestCQGI.py rename to tests/test_cqgi.py diff --git a/tests/TestExporters.py b/tests/test_exporters.py similarity index 100% rename from tests/TestExporters.py rename to tests/test_exporters.py diff --git a/tests/TestImporters.py b/tests/test_importers.py similarity index 100% rename from tests/TestImporters.py rename to tests/test_importers.py diff --git a/tests/TestJupyter.py b/tests/test_jupyter.py similarity index 100% rename from tests/TestJupyter.py rename to tests/test_jupyter.py diff --git a/tests/TestCQSelectors.py b/tests/test_selectors.py similarity index 100% rename from tests/TestCQSelectors.py rename to tests/test_selectors.py diff --git a/tests/TestWorkplanes.py b/tests/test_workplanes.py similarity index 100% rename from tests/TestWorkplanes.py rename to tests/test_workplanes.py From e9924ba6e4cb06f784e90c00eae0cc9c859d8190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20S=C3=A1nchez=20de=20Le=C3=B3n=20Peque?= Date: Thu, 12 Dec 2019 19:38:58 +0100 Subject: [PATCH 3/4] Fix plane rotation method The vector defining the rotation is expected to be in local coordinates and therefore needs to be converted to world coordinates before applying the rotation. --- cadquery/occ_impl/geom.py | 2 +- tests/test_cadquery.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cadquery/occ_impl/geom.py b/cadquery/occ_impl/geom.py index 0c31fe22..d959702a 100644 --- a/cadquery/occ_impl/geom.py +++ b/cadquery/occ_impl/geom.py @@ -619,7 +619,7 @@ class Plane(object): :param rotate: Vector [xDegrees, yDegrees, zDegrees] :return: a copy of this plane rotated as requested. """ - rotate = Vector(rotate) + rotate = Vector(self.toWorldCoords(rotate)) # Convert to radians. rotate = rotate.multiply(math.pi / 180.0) diff --git a/tests/test_cadquery.py b/tests/test_cadquery.py index ddd7cc45..64b85237 100644 --- a/tests/test_cadquery.py +++ b/tests/test_cadquery.py @@ -4,6 +4,9 @@ """ # system modules import math,os.path,time,tempfile +from random import choice +from random import random +from random import randrange # my modules from cadquery import * @@ -246,6 +249,32 @@ class TestCadQuery(BaseTest): self.assertEqual(-0.5, endPoint[1]) self.assertEqual(2.5, endPoint[2]) + def testPlaneRotateZNormal(self): + """ + Rotation of a plane in the Z direction should never alter its normal. + + This test creates random planes, with the normal in a random direction + among positive and negative X, Y and Z. The plane is defined with this + normal and another random perpendicular vector (the X-direction of the + plane). The plane is finally rotated a random angle in the Z-direction + to verify that the resulting plane maintains the same normal. + """ + for _ in range(100): + normal_sign = choice((-1, 1)) + normal_dir = randrange(3) + angle = (random() - 0.5) * 720 + + normal = [0, 0, 0] + normal[normal_dir] = normal_sign + xdir = [random(), random(), random()] + xdir[normal_dir] = 0 + + plane = Plane(origin=(0, 0, 0), xDir=xdir, normal=normal) + rotated = plane.rotated((0, 0, angle)).zDir.toTuple() + self.assertAlmostEqual(rotated[0], normal[0]) + self.assertAlmostEqual(rotated[1], normal[1]) + self.assertAlmostEqual(rotated[2], normal[2]) + def testLoft(self): """ Test making a lofted solid From e69b2f83bde43ad6a0159a72bc058165e684e72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Urba=C5=84czyk?= Date: Tue, 17 Dec 2019 18:28:22 +0100 Subject: [PATCH 4/4] Use pytest in azure as well (#239) * Use pytest in azure as well * Specify test requirements properly * Delete circle ci config --- .circleci/config.yml | 35 ----------------------------------- conda/meta.yaml | 5 +++-- 2 files changed, 3 insertions(+), 37 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 51ba9fad..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,35 +0,0 @@ -version: 2 - -jobs: - runtests: - - macos: - xcode: "9.0" - - environment: - PYTEST_QT_API: pyqt5 - PYTHON_VERSION: 3.6 - - steps: - - checkout - - run: HOMEBREW_NO_AUTO_UPDATE=1 brew install wget - - run: cd && rm -rf ~/.pyenv && rm -rf ~/virtualenvs - - run: wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh - - run: chmod +x ~/miniconda.sh && ~/miniconda.sh -b - - run: echo "export PATH=~/miniconda3/bin:$PATH" >> $BASH_ENV - - run: conda config --set always_yes yes - - run: conda create --quiet --name cqtest -c cadquery -c conda-forge -c dlr-sc pythonocc-core=0.18.2 oce=0.18.2 python=$PYTHON_VERSION pyparsing mock lldb - - run: | - source activate cqtest - pip install coverage - python setup.py install - conda env list - conda list - coverage run runtests.py - -workflows: - version: 2 - - workflow: - jobs: - - runtests \ No newline at end of file diff --git a/conda/meta.yaml b/conda/meta.yaml index 2fe8c171..ce663fda 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -20,11 +20,12 @@ requirements: - pyparsing 2.* test: + requires: + - pytest source_files: - - runtests.py - tests/ commands: - - python runtests.py + - pytest -v about: summary: CadQuery fork based on PythonOCC