Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printer refactor #80

Merged
merged 207 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
207 commits
Select commit Hold shift + click to select a range
fc84c78
v1 of boilerplate for printer classes
L10nhunter Oct 6, 2024
e7c6acd
v1.0.1 of boilerplate for printer classes
L10nhunter Oct 7, 2024
5e373bd
updated test.py
L10nhunter Oct 8, 2024
68043a3
updated test.py
L10nhunter Oct 8, 2024
8da6d89
FabricatorUML!
L10nhunter Oct 8, 2024
2605550
unmangled all the names, because it was making problems for the inher…
L10nhunter Oct 9, 2024
e090555
Delete QView3D Installer.exe
L10nhunter Oct 10, 2024
1774d0c
feat: clean install.sh and create install.bat for windows
iron768 Oct 10, 2024
6f284ab
fix: fix install scripts!
iron768 Oct 10, 2024
10b5300
feat: make scripts delete migrations folder
iron768 Oct 10, 2024
a73ae05
feat: add windows run script
iron768 Oct 10, 2024
c5f89a9
chore: cleanup server
iron768 Oct 10, 2024
4eab87f
fix: add mac files to gitignore
iron768 Oct 10, 2024
63f379a
updated install scripts to delete the hvamc.db
L10nhunter Oct 10, 2024
281579f
refactored a bunch of the methods to usesMarlinGcode.py, because then…
L10nhunter Oct 11, 2024
6a6f767
refactored a bunch of the methods to usesMarlinGcode.py, because then…
L10nhunter Oct 11, 2024
8502efa
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
L10nhunter Oct 11, 2024
a815b81
Device.uml added to git
L10nhunter Oct 14, 2024
6877ba0
test lvl 1 for nate
L10nhunter Oct 14, 2024
0f01a8c
added cnc and laser for future use
L10nhunter Oct 20, 2024
e6d97f8
added a verbose option for debugging
L10nhunter Oct 20, 2024
9e5825f
updated to work with db
L10nhunter Oct 20, 2024
43654f8
updates for new stuff.
L10nhunter Oct 21, 2024
9f38afb
actual proper tests!
L10nhunter Oct 28, 2024
1ab5893
added package-lock.json to the gitignore
L10nhunter Oct 29, 2024
8031183
feat: add very basic printer emulator
iron768 Oct 29, 2024
cc3a314
feat: easier to create emulated printer, testing setting extruder and…
iron768 Oct 29, 2024
9485c8b
my big push for all the updates to the refactor.
L10nhunter Oct 29, 2024
39cb447
PARALLEL TESTS ARE REAL!!! all tests run in parallel and each thread …
L10nhunter Oct 29, 2024
ed77991
feat: printer can now emulate gcode commands
iron768 Oct 30, 2024
6be0309
fix: M602 command
iron768 Oct 30, 2024
c852e8c
feat: add second option to quit command handler
iron768 Oct 30, 2024
5f14f51
expanded codes + reworked a bit
ndg8743 Oct 31, 2024
d75ffac
more codes + added back what i got rid of
ndg8743 Oct 31, 2024
547e223
more codes added
ndg8743 Oct 31, 2024
3f37722
fix: ignore gcode comments
iron768 Oct 31, 2024
621b960
feat: begin basic emulator and server communication
iron768 Nov 2, 2024
dc959f3
fix: deadlock issues with go socketio client
iron768 Nov 2, 2024
574cb0b
Logging completed for tests. now i need to integrate it into the norm…
L10nhunter Nov 5, 2024
b8eba35
Logging completed for normal use of fabricators.
L10nhunter Nov 6, 2024
a240aca
added new requirement to make tests skip if something they are depend…
L10nhunter Nov 7, 2024
0d9a72e
added more logging lines to keep track of what is happening.
L10nhunter Nov 7, 2024
3302330
test logging completed
L10nhunter Nov 7, 2024
12d5657
feat: switch to websockets and add emulator test server
iron768 Nov 8, 2024
934657a
test refactor to include dependencies.
L10nhunter Nov 8, 2024
84463a4
feat: improve emulator and emu test server
iron768 Nov 8, 2024
b113223
refactored old ports.py into new Ports.py
ndg8743 Nov 8, 2024
9dc23f0
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
ndg8743 Nov 8, 2024
4579332
fix: remove unneeded variable
iron768 Nov 8, 2024
dea6e85
fix: time formatting if tests are longer than a minute
L10nhunter Nov 8, 2024
52c24c8
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
L10nhunter Nov 8, 2024
0d9331e
fix: notes for Ports.py
L10nhunter Nov 8, 2024
86c45ca
feat: better logging for devices
L10nhunter Nov 8, 2024
4ba2396
feat: created vanilla gcode implementation for a future implementatio…
L10nhunter Nov 8, 2024
e7ac408
feat: moved stuff that was vanilla to there.
L10nhunter Nov 8, 2024
2c33855
fix: moved file, so imports needed to be changes
L10nhunter Nov 8, 2024
819d437
fix: optimized imports and added static method to commit db.
L10nhunter Nov 8, 2024
e897261
Correct issues with diagnose and repair/ remove deprecated stuff
ndg8743 Nov 9, 2024
6ddc921
fix: moved the routes for the ports to the controller file
L10nhunter Nov 10, 2024
1fe851a
fix: formatted time to finish tests correctly
L10nhunter Nov 11, 2024
c38fad4
fix: updated mk4s to 50% model so its actually comparable.
L10nhunter Nov 11, 2024
044fba8
fix: added os[Port] back in, so the repr methods could reference them.
L10nhunter Nov 11, 2024
e6aa209
fix: removed lots of extra spaces
L10nhunter Nov 11, 2024
7977f2c
feat: added support for multiple chars in the line seperator.
L10nhunter Nov 11, 2024
d5b1ca2
fix: print the whole stack trace on error
L10nhunter Nov 11, 2024
93dfbe6
feat: added checking to ensure that the gcode is able to print on the…
L10nhunter Nov 11, 2024
63ba79e
feat: added FabricatorStatusService.py to be removed once integrated …
L10nhunter Nov 11, 2024
bbc0a65
fix: removed LocationResponse.py because it was only used once.
L10nhunter Nov 11, 2024
d3e332c
fix: minor cleanup in the logger creation.
L10nhunter Nov 11, 2024
24e1122
feat: added the changeFilament and changeNozzle methods
L10nhunter Nov 11, 2024
1dcdb62
feat: added tests for the app config
L10nhunter Nov 11, 2024
badd6c8
fix: added new catches to make sure that the device has the right fil…
L10nhunter Nov 11, 2024
5cb7a00
fix: moved locationResponse to here, because it was the only place it…
L10nhunter Nov 11, 2024
f536a92
feat: better error handling and start to remove error handling in gco…
iron768 Nov 12, 2024
e4bd944
feat: allow user to choose between connection or command in cli
iron768 Nov 12, 2024
981b1c2
feat: more command alts
iron768 Nov 12, 2024
5bb7eda
feat: basic printer registry
iron768 Nov 12, 2024
15e0cfe
feat: finish load from config, allow user to specify which printer to…
iron768 Nov 12, 2024
29aec0b
feat: attributes, marlin and brands
iron768 Nov 12, 2024
e5ff1a5
feat: begin basic serial emulation
iron768 Nov 12, 2024
966bf7f
fix: make writeserial function properly send data over websockets
iron768 Nov 12, 2024
fa447c9
feat: basic setting control for printer emulator
iron768 Nov 12, 2024
af7afb8
feat: added prusaGcode and moved everything that was prusa specific t…
L10nhunter Nov 13, 2024
a66d603
fix: broke out cali-cube setup method
L10nhunter Nov 13, 2024
d32864b
fix: optimized imports
L10nhunter Nov 13, 2024
23ab304
fix: rewrote the pause test so it would fail if something failed, lik…
L10nhunter Nov 13, 2024
2670b60
fix: made logging for expected and measured time more accurate
L10nhunter Nov 13, 2024
4cb3843
fix: updated checks for base_url to be a valid input, not just 127.0.0.1
L10nhunter Nov 13, 2024
2ded9e6
fix: updated to use Prusa Gcode instead of Marlin
L10nhunter Nov 13, 2024
743b956
fix: updated to have proper logging and env setup.
L10nhunter Nov 13, 2024
524c750
fix: updated to have proper logging.
L10nhunter Nov 13, 2024
3d2ef0e
fix: updated to have proper logging.
L10nhunter Nov 13, 2024
c0dd71f
fix: updated to wait during setup, in the case of ender hard crashing…
L10nhunter Nov 13, 2024
fb035b1
fix: updated to return errors if they occur and to log properly
L10nhunter Nov 13, 2024
64cb15b
feat: updated to use concurrent.futures instead of threading, nad cha…
L10nhunter Nov 13, 2024
ba3b274
fix: removed home so it actually pauses in the test, and added settin…
L10nhunter Nov 13, 2024
5242b80
feat: updated to use proper constructor, and to log properly.
L10nhunter Nov 13, 2024
b156c0b
feat: added built-in method for logging exceptions
L10nhunter Nov 13, 2024
bd099d2
fix: fixed formatting
L10nhunter Nov 13, 2024
af339da
fix: changed the job import to pull from the updated version
L10nhunter Nov 13, 2024
2967a9a
feat: added more lines to avoid adding the logs to the git.
L10nhunter Nov 13, 2024
9346055
fix: on error, should return false
L10nhunter Nov 14, 2024
04dcf87
fix: formatted time better
L10nhunter Nov 14, 2024
f8e8d5b
fix: removed arbitrary limit on stuff to add to settingsDict.
L10nhunter Nov 14, 2024
d87036b
fix: made logging errors work properly
L10nhunter Nov 14, 2024
7e03d0d
fix: fully removed threading in favor of concurrent.futures
L10nhunter Nov 14, 2024
c3dbe62
feat: added all the things MK3 needed to function, now that its working.
L10nhunter Nov 14, 2024
fbc8b90
fix: changed model to one word for easier parsing
L10nhunter Nov 14, 2024
c5b1f62
feat: added verbosity to begin, so logging is easier.
L10nhunter Nov 14, 2024
b799be3
feat: optimized code and imports for gcode
L10nhunter Nov 14, 2024
ba740c3
feat: added new logging options
L10nhunter Nov 14, 2024
eae6163
feat: add the ability to add attributes and data to the printer from …
iron768 Nov 14, 2024
cb05425
fix: add start temp
iron768 Nov 14, 2024
48bc7df
fix: undo the deletion?
L10nhunter Nov 14, 2024
546aec3
fix: log captured output
L10nhunter Nov 15, 2024
2f2e8a9
feat: added verbose debug logging
L10nhunter Nov 15, 2024
df5c0c2
feat: optimized response codes and added tracing back everything.
L10nhunter Nov 15, 2024
3d5c6b6
fix: overrode set level
L10nhunter Nov 15, 2024
0a9a13f
feat: updated to run all tests
L10nhunter Nov 15, 2024
1ee9f8f
feat: fixed update loop.
L10nhunter Nov 15, 2024
23661de
fix: optimized class
L10nhunter Nov 15, 2024
3059609
fix: optimized class
L10nhunter Nov 15, 2024
1812699
fix: bad line fixed
L10nhunter Nov 15, 2024
71334df
fix: optimized gcode classes.
L10nhunter Nov 15, 2024
51abd87
feat: external tests to pytests.
L10nhunter Nov 15, 2024
a6c69fd
feat: disable socketIO until its integrated
L10nhunter Nov 15, 2024
1882526
dep: to be removed.
L10nhunter Nov 15, 2024
57929e1
Refactor FabricatorStatusService.py into FabricatorList.py + other ed…
ndg8743 Nov 16, 2024
deff174
fix: update exp go library
iron768 Nov 18, 2024
bd92512
feat: updated tests for integration with FabricatorList
L10nhunter Nov 21, 2024
ac4b547
fix: use abs path for config file loading so server and tests are bot…
L10nhunter Nov 21, 2024
51eb52b
fix: added logging for fixture errors
L10nhunter Nov 21, 2024
06eb85a
fix: added important locations to path for calling, and added catches…
L10nhunter Nov 21, 2024
0a45956
fix: fixed logging
L10nhunter Nov 21, 2024
00e000f
fix: changed queue to extend deque instead of just having one
L10nhunter Nov 21, 2024
2390e37
fix: removed old reqs
L10nhunter Nov 21, 2024
8818ff0
fix: removed all calls to printer status service
L10nhunter Nov 21, 2024
6a716f6
fix: removed test for console logger, since that isn't guaranteed
L10nhunter Nov 21, 2024
d729c02
feat: reworked FabricatorList to no longer be static, and to be testa…
L10nhunter Nov 21, 2024
a45cbdd
feat: updated to use custom logging with built-in terminal writers
L10nhunter Nov 21, 2024
d0305ef
feat: updated app to use new features in other places
L10nhunter Nov 21, 2024
f3b33f2
fix routes
ndg8743 Nov 24, 2024
0794e7e
fixed and added gcode commands
ndg8743 Nov 25, 2024
a17ca33
feat: worked on frontend integration. (WIP)
L10nhunter Nov 29, 2024
f6bf16b
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
L10nhunter Nov 29, 2024
1eeb830
feat: more tests. (WIP)
L10nhunter Nov 29, 2024
2e9f7a6
feat: integration (WIP)
L10nhunter Dec 1, 2024
6924285
fix: create log folder if it doesnt exist
L10nhunter Dec 1, 2024
e06fd44
fix: fix bad RegisterModal.vue
L10nhunter Dec 1, 2024
c7ca79d
Merge branch 'printer-refactor' into printeremulator
iron768 Dec 1, 2024
a3da6ac
Merge pull request #79 from sunyhydralab/printeremulator
iron768 Dec 1, 2024
57ef70a
feat: basic serial and socket connection for fabricators
L10nhunter Dec 1, 2024
26c7d9c
feat: expand fabricator connection to add functions and properties ne…
iron768 Dec 1, 2024
9f24e4d
feat: sockets cleanup and live gcode render socket
L10nhunter Dec 2, 2024
3a9c144
feat: sockets cleanup and live gcode render socket
L10nhunter Dec 2, 2024
3c54d34
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
L10nhunter Dec 2, 2024
204606a
feat: beginning of emulator backend connection
iron768 Dec 2, 2024
842b612
Merge branch 'printer-refactor' of https://github.com/sunyhydralab/QV…
iron768 Dec 2, 2024
c4ae83c
feat: mess around with emulator from front end
iron768 Dec 2, 2024
bc5b2f2
feat: enable renderTravel/also attempt to interrupt
ndg8743 Dec 2, 2024
2d82a0d
feat: PRINTING IS WORKING!!!!
L10nhunter Dec 2, 2024
af9bf27
fix: live rendering works!
ndg8743 Dec 2, 2024
2c33c42
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
ndg8743 Dec 2, 2024
a4b5ccd
feat: finish basic web control panel for emulator
iron768 Dec 2, 2024
ac27209
fix: register printers works
L10nhunter Dec 2, 2024
12cec6f
feat: add fake serial port to emulator
iron768 Dec 2, 2024
10a789b
feat: clean up old websocket server and add event emitter
iron768 Dec 2, 2024
4fb8772
feat: allow start up command to chose printer and connection type
iron768 Dec 3, 2024
8f98c26
fix: home printer works
L10nhunter Dec 3, 2024
3017e27
fix: diagnose and repair ports works
L10nhunter Dec 3, 2024
2dd3866
feat: current app and app custom implementation
L10nhunter Dec 4, 2024
4a3dbd4
feat: websocket integration done
L10nhunter Dec 4, 2024
e91b586
fix: improve emulator connection
iron768 Dec 4, 2024
93156ff
fix: emu gcode commands
ndg8743 Dec 4, 2024
8318997
fix: create emulator even if in list
L10nhunter Dec 4, 2024
137697a
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
L10nhunter Dec 4, 2024
353aae7
fix: MainView errors
ndg8743 Dec 4, 2024
d937d18
fix: break some stuff and fix it, why did we make our own flask again?
ndg8743 Dec 4, 2024
bca4249
fix: break some stuff and fix it, why did we make our own flask again?
ndg8743 Dec 4, 2024
2b7d588
fix: api for emulator
iron768 Dec 4, 2024
f48d153
fix: fix broken serial for mac and possibly linux
iron768 Dec 4, 2024
02e707a
fix: check that logger exists.
L10nhunter Dec 4, 2024
707d2d9
fix: undo the breaking of MainView.vue
L10nhunter Dec 4, 2024
3a48a91
fix: make flask db init work again.
L10nhunter Dec 4, 2024
9051f86
fix: go directory pathing
iron768 Dec 5, 2024
bd88fe8
feat: allow user to quit in printer id ask
iron768 Dec 5, 2024
1e4d61e
feat: work on M155 and begin to make it handle updates better
iron768 Dec 5, 2024
94d8cc6
fix: finish properly handle M155
iron768 Dec 5, 2024
4e5ab59
fix: handle first ok properly for auto temp
iron768 Dec 5, 2024
cf34655
fix: auto temp sends actual values
iron768 Dec 5, 2024
779419b
fix: remove weird printer response for M155
iron768 Dec 5, 2024
5a2bc6b
fix: assorted command print fixes
iron768 Dec 5, 2024
49a4c53
fix: working home pos command G28
iron768 Dec 5, 2024
285a64c
fix: push wip
L10nhunter Dec 8, 2024
20f5ffa
fix/feat: multiline responses for emulator
iron768 Dec 9, 2024
fc8e6df
fix: m155 remove old ok responses
iron768 Dec 9, 2024
bad2af7
fix: temp make port always EMU0
iron768 Dec 9, 2024
dc94e19
feat: documentation! get your docstrings here! All backend python fil…
L10nhunter Dec 11, 2024
dccbccd
fix: general formatting and debugging cleanup
L10nhunter Dec 11, 2024
9ac6e82
fix: general formatting and debugging cleanup
L10nhunter Dec 11, 2024
2f7b927
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
L10nhunter Dec 11, 2024
95af6ac
feat: live real-time render of gcode. still needs lots of work.
L10nhunter Dec 12, 2024
d7303d9
fix: temp values to see if emulator will work properly with backend
iron768 Dec 12, 2024
404d91d
fix: time and eta updating
L10nhunter Dec 16, 2024
3235bb0
Merge remote-tracking branch 'origin/printer-refactor' into printer-r…
L10nhunter Dec 16, 2024
ca6c741
fix: f string issue
iron768 Dec 16, 2024
41dde95
Merge branch 'development' into printer-refactor
ndg8743 Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.vscode

