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

Add POSPAT tests #1452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion bCNC/controllers/_GenericController.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re

STATUSPAT = re.compile(r"^<(\w*?),MPos:([+\-]?\d*\.\d*),([+\-]?\d*\.\d*),([+\-]?\d*\.\d*)(?:,([+\-]?\d*\.\d*))?(?:,([+\-]?\d*\.\d*))?(?:,([+\-]?\d*\.\d*))?,WPos:([+\-]?\d*\.\d*),([+\-]?\d*\.\d*),([+\-]?\d*\.\d*)(?:,([+\-]?\d*\.\d*))?(?:,([+\-]?\d*\.\d*))?(?:,([+\-]?\d*\.\d*))?(?:,.*)?>$")
POSPAT = re.compile(r"^\[(...):([+\-]?\d*\.\d*),([+\-]?\d*\.\d*),([+\-]?\d*\.\d*)(?:,([+\-]?\d*\.\d*))?(?:,([+\-]?\d*\.\d*))?(?:,([+\-]?\d*\.\d*))?(:(\d*))?\]$")
POSPAT = re.compile(r"^\[(...):([+\-]?\d*\.\d*),([+\-]?\d*\.\d*),([+\-]?\d*\.\d*)(?:,([+\-]?\d*\.\d*))?(?:,([+\-]?\d*\.\d*))?(?:,([+\-]?\d*\.\d*))?(?::(?:\d*))?\]$")
TLOPAT = re.compile(r"^\[(...):([+\-]?\d*\.\d*)\]$")
DOLLARPAT = re.compile(r"^\[G\d* .*\]$")
SPLITPAT = re.compile(r"[:,]")
Expand Down
Empty file added bCNC/controllers/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions bCNC/controllers/test_controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from _GenericController import POSPAT, STATUSPAT


def test_pospat():
class Test:
def __init__(self, **entries): self.__dict__.update(entries)
input = ""
expected = []

for t in [
Test(input="[PRB:-356.0,-5.28,-118.3]", expected=("PRB", "-356.0", "-5.28", "-118.3", None, None, None)),
Test(input="[PRB:-356.0,-5.28,-118.3,4.0]", expected=("PRB", "-356.0", "-5.28", "-118.3", "4.0", None, None)),
Test(input="[PRB:-356.0,-5.28,-118.3,4.0,5.0]", expected=("PRB", "-356.0", "-5.28", "-118.3", "4.0", "5.0", None)),
Test(input="[PRB:-356.0,-5.28,-118.3,4.0,5.0,6.0]", expected=("PRB", "-356.0", "-5.28", "-118.3", "4.0", "5.0", "6.0")),
Test(input="[PRB:-356.0,-5.28,-118.3:0]", expected=("PRB", "-356.0", "-5.28", "-118.3", None, None, None)),
Test(input="[PRB:-356.0,-5.28,-118.3:1]", expected=("PRB", "-356.0", "-5.28", "-118.3", None, None, None)),
Test(input="[PRB:-356.0,-5.28,-118.3:12]", expected=("PRB", "-356.0", "-5.28", "-118.3", None, None, None)),
Test(input="[PRB:-356.0,-5.28,-118.3,4.0:1]", expected=("PRB", "-356.0", "-5.28", "-118.3", "4.0", None, None)),
Test(input="[PRB:-356.0,-5.28,-118.3,4.0,5.0:2]", expected=("PRB", "-356.0", "-5.28", "-118.3", "4.0", "5.0", None)),
Test(input="[PRB:-356.0,-5.28,-118.3,4.0,5.0,6.0:3]", expected=("PRB", "-356.0", "-5.28", "-118.3", "4.0", "5.0", "6.0")),
]:
got = POSPAT.match(t.input)
assert got != None, "input %s should match, but didn't" % t.input
assert got.groups() == t.expected, "input %s should result in %s, but got %s" % (t.input, t.expected, got.groups())


if __name__ == '__main__':
test_pospat()