diff --git a/preprocess_cancellation.py b/preprocess_cancellation.py index 737c8c8..3ffb9b4 100644 --- a/preprocess_cancellation.py +++ b/preprocess_cancellation.py @@ -147,14 +147,14 @@ def _clean_id(id): def parse_gcode(line): # drop comments - line = line.split(';', maxsplit=1)[0] + line = line.split(";", maxsplit=1)[0] command, *params = line.strip().split() parsed = {} for param in params: - if '=' in param: - parsed.update(dict(zip(param.split('=', maxsplit=1)))) + if "=" in param: + parsed.update(dict(zip(param.split("=", maxsplit=1)))) else: - parsed.update({ param[0].upper(): param[1:] }) + parsed.update({param[0].upper(): param[1:]}) return command, parsed @@ -510,5 +510,6 @@ def _main(): sys.exit(exitcode) + if __name__ == "__main__": _main() diff --git a/test_preprocessor.py b/test_preprocessor.py index 66138a5..10bf820 100644 --- a/test_preprocessor.py +++ b/test_preprocessor.py @@ -281,30 +281,102 @@ def test_issue_2_retractions_included_in_bounding_boxes(): definitions = [r for r in results if r.startswith("DEFINE_OBJECT")] - assert "DEFINE_OBJECT NAME=Leaf_stl_id_0_copy_0 CENTER=262.560,254.074 POLYGON=[[248.503,217.6],[247.62,218.483],[247.62,287.417],[248.503,288.3],[276.637,288.3],[277.52,287.417],[277.52,218.483],[276.637,217.6],[248.503,217.6]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_17 CENTER=212.125,263.634 POLYGON=[[249.038,218.607],[176.523,248.78],[175.64,249.663],[175.64,277.797],[176.523,278.68],[245.457,278.68],[246.34,277.797],[249.038,218.607]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_7 CENTER=212.092,232.556 POLYGON=[[176.523,217.6],[175.64,218.483],[175.64,246.617],[176.523,247.5],[217.858,270.087],[245.457,247.5],[246.34,246.617],[246.34,218.483],[245.457,217.6],[176.523,217.6]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_3 CENTER=212.085,201.377 POLYGON=[[176.523,186.42],[175.64,187.303],[175.64,215.437],[176.523,216.32],[217.858,238.907],[245.457,216.32],[246.34,215.437],[246.34,187.303],[245.457,186.42],[176.523,186.42]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_2 CENTER=212.085,170.197 POLYGON=[[176.523,155.24],[175.64,156.123],[175.64,184.257],[176.523,185.14],[217.858,207.727],[245.457,185.14],[246.34,184.257],[246.34,156.123],[245.457,155.24],[176.523,155.24]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_5 CENTER=212.085,139.017 POLYGON=[[176.523,124.06],[175.64,124.943],[175.64,153.077],[176.523,153.96],[217.858,176.547],[245.457,153.96],[246.34,153.077],[246.34,124.943],[245.457,124.06],[176.523,124.06]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_12 CENTER=212.085,107.837 POLYGON=[[176.523,92.88],[175.64,93.763],[175.64,121.897],[176.523,122.78],[217.858,145.367],[245.457,122.78],[246.34,121.897],[246.34,93.763],[245.457,92.88],[176.523,92.88]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_21 CENTER=212.086,76.657 POLYGON=[[176.523,61.7],[175.64,62.583],[175.64,90.717],[176.523,91.6],[217.858,114.187],[245.457,91.6],[246.34,90.717],[246.34,62.583],[245.457,61.7],[176.523,61.7]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_20 CENTER=139.930,76.676 POLYGON=[[104.543,61.7],[103.66,62.583],[103.66,90.717],[104.543,91.6],[173.477,91.6],[217.858,83.007],[173.477,61.7],[104.543,61.7]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_13 CENTER=140.185,107.747 POLYGON=[[145.878,83.007],[104.543,92.88],[103.66,93.763],[103.66,121.897],[104.543,122.78],[173.477,122.78],[174.36,121.897],[174.36,93.763],[173.477,92.88],[145.878,83.007]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_4 CENTER=140.185,138.927 POLYGON=[[145.878,114.187],[104.543,124.06],[103.66,124.943],[103.66,153.077],[104.543,153.96],[173.477,153.96],[174.36,153.077],[174.36,124.943],[173.477,124.06],[145.878,114.187]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_0 CENTER=140.185,170.107 POLYGON=[[145.878,145.367],[104.543,155.24],[103.66,156.123],[103.66,184.257],[104.543,185.14],[173.477,185.14],[174.36,184.257],[174.36,156.123],[173.477,155.24],[145.878,145.367]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_1 CENTER=140.185,201.287 POLYGON=[[145.878,176.547],[104.543,186.42],[103.66,187.303],[103.66,215.437],[104.543,216.32],[173.477,216.32],[174.36,215.437],[174.36,187.303],[173.477,186.42],[145.878,176.547]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_6 CENTER=140.189,232.467 POLYGON=[[145.878,207.727],[104.543,217.6],[103.66,218.483],[103.66,246.617],[104.543,247.5],[173.477,247.5],[174.36,246.617],[174.36,218.483],[173.477,217.6],[145.878,207.727]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_15 CENTER=140.183,263.647 POLYGON=[[145.878,238.907],[104.543,248.78],[103.66,249.663],[103.66,277.797],[104.543,278.68],[173.477,278.68],[174.36,277.797],[174.36,249.663],[173.477,248.78],[145.878,238.907]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_16 CENTER=67.954,263.755 POLYGON=[[32.563,248.78],[31.68,249.663],[31.68,277.797],[32.563,278.68],[101.497,278.68],[145.878,270.087],[101.497,248.78],[32.563,248.78]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_11 CENTER=68.132,232.556 POLYGON=[[32.563,217.6],[31.68,218.483],[31.68,246.617],[32.563,247.5],[73.898,270.087],[101.497,247.5],[102.38,246.617],[102.38,218.483],[101.497,217.6],[32.563,217.6]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_9 CENTER=68.125,201.377 POLYGON=[[32.563,186.42],[31.68,187.303],[31.68,215.437],[32.563,216.32],[73.898,238.907],[101.497,216.32],[102.38,215.437],[102.38,187.303],[101.497,186.42],[32.563,186.42]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_8 CENTER=68.125,170.197 POLYGON=[[32.563,155.24],[31.68,156.123],[31.68,184.257],[32.563,185.14],[73.898,207.727],[101.497,185.14],[102.38,184.257],[102.38,156.123],[101.497,155.24],[32.563,155.24]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_10 CENTER=68.125,139.017 POLYGON=[[32.563,124.06],[31.68,124.943],[31.68,153.077],[32.563,153.96],[73.898,176.547],[101.497,153.96],[102.38,153.077],[102.38,124.943],[101.497,124.06],[32.563,124.06]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_14 CENTER=68.124,107.836 POLYGON=[[32.563,92.88],[31.68,93.763],[31.68,121.897],[32.563,122.78],[73.898,145.367],[101.497,122.78],[102.38,121.897],[102.38,93.763],[101.497,92.88],[32.563,92.88]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_22 CENTER=284.066,138.959 POLYGON=[[73.898,114.187],[248.503,153.96],[317.437,153.96],[318.32,153.077],[318.32,124.943],[317.437,124.06],[73.898,114.187]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_18 CENTER=284.145,170.107 POLYGON=[[289.838,145.367],[248.503,155.24],[247.62,156.123],[247.62,184.257],[248.503,185.14],[317.437,185.14],[318.32,184.257],[318.32,156.123],[317.437,155.24],[289.838,145.367]]" not in definitions - assert "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_19 CENTER=283.965,201.251 POLYGON=[[289.838,176.547],[248.503,186.42],[247.62,187.303],[247.62,215.437],[248.503,216.32],[317.437,216.32],[318.32,215.437],[318.32,187.303],[317.437,186.42],[289.838,176.547]]" not in definitions + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_0_copy_0 CENTER=262.560,254.074 POLYGON=[[248.503,217.6],[247.62,218.483],[247.62,287.417],[248.503,288.3],[276.637,288.3],[277.52,287.417],[277.52,218.483],[276.637,217.6],[248.503,217.6]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_17 CENTER=212.125,263.634 POLYGON=[[249.038,218.607],[176.523,248.78],[175.64,249.663],[175.64,277.797],[176.523,278.68],[245.457,278.68],[246.34,277.797],[249.038,218.607]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_7 CENTER=212.092,232.556 POLYGON=[[176.523,217.6],[175.64,218.483],[175.64,246.617],[176.523,247.5],[217.858,270.087],[245.457,247.5],[246.34,246.617],[246.34,218.483],[245.457,217.6],[176.523,217.6]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_3 CENTER=212.085,201.377 POLYGON=[[176.523,186.42],[175.64,187.303],[175.64,215.437],[176.523,216.32],[217.858,238.907],[245.457,216.32],[246.34,215.437],[246.34,187.303],[245.457,186.42],[176.523,186.42]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_2 CENTER=212.085,170.197 POLYGON=[[176.523,155.24],[175.64,156.123],[175.64,184.257],[176.523,185.14],[217.858,207.727],[245.457,185.14],[246.34,184.257],[246.34,156.123],[245.457,155.24],[176.523,155.24]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_5 CENTER=212.085,139.017 POLYGON=[[176.523,124.06],[175.64,124.943],[175.64,153.077],[176.523,153.96],[217.858,176.547],[245.457,153.96],[246.34,153.077],[246.34,124.943],[245.457,124.06],[176.523,124.06]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_12 CENTER=212.085,107.837 POLYGON=[[176.523,92.88],[175.64,93.763],[175.64,121.897],[176.523,122.78],[217.858,145.367],[245.457,122.78],[246.34,121.897],[246.34,93.763],[245.457,92.88],[176.523,92.88]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_21 CENTER=212.086,76.657 POLYGON=[[176.523,61.7],[175.64,62.583],[175.64,90.717],[176.523,91.6],[217.858,114.187],[245.457,91.6],[246.34,90.717],[246.34,62.583],[245.457,61.7],[176.523,61.7]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_20 CENTER=139.930,76.676 POLYGON=[[104.543,61.7],[103.66,62.583],[103.66,90.717],[104.543,91.6],[173.477,91.6],[217.858,83.007],[173.477,61.7],[104.543,61.7]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_13 CENTER=140.185,107.747 POLYGON=[[145.878,83.007],[104.543,92.88],[103.66,93.763],[103.66,121.897],[104.543,122.78],[173.477,122.78],[174.36,121.897],[174.36,93.763],[173.477,92.88],[145.878,83.007]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_4 CENTER=140.185,138.927 POLYGON=[[145.878,114.187],[104.543,124.06],[103.66,124.943],[103.66,153.077],[104.543,153.96],[173.477,153.96],[174.36,153.077],[174.36,124.943],[173.477,124.06],[145.878,114.187]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_0 CENTER=140.185,170.107 POLYGON=[[145.878,145.367],[104.543,155.24],[103.66,156.123],[103.66,184.257],[104.543,185.14],[173.477,185.14],[174.36,184.257],[174.36,156.123],[173.477,155.24],[145.878,145.367]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_1 CENTER=140.185,201.287 POLYGON=[[145.878,176.547],[104.543,186.42],[103.66,187.303],[103.66,215.437],[104.543,216.32],[173.477,216.32],[174.36,215.437],[174.36,187.303],[173.477,186.42],[145.878,176.547]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_6 CENTER=140.189,232.467 POLYGON=[[145.878,207.727],[104.543,217.6],[103.66,218.483],[103.66,246.617],[104.543,247.5],[173.477,247.5],[174.36,246.617],[174.36,218.483],[173.477,217.6],[145.878,207.727]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_15 CENTER=140.183,263.647 POLYGON=[[145.878,238.907],[104.543,248.78],[103.66,249.663],[103.66,277.797],[104.543,278.68],[173.477,278.68],[174.36,277.797],[174.36,249.663],[173.477,248.78],[145.878,238.907]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_16 CENTER=67.954,263.755 POLYGON=[[32.563,248.78],[31.68,249.663],[31.68,277.797],[32.563,278.68],[101.497,278.68],[145.878,270.087],[101.497,248.78],[32.563,248.78]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_11 CENTER=68.132,232.556 POLYGON=[[32.563,217.6],[31.68,218.483],[31.68,246.617],[32.563,247.5],[73.898,270.087],[101.497,247.5],[102.38,246.617],[102.38,218.483],[101.497,217.6],[32.563,217.6]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_9 CENTER=68.125,201.377 POLYGON=[[32.563,186.42],[31.68,187.303],[31.68,215.437],[32.563,216.32],[73.898,238.907],[101.497,216.32],[102.38,215.437],[102.38,187.303],[101.497,186.42],[32.563,186.42]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_8 CENTER=68.125,170.197 POLYGON=[[32.563,155.24],[31.68,156.123],[31.68,184.257],[32.563,185.14],[73.898,207.727],[101.497,185.14],[102.38,184.257],[102.38,156.123],[101.497,155.24],[32.563,155.24]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_10 CENTER=68.125,139.017 POLYGON=[[32.563,124.06],[31.68,124.943],[31.68,153.077],[32.563,153.96],[73.898,176.547],[101.497,153.96],[102.38,153.077],[102.38,124.943],[101.497,124.06],[32.563,124.06]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_14 CENTER=68.124,107.836 POLYGON=[[32.563,92.88],[31.68,93.763],[31.68,121.897],[32.563,122.78],[73.898,145.367],[101.497,122.78],[102.38,121.897],[102.38,93.763],[101.497,92.88],[32.563,92.88]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_22 CENTER=284.066,138.959 POLYGON=[[73.898,114.187],[248.503,153.96],[317.437,153.96],[318.32,153.077],[318.32,124.943],[317.437,124.06],[73.898,114.187]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_18 CENTER=284.145,170.107 POLYGON=[[289.838,145.367],[248.503,155.24],[247.62,156.123],[247.62,184.257],[248.503,185.14],[317.437,185.14],[318.32,184.257],[318.32,156.123],[317.437,155.24],[289.838,145.367]]" + not in definitions + ) + assert ( + "DEFINE_OBJECT NAME=Leaf_stl_id_1_copy_19 CENTER=283.965,201.251 POLYGON=[[289.838,176.547],[248.503,186.42],[247.62,187.303],[247.62,215.437],[248.503,216.32],[317.437,216.32],[318.32,215.437],[318.32,187.303],[317.437,186.42],[289.838,176.547]]" + not in definitions + ) assert ( "DEFINE_OBJECT NAME=Leaf_stl_id_0_copy_0 CENTER=262.533,254.031 POLYGON=[[248.503,217.6],[247.62,218.483],[247.62,287.417],[248.503,288.3],[276.637,288.3],[277.52,287.417],[277.52,218.483],[276.637,217.6],[248.503,217.6]]"