.DS_Store

*.pyc
__pycache__/
Expand All @@ -9,4 +9,13 @@ migrations/
*.db

server/qview3dserver.egg-info/
server/dist
server/dist

printeremu/testserver/node_modules/

.DS_Store
/qodana.yaml
/Tests/logs/
/Tests/server/
/logs/
/server/logs/
365 changes: 365 additions & 0 deletions Tests/conftest.py

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions Tests/parallel_test_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import sys
import re
import subprocess
import platform

# Add test root to sys.path if needed
from globals import root_path
if root_path not in sys.path:
sys.path.append(root_path)
serverpath = os.path.join(root_path, "server")
if serverpath not in sys.path:
sys.path.append(serverpath)
testpath = os.path.join(root_path, "Tests")
if testpath not in sys.path:
sys.path.append(testpath)

from server.Classes.Ports import Ports

PORTS = []
# List of available ports for testing
if platform.system() == "Windows":
import winreg
path = "HARDWARE\\DEVICEMAP\\SERIALCOMM"
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
for i in range(256):
try:
val = winreg.EnumValue(key, i)
if re.match(r"COM\d+|LPT\d+", val[1]):
PORTS.append(val[1])
except OSError:
break
except FileNotFoundError:
pass
elif platform.system() == "Darwin":
import glob
PORTS = glob.glob("/dev/tty.*")
else:
import glob
PORTS = glob.glob("/dev/tty[A-Za-z]*")



