Skip to content

Commit 9c08282

Browse files
authored
Bugfix/sw 1427 fix mr beam plugin unit tests (mrbeam#1520)
* Fix test_camera * Fix and/or comment test_undistort + corners.py * Fix migrations test file names * Fix test_settings * Comment out gcodegenerator: no tests are valid * Halfway fix the frontend tests * Create requirements.txt for tests virtualenv * Update README with unit test information * Disable frontend tests * Add missing test files * Restore requirements.txt * Change relative imports to absolute imports * Change relative to absolute imports * Change missing commits
1 parent 7cc3ddd commit 9c08282

32 files changed

+96
-101
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ docker run --name mrbeam-plugin -d -p5002:5000 mrbeam_plugin
3030
Access from the browser:
3131

3232
http://localhost:5002
33+
34+
35+
## Running unit tests
36+
Create a Python 2 virtual environment and activate it:
37+
```shell
38+
virtualenv -p /usr/bin/python2.7 tests_req
39+
```
40+
41+
Run the unit tests directly from **Pycharm** or from the command line:
42+
```shell
43+
python -m pytest paht/to/MrBeamPlugin/tests/
44+
```

octoprint_mrbeam/camera/corners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def get_deltas_and_refs(
170170
"""
171171
pic_settings = get_corner_calibration(settings)
172172
if pic_settings is None:
173-
return None
173+
return None, None, None
174174

175175
# Values taken from the calibration file. Used as a reference to warp the image correctly.
176176
# Legacy devices only have the values for the lensCorrected position.

test-requirements.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Install this in a Python2 virtualenv to run the tests
2+
# Tests can be run by: python -m pytest paht/to/MrBeamPlugin/tests/
3+
4+
# The tags can be changed here (after @):
5+
git+https://github.com/mrbeam/[email protected]#egg=MrBeamDoc
6+
git+https://github.com/mrbeam/[email protected]#egg=OctoPrint
7+
8+
mock==3.0.5
9+
numpy==1.16.6
10+
opencv-python==4.2.0.32
11+
Pillow==6.2.2
12+
pytest==4.6.11
13+
pytest-datafiles==2.0
14+
requests-mock==1.9.3
15+
selenium==3.141.0
16+
webdriver-manager==2.4.0
17+

tests/camera/test_camera.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/usr/bin/env python
22
import pytest
33
import time
4-
from os.path import dirname, basename, join, split, realpath
4+
from os.path import dirname, join, realpath
55

66
from octoprint_mrbeam.camera.exc import MrbCameraError
7-
from octoprint_mrbeam.camera.mrbcamera import mrbCamera, MrbCamera
7+
from octoprint_mrbeam.camera.mrbcamera import MrbCamera
88
from octoprint_mrbeam.camera.worker import MrbPicWorker
99
from octoprint.settings import settings
10-
from testutils.fetch_resource import fetch
10+
from tests.testutils.fetch_resource import fetch
1111

1212
sett = settings(init=True) # fix some init bug
1313
path = dirname(realpath(__file__))
14-
CAM_DIR = join(path, "rsc", "camera")
14+
CAM_DIR = join(path, "..", "rsc", "camera")
1515

1616
RESOURCES = [join(CAM_DIR, "raw.jpg")]
1717
fetch(RESOURCES)

tests/camera/test_undistort.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/usr/bin/env python3
2-
3-
from os.path import dirname, basename, join, split, realpath
4-
5-
# from collections import NoneType
6-
7-
path = dirname(realpath(__file__))
8-
CAM_DIR = join(path, "rsc", "camera")
2+
from os.path import dirname, join, realpath
93

104
import pytest
115
import logging
126
import cv2
137
import numpy as np
148
from octoprint_mrbeam.camera.undistort import prepareImage
9+
from octoprint_mrbeam.camera.lens import BoardDetectorDaemon
10+
import octoprint_mrbeam.camera.lens as lens
11+
import time
12+
13+
14+
path = dirname(realpath(__file__))
15+
CAM_DIR = join(path, "..", "rsc", "camera")
1516

1617

1718
@pytest.mark.datafiles(
@@ -42,25 +43,16 @@ def test_undist(datafiles):
4243
assert res[5]["lens_corrected"]
4344

4445

45-
from octoprint_mrbeam.camera.lens import BoardDetectorDaemon
46-
import octoprint_mrbeam.camera.lens as lens
47-
import yaml, time
48-
4946
BOARD_IMGS = tuple("tmp_raw_img_0%02i.jpg" % i for i in range(21, 31))
5047

48+
5149
BOARDS = pytest.mark.datafiles(
5250
join(CAM_DIR, "boards", "tmp_raw_img_021.jpg"),
53-
join(CAM_DIR, "boards", "tmp_raw_img_021.jpg.npz"),
5451
join(CAM_DIR, "boards", "tmp_raw_img_022.jpg"),
55-
join(CAM_DIR, "boards", "tmp_raw_img_022.jpg.npz"),
5652
join(CAM_DIR, "boards", "tmp_raw_img_023.jpg"),
5753
join(CAM_DIR, "boards", "tmp_raw_img_024.jpg"),
5854
join(CAM_DIR, "boards", "tmp_raw_img_025.jpg"),
5955
join(CAM_DIR, "boards", "tmp_raw_img_026.jpg"),
60-
join(CAM_DIR, "boards", "tmp_raw_img_027.jpg"),
61-
join(CAM_DIR, "boards", "tmp_raw_img_028.jpg"),
62-
join(CAM_DIR, "boards", "tmp_raw_img_029.jpg"),
63-
join(CAM_DIR, "boards", "tmp_raw_img_030.jpg"),
6456
)
6557

6658

@@ -127,7 +119,7 @@ def test_lens_calibration_abort(datafiles):
127119
# logging.error(timeout_msg)
128120
# raise
129121
logging.info(
130-
"Joined the lens calibratior stuff - ret %s, is_alive %s", ret, b.is_alive()
122+
"Joined the lens calibratior stuff - ret, is_alive %s", b.is_alive()
131123
)
132124

133125

tests/frontend/chromedriver

11.7 MB
Binary file not shown.

tests/frontend/critical_designs/base_procedure.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import time
2-
import logging
1+
import unittest
32

43
from selenium.webdriver.common.by import By
54
from selenium.webdriver.support.ui import WebDriverWait
65
from selenium.webdriver.support import expected_conditions as EC
76

8-
from frontend import uiUtils
9-
from frontend import webdriverUtils
10-
from frontend import gcodeUtils
11-
from frontend import frontendTestUtils
7+
from tests.frontend import webdriverUtils, gcodeUtils, frontendTestUtils, uiUtils
128

139

14-
class BaseProcedure:
10+
@unittest.skip('DEPRECATED')
11+
class BaseProcedure(unittest.TestCase):
1512
def setup_method(self, method):
1613

1714
# expectations (None means skip)

tests/frontend/critical_designs/test_elements_without_id.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
2-
from frontend import webdriverUtils
3-
from frontend.critical_designs.base_procedure import BaseProcedure
2+
from tests.frontend import webdriverUtils
3+
from tests.frontend.critical_designs.base_procedure import BaseProcedure
44

55

66
class TestElementsWithoutId(BaseProcedure):

tests/frontend/critical_designs/test_fillings_in_defs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
2-
from frontend import webdriverUtils
3-
from frontend.critical_designs.base_procedure import BaseProcedure
2+
from tests.frontend import webdriverUtils
3+
from tests.frontend.critical_designs.base_procedure import BaseProcedure
44

55

66
class TestFillingsInDefs(BaseProcedure):

tests/frontend/critical_designs/test_namespace_references_to_ENTITYs_outside_the_xml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
2-
from frontend import webdriverUtils
3-
from frontend.critical_designs.base_procedure import BaseProcedure
2+
from tests.frontend import webdriverUtils
3+
from tests.frontend.critical_designs.base_procedure import BaseProcedure
44

55

66
class TestNamespaceReferencesToEntitysOutsideTheXML(BaseProcedure):

0 commit comments

Comments
 (0)