Skip to content

Commit b7c6235

Browse files
committed
start fixing tests
1 parent ffafef1 commit b7c6235

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

examples/custom_m_codes.py

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ def start_intercept():
3030

3131
# Check for the type of the code
3232
if cde.type == CodeType.MCode and cde.majorNumber == 1234:
33+
# --------------- BEGIN FLUSH ---------------------
34+
# Flushing is only necessary if the action below needs to be in sync with the machine
35+
# at this point in the GCode stream. Otherwise, it can and should be skipped
36+
37+
# Flush the code's channel to be sure we are being in sync with the machine
38+
success = intercept_connection.flush(cde.channel).success
39+
40+
# Flushing failed so we need to cancel our code
41+
if not success:
42+
print("Flush failed")
43+
intercept_connection.cancel_code()
44+
continue
45+
# -------------- END FLUSH ------------------------
46+
3347
# Do whatever needs to be done if this is the right code
3448
print(cde, cde.flags)
3549

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setuptools.setup(
88
name="dsf-python",
9-
version="3.6.0",
9+
version="3.6.0-b2",
1010
description="Python interface to access DuetSoftwareFramework",
1111
long_description=long_description,
1212
long_description_content_type="text/markdown",

src/dsf/commands/code.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def short_str(self):
134134
if self.type == CodeType.Comment:
135135
return "(comment)"
136136

137-
prefix = "G53 " if self.flags & CodeFlags.EnforceAbsolutePosition != 0 else ""
137+
prefix = "G53 " if self.is_flag_set(CodeFlags.EnforceAbsolutePosition) else ""
138138
if self.majorNumber is not None:
139139
if self.minorNumber is not None:
140140
return f"{prefix}{self.type}{self.majorNumber}.{self.minorNumber}"
@@ -158,3 +158,6 @@ def keyword_to_str(self):
158158
KeywordType.Echo: "echo",
159159
KeywordType.Global: "global",
160160
}.get(self.keyword)
161+
162+
def is_flag_set(self, flag: CodeFlags):
163+
return self.flags & flag != 0

tests/test_custom_m_codes.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ def mock_dcs():
2727
server.listen(1)
2828
conn, _ = server.accept()
2929
print("send all")
30-
conn.sendall(b'{"version":11, "id":"foobar"}')
30+
conn.sendall(b'{"version":12, "id":"foobar"}')
3131
assert (
3232
conn.recv(1024) == b"{"
33-
b'"mode":"Intercept","version":11,"InterceptionMode":"Pre","Channels":["HTTP","Telnet",'
34-
b'"File","USB","Aux","Trigger","Queue","LCD","SBC","Daemon","Aux2","AutoPause","Unknown"],'
35-
b'"Filters":null,"PriorityCodes":false'
33+
b'"mode":"Intercept","version":12,"interceptionMode":"Pre","channels":["HTTP","Telnet",'
34+
b'"File","USB","Aux","Trigger","Queue","LCD","SBC","Daemon","Aux2","Autopause","Unknown"],'
35+
b'"filters":null,"priorityCodes":false'
3636
b"}"
3737
)
3838
conn.sendall(b'{"success":true}')
3939
conn.sendall(
4040
b"{"
41-
b'"connection":{"id":12,"apiVersion":10,"isConnected":true},"sourceConnection":12,'
41+
b'"connection":{"id":12,"apiVersion":12,"isConnected":true},"sourceConnection":12,'
4242
b'"result":null,"type":"M","channel":"HTTP","lineNumber":null,"indent":0,"keyword":0,'
4343
b'"keywordArgument":null,"majorNumber":1234,"minorNumber":null,"flags":2048,"comment":null,'
4444
b'"filePosition":null,"length":6,"parameters":[],"command":"Code"'
@@ -49,7 +49,7 @@ def mock_dcs():
4949
assert conn.recv(1024) == b'{"command":"Resolve","Type":0,"Content":null}'
5050
conn.sendall(
5151
b"{"
52-
b'"connection":{"id":12,"apiVersion":10,"isConnected":true},"sourceConnection":12,'
52+
b'"connection":{"id":12,"apiVersion":12,"isConnected":true},"sourceConnection":12,'
5353
b'"result":null,"type":"M","channel":"HTTP","lineNumber":null,"indent":0,"keyword":0,'
5454
b'"keywordArgument":null,"majorNumber":5678,"minorNumber":null,"flags":2048,"comment":null,'
5555
b'"filePosition":null,"length":6,"parameters":[],"command":"Code"'

0 commit comments

Comments
 (0)