# Function to run pytest for a specific port
testLevel = 10
verbosity = 2
runFlags = 0b010 # 0b001: -s, 0b010: -vvv or -p no:terminal, 0b100: debug or info

def run_tests_for_port(comm_port):
env = os.environ.copy()
env["PORT"] = comm_port
args = ["pytest", testpath, f"--myVerbose={verbosity}", f"--port={comm_port}"]
if runFlags & 0b1: args.append("-s")
args.append("-vv") if runFlags & 0b10 else args.append("-p no:terminal")
env["LEVEL"] = "DEBUG" if runFlags & 0b100 else "INFO"
subprocess.Popen(args, env=env).wait()

if __name__ == "__main__":
from concurrent.futures import ThreadPoolExecutor, as_completed
if len(PORTS) != 0:
with ThreadPoolExecutor(max_workers=len(PORTS)) as executor:
futures = [executor.submit(run_tests_for_port, port) for port in PORTS if
Ports.getPortByName(port) is not None]
for future in as_completed(futures):
try:
future.result()
except Exception as e:
from globals import current_app
current_app.handle_errors_and_logging(e)
146 changes: 146 additions & 0 deletions Tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import os
import re
import pytest
from Classes.Logger import Logger
from parallel_test_runner import testLevel

def __desc__(): return "App Tests"

@pytest.mark.dependency()
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_db_to_make_sure_it_has_valid_file_path(app):
db_file_no_path = app.config["SQLALCHEMY_DATABASE_URI"].split("/")[-1].split("\\")[-1]
assert db_file_no_path, "database_uri doesn't exist?"
assert db_file_no_path == "hvamc.db", f"database_uri is {db_file_no_path}"
assert os.path.exists(app.config["SQLALCHEMY_DATABASE_URI"].split("sqlite:///")[
-1]), f"Database file {app.config["SQLALCHEMY_DATABASE_URI"].split("sqlite:///")[-1]} does not exist"


@pytest.mark.dependency(depends=["test_db_to_make_sure_it_has_valid_file_path"])
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_base_url_for_http_responses_has_valid_format(app):
assert app.config["base_url"], "base_url doesnt exist?"
assert re.match(r"http://\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}$", app.config["base_url"]) or re.match(
r"http://localhost:\d{1,5}$", app.config["base_url"]), f"base_url is {app.config['base_url']}"


@pytest.mark.dependency(depends=["test_base_url_for_http_responses_has_valid_format"])
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_environment_for_development(app):
assert app.config["environment"], "environment doesnt exist?"
assert app.config["environment"] == "development", f"environment is {app.config['environment']}"


@pytest.mark.dependency(depends=["test_environment_for_development"])
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_logger_is_custom_implementation_and_exists(app):
assert app.logger, "myLogger doesnt exist?"
assert app.logger.name, "name doesnt exist?"
assert str(app.logger.name) == "Logger_App", f"myLogger is {str(app.logger.name)}"
assert isinstance(app.logger, Logger), "myLogger is not an instance of Logger?"
assert app.logger.fileLogger, "fileLogger doesnt exist?"


@pytest.mark.dependency(depends=["test_logger_is_custom_implementation_and_exists"])
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_socketio_exists_and_works(app):
assert app.socketio, "socketio doesnt exist?"
assert app.socketio.async_mode, "async_mode doesnt exist?"
assert app.socketio.async_mode == "threading", f"async_mode is {app.socketio.async_mode}"
socketio_test_client = app.socketio.test_client(app)
assert socketio_test_client.is_connected(), "socketio_test_client is not connected?"
socketio_test_client.emit('my_event', {'data': 'test'})
received = socketio_test_client.get_received()
assert len(received) == 0, "Response received from socketio"


@pytest.mark.dependency(depends=["test_socketio_exists_and_works"])
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_handle_errors_and_logging(app):
assert app.handle_errors_and_logging, "handle_errors_and_logging doesnt exist?"
assert callable(app.handle_errors_and_logging), "handle_errors_and_logging is not callable?"
assert app.handle_errors_and_logging(Exception("Test Exception")) is False, "handle_errors_and_logging did not return False?"


@pytest.mark.dependency(depends=["test_handle_errors_and_logging"])
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_static_loading_for_client(app):
assert app.static_folder, "static_folder doesnt exist?"
assert os.path.join("client","dist") in app.static_folder, f"static_folder is {app.static_folder}"
assert os.path.exists(app.static_folder), f"static_folder {app.static_folder} does not exist"


@pytest.mark.dependency(depends=["test_static_loading_for_client"])
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_index_html_exists_in_the_static_files(app):
assert os.path.exists(os.path.join(app.static_folder, "index.html")), f"index.html does not exist in {app.static_folder}"


@pytest.mark.dependency(depends=["test_index_html_exists_in_the_static_files"])
@pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
def test_main_view_response_is_200(app):
with app.test_client() as client:
response = client.get('/')
assert response.status_code == 200, f"Response status code is {response.status_code}"
assert response.data, "Response data is empty?"
assert b'<!DOCTYPE html>' in response.data, "Response data does not contain <!DOCTYPE html>?"
assert b'<html' in response.data, "Response data does not contain <html>?"
assert b'<head>' in response.data, "Response data does not contain <head>?"
assert b'<title>' in response.data, "Response data does not contain <title>?"
assert b'<body>' in response.data, "Response data does not contain <body>?"
assert b'<div id="app">' in response.data, 'Response data does not contain <div id="app">?'
assert b'<script type="module" crossorigin src=' in response.data, 'Response data does not contain <script type="module" crossorigin src=?'
assert b'<link rel="stylesheet" crossorigin href=' in response.data, 'Response data does not contain <link rel="stylesheet" crossorigin href=?'
assert b'</body>' in response.data, "Response data does not contain </body>?"
assert b'</html>' in response.data, "Response data does not contain </html>?"

# @pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
# def test_queue_view_response(app):
# with app.test_client() as client:
# response = client.get('/queue')
# assert response.status_code == 200, f"Response status code is {response.status_code}"
# assert response.data, "Response data is empty?"
# assert b'<!DOCTYPE html>' in response.data, "Response data does not contain <!DOCTYPE html>?"
# assert b'<html' in response.data, "Response data does not contain <html>?"
# assert b'<head>' in response.data, "Response data does not contain <head>?"
# assert b'<title>' in response.data, "Response data does not contain <title>?"
# assert b'<body>' in response.data, "Response data does not contain <body>?"
# assert b'<div id="app">' in response.data, 'Response data does not contain <div id="app">?'
# assert b'<script type="module" crossorigin src=' in response.data, 'Response data does not contain <script type="module" crossorigin src=?'
# assert b'<link rel="stylesheet" crossorigin href=' in response.data, 'Response data does not contain <link rel="stylesheet" crossorigin href=?'
# assert b'</body>' in response.data, "Response data does not contain </body>?"
# assert b'</html>' in response.data, "Response data does not contain </html>?"
#
# @pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
# def test_registered_view_response(app):
# with app.test_client() as client:
# response = client.get('/registration')
# assert response.status_code == 200, f"Response status code is {response.status_code}"
# assert response.data, "Response data is empty?"
# assert b'<!DOCTYPE html>' in response.data, "Response data does not contain <!DOCTYPE html>?"
# assert b'<html' in response.data, "Response data does not contain <html>?"
# assert b'<head>' in response.data, "Response data does not contain <head>?"
# assert b'<title>' in response.data, "Response data does not contain <title>?"
# assert b'<body>' in response.data, "Response data does not contain <body>?"
# assert b'<div id="app">' in response.data, 'Response data does not contain <div id="app">?'
# assert b'<script type="module" crossorigin src=' in response.data, 'Response data does not contain <script type="module" crossorigin src=?'
# assert b'<link rel="stylesheet" crossorigin href=' in response.data, 'Response data does not contain <link rel="stylesheet" crossorigin href=?'
# assert b'</body>' in response.data, "Response data does not contain </body>?"
# assert b'</html>' in response.data, "Response data does not contain </html>?"
#
# @pytest.mark.skipif(condition=testLevel < 1, reason="Not doing lvl 1 tests")
# def test_error_view_response(app):
# with app.test_client() as client:
# response = client.get('/error')
# assert response.status_code == 200, f"Response status code is {response.status_code}"
# assert response.data, "Response data is empty?"
# assert b'<!DOCTYPE html>' in response.data, "Response data does not contain <!DOCTYPE html>?"
# assert b'<html' in response.data, "Response data does not contain <html>?"
# assert b'<head>' in response.data, "Response data does not contain <head>?"
# assert b'<title>' in response.data, "Response data does not contain <title>?"
# assert b'<body>' in response.data, "Response data does not contain <body>?"
# assert b'<div id="app">' in response.data, 'Response data does not contain <div id="app">?'
# assert b'<script type="module" crossorigin src=' in response.data, 'Response data does not contain <script type="module" crossorigin src=?'
# assert b'<link rel="stylesheet" crossorigin href=' in response.data, 'Response data does not contain <link rel="stylesheet" crossorigin href=?'
# assert b'</body>' in response.data, "Response data does not contain </body>?"
# assert b'</html>' in response.data, "Response data does not contain </html>?"
56 changes: 56 additions & 0 deletions Tests/test_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import pytest
from Classes.Ports import Ports
from Classes.Vector3 import Vector3
from parallel_test_runner import testLevel

testLevelToRun = testLevel
shortTest = True

def __desc__():
return "Device Tests"

def __repr__():
return f"test_device.py running on port {Ports.getPortByName(os.getenv('PORT'))}"

@pytest.mark.dependency(depends=["test_app.py::test_main_view_response_is_200"], scope="session")
@pytest.mark.skipif(condition=testLevelToRun < 1, reason="Not doing lvl 1 tests")
def test_connection(app, fabricator):
assert fabricator.device is not None, f"No printer connected on {fabricator.device.DESCRIPTION}"
assert fabricator.device.serialConnection is not None, f"No serial connection on {fabricator.device.DESCRIPTION}"
assert fabricator.device.serialConnection.isOpen(), f"Serial connection not open on {fabricator.device.DESCRIPTION}"

@pytest.mark.dependency(depends=["test_connection"])
@pytest.mark.skipif(condition=testLevelToRun < 3, reason="Not doing lvl 3 tests")
def test_home(app, fabricator):
assert fabricator.device.home(), f"Failed to home {fabricator.device.DESCRIPTION}"

@pytest.mark.dependency(depends=["test_home"])
@pytest.mark.skipif(condition=testLevelToRun < 5, reason="Not doing lvl 5 tests")
def test_draw_square(app, fabricator):
squarePasses = 0
for point in [Vector3(50.0, 50.0, 2.0), Vector3(200.0, 50.0, 2.0), Vector3(200.0, 150.0, 2.0),
Vector3(50.0, 150.0, 2.0)]:
squarePasses += 1 if fabricator.device.goTo(point, isVerbose=True) else 0
assert squarePasses == 4, f"Failed to draw square on {fabricator.device.DESCRIPTION}"

@pytest.mark.dependency(depends=["test_home"])
@pytest.mark.skipif(condition=testLevelToRun < 5, reason="Not doing lvl 5 tests")
def test_draw_octagon(app, fabricator):
octagonPasses = 0
for point in [Vector3(50.0, 100.0, 2.0), Vector3(100.0, 50.0, 2.0), Vector3(150.0, 50.0, 2.0),
Vector3(200.0, 100.0, 2), Vector3(200.0, 150.0, 2.0), Vector3(150.0, 200.0, 2),
Vector3(100.0, 200.0, 2.0), Vector3(50.0, 150.0, 2.0)]:
octagonPasses += 1 if fabricator.device.goTo(point) else 0
assert octagonPasses == 8, f"Failed to draw octagon on {fabricator.device.DESCRIPTION}"

@pytest.mark.dependency(depends=["test_home"])
@pytest.mark.skipif(condition=testLevelToRun < 5, reason="Not doing lvl 5 tests")
def test_go_to_center(app, fabricator):
assert fabricator.device.goTo(Vector3(125.0, 100.0, 2.0)), f"Failed to go to location on {fabricator.device.DESCRIPTION}"

@pytest.mark.dependency(depends=["test_go_to_center"])
@pytest.mark.skipif(condition=testLevelToRun < 5, reason="Not doing lvl 5 tests")
def test_draw_circle(app, fabricator):
assert fabricator.device.sendGcode(b"G2 X125 Y100 I25 J0\n"), f"Failed to draw circle on {fabricator.device.DESCRIPTION}"
assert fabricator.device.sendGcode(b"G2 X125 Y100 I-25 J0\n"), f"Failed to draw circle on {fabricator.device.DESCRIPTION}"
Loading
Loading