diff --git a/src/Mod/CAM/Path/Post/Utils.py b/src/Mod/CAM/Path/Post/Utils.py index 1006a7df4b..1c27e45747 100644 --- a/src/Mod/CAM/Path/Post/Utils.py +++ b/src/Mod/CAM/Path/Post/Utils.py @@ -88,7 +88,7 @@ class FilenameGenerator: filename = FreeCAD.ActiveDocument.Label if not outputpath: - outputpath = "." + outputpath = os.getcwd() if not ext: ext = ".nc" diff --git a/src/Mod/CAM/TestCAMApp.py b/src/Mod/CAM/TestCAMApp.py index 847555751f..15197965cc 100644 --- a/src/Mod/CAM/TestCAMApp.py +++ b/src/Mod/CAM/TestCAMApp.py @@ -46,7 +46,7 @@ from Tests.TestPathOpUtil import TestPathOpUtil #from Tests.TestPathPost import TestPathPost from Tests.TestPathPost import TestPathPostUtils from Tests.TestPathPost import TestBuildPostList -from Tests.TestPathPost import TestOutputNameSubstitution +# from Tests.TestPathPost import TestOutputNameSubstitution from Tests.TestPathPost import TestPostProcessorFactory from Tests.TestPathPost import TestResolvingPostProcessorName from Tests.TestPathPost import TestFileNameGenerator @@ -88,7 +88,7 @@ False if TestFileNameGenerator.__name__ else True False if TestGeneratorDogboneII.__name__ else True False if TestHoldingTags.__name__ else True False if TestPathLanguage.__name__ else True -False if TestOutputNameSubstitution.__name__ else True +# False if TestOutputNameSubstitution.__name__ else True False if TestPathAdaptive.__name__ else True False if TestPathCore.__name__ else True False if TestPathOpDeburr.__name__ else True diff --git a/src/Mod/CAM/Tests/TestPathOpUtil.py b/src/Mod/CAM/Tests/TestPathOpUtil.py index fb2326ebee..72b8973cff 100644 --- a/src/Mod/CAM/Tests/TestPathOpUtil.py +++ b/src/Mod/CAM/Tests/TestPathOpUtil.py @@ -34,6 +34,7 @@ Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule()) DOC = FreeCAD.getHomePath() + "Mod/CAM/Tests/test_geomop.fcstd" + def getWire(obj, nr=0): return obj.Tip.Profile[0].Shape.Wires[nr] @@ -81,6 +82,13 @@ def wireMarkers(wire): class TestPathOpUtil(PathTestUtils.PathTestBase): + @classmethod + def setUpClass(cls): + cls.doc = FreeCAD.openDocument(DOC) + + @classmethod + def tearDownClass(cls): + FreeCAD.closeDocument(cls.doc.Name) def test00(self): """Verify isWireClockwise for polygon wires.""" @@ -137,8 +145,7 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): def test11(self): """Check offsetting a circular hole.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-circle")[0] + obj = self.doc.getObjectsByLabel("offset-circle")[0] small = getWireInside(obj) self.assertRoughly(10, small.Edges[0].Curve.Radius) @@ -154,12 +161,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertEqual(1, len(wire.Edges)) self.assertRoughly(0.1, wire.Edges[0].Curve.Radius) self.assertCoincide(Vector(0, 0, 1), wire.Edges[0].Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test12(self): """Check offsetting a circular hole by the radius or more makes the hole vanish.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-circle")[0] + obj = self.doc.getObjectsByLabel("offset-circle")[0] small = getWireInside(obj) self.assertRoughly(10, small.Edges[0].Curve.Radius) @@ -168,12 +173,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): wire = PathOpUtil.offsetWire(small, obj.Shape, 15, True) self.assertIsNone(wire) - FreeCAD.closeDocument("test_geomop") def test13(self): """Check offsetting a cylinder succeeds.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-circle")[0] + obj = self.doc.getObjectsByLabel("offset-circle")[0] big = getWireOutside(obj) self.assertRoughly(20, big.Edges[0].Curve.Radius) @@ -189,12 +192,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertEqual(1, len(wire.Edges)) self.assertRoughly(40, wire.Edges[0].Curve.Radius) self.assertCoincide(Vector(0, 0, -1), wire.Edges[0].Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test14(self): """Check offsetting a hole with Placement.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-placement")[0] + obj = self.doc.getObjectsByLabel("offset-placement")[0] wires = [ w @@ -215,12 +216,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertRoughly(8, wire.Edges[0].Curve.Radius) self.assertCoincide(Vector(0, 0, 0), wire.Edges[0].Curve.Center) self.assertCoincide(Vector(0, 0, 1), wire.Edges[0].Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test15(self): """Check offsetting a cylinder with Placement.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-placement")[0] + obj = self.doc.getObjectsByLabel("offset-placement")[0] wires = [ w @@ -241,12 +240,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertRoughly(22, wire.Edges[0].Curve.Radius) self.assertCoincide(Vector(0, 0, 0), wire.Edges[0].Curve.Center) self.assertCoincide(Vector(0, 0, -1), wire.Edges[0].Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test20(self): """Check offsetting hole wire succeeds.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] small = getWireInside(obj) # sanity check @@ -276,12 +273,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): False, [Vector(0, 4, 0), Vector(-x, -2, 0), Vector(x, -2, 0), Vector(0, 4, 0)], ) - FreeCAD.closeDocument("test_geomop") def test21(self): """Check offsetting hole wire for more than it's size makes hole vanish.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] small = getWireInside(obj) # sanity check @@ -299,12 +294,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): ) wire = PathOpUtil.offsetWire(small, obj.Shape, 5, True) self.assertIsNone(wire) - FreeCAD.closeDocument("test_geomop") def test22(self): """Check offsetting a body wire succeeds.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] big = getWireOutside(obj) # sanity check @@ -351,12 +344,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertIsNone("%s: angle=%s" % (type(e.Curve), angle)) lastAngle = angle self.assertTrue(PathOpUtil.isWireClockwise(wire)) - FreeCAD.closeDocument("test_geomop") def test31(self): """Check offsetting a cylinder.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("circle-cut")[0] + obj = self.doc.getObjectsByLabel("circle-cut")[0] wire = PathOpUtil.offsetWire(getWire(obj.Tool), getPositiveShape(obj), 3, True) self.assertEqual(1, len(wire.Edges)) @@ -372,12 +363,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertCoincide(Vector(), edge.Curve.Center) self.assertCoincide(Vector(0, 0, +1), edge.Curve.Axis) self.assertRoughly(33, edge.Curve.Radius) - FreeCAD.closeDocument("test_geomop") def test32(self): """Check offsetting a box.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("square-cut")[0] + obj = self.doc.getObjectsByLabel("square-cut")[0] wire = PathOpUtil.offsetWire(getWire(obj.Tool), getPositiveShape(obj), 3, True) self.assertEqual(8, len(wire.Edges)) @@ -413,12 +402,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertRoughly(3, e.Curve.Radius) self.assertCoincide(Vector(0, 0, +1), e.Curve.Axis) self.assertFalse(PathOpUtil.isWireClockwise(wire)) - FreeCAD.closeDocument("test_geomop") def test33(self): """Check offsetting a triangle.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("triangle-cut")[0] + obj = self.doc.getObjectsByLabel("triangle-cut")[0] wire = PathOpUtil.offsetWire(getWire(obj.Tool), getPositiveShape(obj), 3, True) self.assertEqual(6, len(wire.Edges)) @@ -447,12 +434,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): if Part.Circle == type(e.Curve): self.assertRoughly(3, e.Curve.Radius) self.assertCoincide(Vector(0, 0, +1), e.Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test34(self): """Check offsetting a shape.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("shape-cut")[0] + obj = self.doc.getObjectsByLabel("shape-cut")[0] wire = PathOpUtil.offsetWire(getWire(obj.Tool), getPositiveShape(obj), 3, True) self.assertEqual(6, len(wire.Edges)) @@ -482,12 +467,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): if Part.Circle == type(e.Curve): self.assertRoughly(radius, e.Curve.Radius) self.assertCoincide(Vector(0, 0, +1), e.Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test35(self): """Check offsetting a cylindrical hole.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("circle-cut")[0] + obj = self.doc.getObjectsByLabel("circle-cut")[0] wire = PathOpUtil.offsetWire(getWire(obj.Tool), getNegativeShape(obj), 3, True) self.assertEqual(1, len(wire.Edges)) @@ -503,12 +486,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertCoincide(Vector(), edge.Curve.Center) self.assertCoincide(Vector(0, 0, -1), edge.Curve.Axis) self.assertRoughly(27, edge.Curve.Radius) - FreeCAD.closeDocument("test_geomop") def test36(self): """Check offsetting a square hole.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("square-cut")[0] + obj = self.doc.getObjectsByLabel("square-cut")[0] wire = PathOpUtil.offsetWire(getWire(obj.Tool), getNegativeShape(obj), 3, True) self.assertEqual(4, len(wire.Edges)) @@ -530,12 +511,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): if Path.Geom.isRoughly(e.Vertexes[0].Point.y, e.Vertexes[1].Point.y): self.assertRoughly(54, e.Length) self.assertTrue(PathOpUtil.isWireClockwise(wire)) - FreeCAD.closeDocument("test_geomop") def test37(self): """Check offsetting a triangular holee.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("triangle-cut")[0] + obj = self.doc.getObjectsByLabel("triangle-cut")[0] wire = PathOpUtil.offsetWire(getWire(obj.Tool), getNegativeShape(obj), 3, True) self.assertEqual(3, len(wire.Edges)) @@ -552,12 +531,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): for e in wire.Edges: self.assertRoughly(length, e.Length) self.assertTrue(PathOpUtil.isWireClockwise(wire)) - FreeCAD.closeDocument("test_geomop") def test38(self): """Check offsetting a shape hole.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("shape-cut")[0] + obj = self.doc.getObjectsByLabel("shape-cut")[0] wire = PathOpUtil.offsetWire(getWire(obj.Tool), getNegativeShape(obj), 3, True) self.assertEqual(6, len(wire.Edges)) @@ -587,12 +564,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): if Part.Circle == type(e.Curve): self.assertRoughly(radius, e.Curve.Radius) self.assertCoincide(Vector(0, 0, -1), e.Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test40(self): """Check offsetting a single outside edge forward.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] w = getWireOutside(obj) length = 40 * math.cos(math.pi / 6) @@ -628,12 +603,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertCoincide(Vector(+x, y, 0), wire.Edges[0].Vertexes[0].Point) self.assertCoincide(Vector(-x, y, 0), wire.Edges[0].Vertexes[1].Point) - FreeCAD.closeDocument("test_geomop") def test41(self): """Check offsetting a single outside edge not forward.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] w = getWireOutside(obj) length = 40 * math.cos(math.pi / 6) @@ -668,14 +641,12 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertCoincide(Vector(-x, y, 0), wire.Edges[0].Vertexes[0].Point) self.assertCoincide(Vector(+x, y, 0), wire.Edges[0].Vertexes[1].Point) - FreeCAD.closeDocument("test_geomop") def test42(self): """Check offsetting multiple outside edges.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] obj.Shape.tessellate(0.01) - doc.recompute() + self.doc.recompute() w = getWireOutside(obj) length = 40 * math.cos(math.pi / 6) @@ -713,14 +684,12 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertEqual(1, len(rEdges)) self.assertCoincide(Vector(0, 20, 0), rEdges[0].Curve.Center) self.assertCoincide(Vector(0, 0, +1), rEdges[0].Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test43(self): """Check offsetting multiple backwards outside edges.""" # This is exactly the same as test32, except that the wire is flipped to make # sure the input orientation doesn't matter - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] w = getWireOutside(obj) length = 40 * math.cos(math.pi / 6) @@ -759,12 +728,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertEqual(1, len(rEdges)) self.assertCoincide(Vector(0, 20, 0), rEdges[0].Curve.Center) self.assertCoincide(Vector(0, 0, +1), rEdges[0].Curve.Axis) - FreeCAD.closeDocument("test_geomop") def test44(self): """Check offsetting a single inside edge forward.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] w = getWireInside(obj) length = 20 * math.cos(math.pi / 6) @@ -800,12 +767,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertCoincide(Vector(-x, y, 0), wire.Edges[0].Vertexes[0].Point) self.assertCoincide(Vector(+x, y, 0), wire.Edges[0].Vertexes[1].Point) - FreeCAD.closeDocument("test_geomop") def test45(self): """Check offsetting a single inside edge not forward.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] w = getWireInside(obj) length = 20 * math.cos(math.pi / 6) @@ -841,12 +806,10 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): self.assertCoincide(Vector(+x, y, 0), wire.Edges[0].Vertexes[0].Point) self.assertCoincide(Vector(-x, y, 0), wire.Edges[0].Vertexes[1].Point) - FreeCAD.closeDocument("test_geomop") def test46(self): """Check offsetting multiple inside edges.""" - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] w = getWireInside(obj) length = 20 * math.cos(math.pi / 6) @@ -878,14 +841,12 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): rEdges = [e for e in wire.Edges if Part.Circle == type(e.Curve)] self.assertEqual(0, len(rEdges)) - FreeCAD.closeDocument("test_geomop") def test47(self): """Check offsetting multiple backwards inside edges.""" # This is exactly the same as test36 except that the wire is flipped to make # sure it's orientation doesn't matter - doc = FreeCAD.openDocument(DOC) - obj = doc.getObjectsByLabel("offset-edge")[0] + obj = self.doc.getObjectsByLabel("offset-edge")[0] w = getWireInside(obj) length = 20 * math.cos(math.pi / 6) @@ -918,7 +879,6 @@ class TestPathOpUtil(PathTestUtils.PathTestBase): rEdges = [e for e in wire.Edges if Part.Circle == type(e.Curve)] self.assertEqual(0, len(rEdges)) - FreeCAD.closeDocument("test_geomop") def test50(self): """Orient an already oriented wire""" diff --git a/src/Mod/CAM/Tests/TestPathPost.py b/src/Mod/CAM/Tests/TestPathPost.py index fea14801dd..9494f5fb6a 100644 --- a/src/Mod/CAM/Tests/TestPathPost.py +++ b/src/Mod/CAM/Tests/TestPathPost.py @@ -21,29 +21,20 @@ # * * # *************************************************************************** +from Path.Post.Command import DlgSelectPostProcessor +from Path.Post.Processor import PostProcessor, PostProcessorFactory +from unittest.mock import patch, MagicMock +import FreeCAD +import Path +import Path.Post.Command as PathCommand +import Path.Post.Processor as PathPost +import Path.Post.Utils as PostUtils import difflib import os import unittest -from unittest.mock import patch, MagicMock - -import FreeCAD -import Path - -import Path.Post.Command as PathCommand -import Path.Post.Utils as PostUtils - -from Path.Post.Processor import PostProcessor, PostProcessorFactory - -#from Path.Post.Command import processFileNameSubstitutions, DlgSelectPostProcessor -from Path.Post.Command import DlgSelectPostProcessor - -# If KEEP_DEBUG_OUTPUT is False, remove the gcode file after the test succeeds. -# If KEEP_DEBUG_OUTPUT is True or the test fails leave the gcode file behind -# so it can be looked at easily. -KEEP_DEBUG_OUTPUT = True PathCommand.LOG_MODULE = Path.Log.thisModule() -Path.Log.setLevel(Path.Log.Level.DEBUG, PathCommand.LOG_MODULE) +Path.Log.setLevel(Path.Log.Level.INFO, PathCommand.LOG_MODULE) class TestFileNameGenerator(unittest.TestCase): @@ -149,13 +140,15 @@ class TestFileNameGenerator(unittest.TestCase): generator = PostUtils.FilenameGenerator(job=self.job) filename_generator = generator.generate_filenames() filename = next(filename_generator) + Path.Log.debug(filename) # outlist = PathPost.buildPostList(self.job) # self.assertTrue(len(outlist) == 1) # subpart, objs = outlist[0] # filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, os.path.normpath(f"{self.testfilename}.nc")) + #self.assertEqual(filename, os.path.normpath(f"{self.testfilename}.nc")) + self.assertEqual(filename, os.path.join(os.getcwd(), f"{self.testfilename}.nc")) def test010(self): # Substitute current file path @@ -207,7 +200,9 @@ class TestFileNameGenerator(unittest.TestCase): filename_generator = generator.generate_filenames() filename = next(filename_generator) - self.assertEqual(filename, f"{self.testfilename}.nc") + expected = os.path.join(os.getcwd(), f"{self.testfilename}.nc") + + self.assertEqual(filename, expected ) #f"{self.testfilename}.nc") def test030(self): teststring = "%M/outfile.nc" @@ -256,7 +251,7 @@ class TestFileNameGenerator(unittest.TestCase): self.job.PostProcessorOutputFile = teststring generator = PostUtils.FilenameGenerator(job=self.job) filename_generator = generator.generate_filenames() - expected_filenames = [f"{i}-test_filenaming.nc" for i in range(5)] + expected_filenames = [os.path.join( os.getcwd(), f"{i}-test_filenaming.nc") for i in range(5)] for expected_filename in expected_filenames: filename = next(filename_generator) self.assertEqual(filename, os.path.normpath(expected_filename)) @@ -273,10 +268,10 @@ class TestFileNameGenerator(unittest.TestCase): filename_generator = generator.generate_filenames() filename = next(filename_generator) - self.assertEqual(filename, os.path.normpath("0-test_filenaming.nc")) + self.assertEqual(filename, os.path.join(os.getcwd(), "0-test_filenaming.nc")) def test060(self): - """ Test subpart naming""" + """Test subpart naming""" teststring = "%M/outfile.nc" self.job.PostProcessorOutputFile = teststring Path.Preferences.setOutputFileDefaults( @@ -292,14 +287,21 @@ class TestFileNameGenerator(unittest.TestCase): class TestResolvingPostProcessorName(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/Tests/boxtest.fcstd") + cls.job = cls.doc.getObject("Job") + + @classmethod + def tearDownClass(cls): + FreeCAD.closeDocument(cls.doc.Name) + def setUp(self): - self.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/Tests/boxtest.fcstd") - self.job = self.doc.getObject("Job") pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/CAM") pref.SetString("PostProcessorDefault", "") def tearDown(self): - FreeCAD.closeDocument("boxtest") + pass def test010(self): # Test if post is defined in job @@ -340,12 +342,20 @@ class TestResolvingPostProcessorName(unittest.TestCase): class TestPostProcessorFactory(unittest.TestCase): """Test creation of postprocessor objects.""" + @classmethod + def setUpClass(cls): + cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/Tests/boxtest.fcstd") + cls.job = cls.doc.getObject("Job") + + @classmethod + def tearDownClass(cls): + FreeCAD.closeDocument(cls.doc.Name) + def setUp(self): - self.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/Tests/boxtest.fcstd") - self.job = self.doc.getObject("Job") + pass def tearDown(self): - FreeCAD.closeDocument("boxtest") + pass def test020(self): # test creation of postprocessor object @@ -360,94 +370,27 @@ class TestPostProcessorFactory(unittest.TestCase): self.assertTrue(post is not None) self.assertTrue(hasattr(post, "_buildPostList")) - # def test100(self): - # """Test the processFileNameSubstitutions function.""" - - # document_dir = os.path.dirname(FreeCAD.ActiveDocument.FileName) - # Path.Log.debug(f"document_dir: {document_dir}") - - # user_macro_dir = os.path.dirname(FreeCAD.getUserMacroDir()) - # Path.Log.debug(f"user_macro_dir: {user_macro_dir}") - - # outputpath = "%D/output" - # filename = "outputfile-%j-%d" - # ext = ".txt" - # expected_path = f"{document_dir}{os.path.sep}output/outputfile-{self.job.Label}-{self.doc.Label}{ext}" - - # # Call the function - # result = processFileNameSubstitutions( - # self.job, "Subpart", 1, outputpath, filename, ext - # ) - - # Path.Log.debug(f"result: {result}") - - # self.assertEqual(result, expected_path) - - # # test macro path substitution - # outputpath = "%M/output" - # filename = "file-%j" - # ext = ".txt" - - # result = processFileNameSubstitutions( - # self.job, "Subpart", 1, outputpath, filename, ext - # ) - # expected_path = f"{user_macro_dir}/output/file-{self.job.Label}.txt" - - # self.assertEqual(result, expected_path) - - # # test job name substitution - # document_label = FreeCAD.ActiveDocument.Label - # outputpath = "output/%d" - # filename = "file-%d-%j" - # ext = ".txt" - - # result = processFileNameSubstitutions( - # self.job, "Subpart", 1, outputpath, filename, ext - # ) - # expected_path = ( - # f"output/{document_label}/file-{document_label}-{self.job.Label}.txt" - # ) - - # self.assertEqual(result, expected_path) - - # # test sequence number substitution - # outputpath = "output" - # filename = "file-%S" - # ext = ".txt" - - # result = processFileNameSubstitutions( - # self.job, "Subpart", 42, outputpath, filename, ext - # ) - # expected_path = f"output/file-42.txt" - - # self.assertEqual(result, expected_path) - - # # test tool number substitution - # outputpath = "output" - # filename = "file" - # ext = "" - - # result = processFileNameSubstitutions( - # self.job, "Subpart", 1, outputpath, filename, ext - # ) - # expected_path = f"output/file.nc" # Expect default .nc extension - - # self.assertEqual(result, expected_path) - class TestPostProcessorClass(unittest.TestCase): """Test new post structure objects.""" + @classmethod + def setUpClass(cls): + cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/Tests/boxtest.fcstd") + cls.job = cls.doc.getObject("Job") + + @classmethod + def tearDownClass(cls): + FreeCAD.closeDocument(cls.doc.Name) + def setUp(self): pass def tearDown(self): - FreeCAD.closeDocument(FreeCAD.ActiveDocument.Name) + pass def test010(self): """Test the export function.""" - doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/Tests/boxtest.fcstd") - job = doc.getObject("Job") post = PostProcessorFactory.get_post_processor(job, "linuxcnc") sections = post.export() for sec in sections: @@ -455,8 +398,6 @@ class TestPostProcessorClass(unittest.TestCase): def test020(self): """Test the export function with splitting.""" - doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/Tests/test_filenaming.fcstd") - job = doc.getObject("Job") post = PostProcessorFactory.get_post_processor(job, "linuxcnc") sections = post.export() for sec in sections: @@ -464,8 +405,6 @@ class TestPostProcessorClass(unittest.TestCase): def test030(self): """Test the export function with splitting.""" - doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/Tests/test_filenaming.fcstd") - job = doc.getObject("Job") post = PostProcessorFactory.get_post_processor(job, "generic") sections = post.export() for sec in sections: @@ -484,156 +423,156 @@ class TestPostProcessorClass(unittest.TestCase): # def tearDown(self): # FreeCAD.closeDocument("boxtest") - ## - ## You can run just this test using: - ## ./FreeCAD -c -t Tests.TestPathPost.TestPathPost.test_postprocessors - ## - # def test_postprocessors(self): - # """Test the postprocessors.""" - # # - # # The tests are performed in the order they are listed: - # # one test performed on all of the postprocessors - # # then the next test on all of the postprocessors, etc. - # # You can comment out the tuples for tests that you don't want - # # to use. - # # - # tests_to_perform = ( - # # (output_file_id, freecad_document, job_name, postprocessor_arguments, - # # postprocessor_list) - # # - # # test with all of the defaults (metric mode, etc.) - # ("default", "boxtest1", "Job", "--no-show-editor", ()), - # # test in Imperial mode - # ("imperial", "boxtest1", "Job", "--no-show-editor --inches", ()), - # # test in metric, G55, M4, the other way around the part - # ("other_way", "boxtest1", "Job001", "--no-show-editor", ()), - # # test in metric, split by fixtures, G54, G55, G56 - # ("split", "boxtest1", "Job002", "--no-show-editor", ()), - # # test in metric mode without the header - # ("no_header", "boxtest1", "Job", "--no-header --no-show-editor", ()), - # # test translating G81, G82, and G83 to G00 and G01 commands - # ( - # "drill_translate", - # "drill_test1", - # "Job", - # "--no-show-editor --translate_drill", - # ("grbl", "refactored_grbl"), - # ), - # ) - # # - # # The postprocessors to test. - # # You can comment out any postprocessors that you don't want - # # to test. - # # - # postprocessors_to_test = ( - # "centroid", - # # "fanuc", - # "grbl", - # "linuxcnc", - # "mach3_mach4", - # "refactored_centroid", - # # "refactored_fanuc", - # "refactored_grbl", - # "refactored_linuxcnc", - # "refactored_mach3_mach4", - # "refactored_test", - # ) - # # - # # Enough of the path to where the tests are stored so that - # # they can be found by the python interpreter. - # # - # PATHTESTS_LOCATION = "Mod/CAM/Tests" - # # - # # The following code tries to re-use an open FreeCAD document - # # as much as possible. It compares the current document with - # # the document for the next test. If the names are different - # # then the current document is closed and the new document is - # # opened. The final document is closed at the end of the code. - # # - # current_document = "" - # for ( - # output_file_id, - # freecad_document, - # job_name, - # postprocessor_arguments, - # postprocessor_list, - # ) in tests_to_perform: - # if current_document != freecad_document: - # if current_document != "": - # FreeCAD.closeDocument(current_document) - # current_document = freecad_document - # current_document_path = ( - # FreeCAD.getHomePath() - # + PATHTESTS_LOCATION - # + os.path.sep - # + current_document - # + ".fcstd" - # ) - # FreeCAD.open(current_document_path) - # job = FreeCAD.ActiveDocument.getObject(job_name) - # # Create the objects to be written by the postprocessor. - # postlist = PathPost.buildPostList(job) - # for postprocessor_id in postprocessors_to_test: - # if postprocessor_list == () or postprocessor_id in postprocessor_list: - # print( - # "\nRunning %s test on %s postprocessor:\n" - # % (output_file_id, postprocessor_id) - # ) - # processor = PostProcessor.load(postprocessor_id) - # output_file_path = FreeCAD.getHomePath() + PATHTESTS_LOCATION - # output_file_pattern = "test_%s_%s" % ( - # postprocessor_id, - # output_file_id, - # ) - # output_file_extension = ".ngc" - # for idx, section in enumerate(postlist): - # partname = section[0] - # sublist = section[1] - # output_filename = PathPost.processFileNameSubstitutions( - # job, - # partname, - # idx, - # output_file_path, - # output_file_pattern, - # output_file_extension, - # ) - # # print("output file: " + output_filename) - # file_path, extension = os.path.splitext(output_filename) - # reference_file_name = "%s%s%s" % (file_path, "_ref", extension) - # # print("reference file: " + reference_file_name) - # gcode = processor.export( - # sublist, output_filename, postprocessor_arguments - # ) - # if not gcode: - # print("no gcode") - # with open(reference_file_name, "r") as fp: - # reference_gcode = fp.read() - # if not reference_gcode: - # print("no reference gcode") - # # Remove the "Output Time:" line in the header from the - # # comparison if it is present because it changes with - # # every test. - # gcode_lines = [ - # i for i in gcode.splitlines(True) if "Output Time:" not in i - # ] - # reference_gcode_lines = [ - # i - # for i in reference_gcode.splitlines(True) - # if "Output Time:" not in i - # ] - # if gcode_lines != reference_gcode_lines: - # msg = "".join( - # difflib.ndiff(gcode_lines, reference_gcode_lines) - # ) - # self.fail( - # os.path.basename(output_filename) - # + " output doesn't match:\n" - # + msg - # ) - # if not KEEP_DEBUG_OUTPUT: - # os.remove(output_filename) - # if current_document != "": - # FreeCAD.closeDocument(current_document) +## +## You can run just this test using: +## ./FreeCAD -c -t Tests.TestPathPost.TestPathPost.test_postprocessors +## +# def test_postprocessors(self): +# """Test the postprocessors.""" +# # +# # The tests are performed in the order they are listed: +# # one test performed on all of the postprocessors +# # then the next test on all of the postprocessors, etc. +# # You can comment out the tuples for tests that you don't want +# # to use. +# # +# tests_to_perform = ( +# # (output_file_id, freecad_document, job_name, postprocessor_arguments, +# # postprocessor_list) +# # +# # test with all of the defaults (metric mode, etc.) +# ("default", "boxtest1", "Job", "--no-show-editor", ()), +# # test in Imperial mode +# ("imperial", "boxtest1", "Job", "--no-show-editor --inches", ()), +# # test in metric, G55, M4, the other way around the part +# ("other_way", "boxtest1", "Job001", "--no-show-editor", ()), +# # test in metric, split by fixtures, G54, G55, G56 +# ("split", "boxtest1", "Job002", "--no-show-editor", ()), +# # test in metric mode without the header +# ("no_header", "boxtest1", "Job", "--no-header --no-show-editor", ()), +# # test translating G81, G82, and G83 to G00 and G01 commands +# ( +# "drill_translate", +# "drill_test1", +# "Job", +# "--no-show-editor --translate_drill", +# ("grbl", "refactored_grbl"), +# ), +# ) +# # +# # The postprocessors to test. +# # You can comment out any postprocessors that you don't want +# # to test. +# # +# postprocessors_to_test = ( +# "centroid", +# # "fanuc", +# "grbl", +# "linuxcnc", +# "mach3_mach4", +# "refactored_centroid", +# # "refactored_fanuc", +# "refactored_grbl", +# "refactored_linuxcnc", +# "refactored_mach3_mach4", +# "refactored_test", +# ) +# # +# # Enough of the path to where the tests are stored so that +# # they can be found by the python interpreter. +# # +# PATHTESTS_LOCATION = "Mod/CAM/Tests" +# # +# # The following code tries to re-use an open FreeCAD document +# # as much as possible. It compares the current document with +# # the document for the next test. If the names are different +# # then the current document is closed and the new document is +# # opened. The final document is closed at the end of the code. +# # +# current_document = "" +# for ( +# output_file_id, +# freecad_document, +# job_name, +# postprocessor_arguments, +# postprocessor_list, +# ) in tests_to_perform: +# if current_document != freecad_document: +# if current_document != "": +# FreeCAD.closeDocument(current_document) +# current_document = freecad_document +# current_document_path = ( +# FreeCAD.getHomePath() +# + PATHTESTS_LOCATION +# + os.path.sep +# + current_document +# + ".fcstd" +# ) +# FreeCAD.open(current_document_path) +# job = FreeCAD.ActiveDocument.getObject(job_name) +# # Create the objects to be written by the postprocessor. +# self.pp._buildPostList(job) +# for postprocessor_id in postprocessors_to_test: +# if postprocessor_list == () or postprocessor_id in postprocessor_list: +# print( +# "\nRunning %s test on %s postprocessor:\n" +# % (output_file_id, postprocessor_id) +# ) +# processor = PostProcessor.load(postprocessor_id) +# output_file_path = FreeCAD.getHomePath() + PATHTESTS_LOCATION +# output_file_pattern = "test_%s_%s" % ( +# postprocessor_id, +# output_file_id, +# ) +# output_file_extension = ".ngc" +# for idx, section in enumerate(postlist): +# partname = section[0] +# sublist = section[1] +# output_filename = PathPost.processFileNameSubstitutions( +# job, +# partname, +# idx, +# output_file_path, +# output_file_pattern, +# output_file_extension, +# ) +# # print("output file: " + output_filename) +# file_path, extension = os.path.splitext(output_filename) +# reference_file_name = "%s%s%s" % (file_path, "_ref", extension) +# # print("reference file: " + reference_file_name) +# gcode = processor.export( +# sublist, output_filename, postprocessor_arguments +# ) +# if not gcode: +# print("no gcode") +# with open(reference_file_name, "r") as fp: +# reference_gcode = fp.read() +# if not reference_gcode: +# print("no reference gcode") +# # Remove the "Output Time:" line in the header from the +# # comparison if it is present because it changes with +# # every test. +# gcode_lines = [ +# i for i in gcode.splitlines(True) if "Output Time:" not in i +# ] +# reference_gcode_lines = [ +# i +# for i in reference_gcode.splitlines(True) +# if "Output Time:" not in i +# ] +# if gcode_lines != reference_gcode_lines: +# msg = "".join( +# difflib.ndiff(gcode_lines, reference_gcode_lines) +# ) +# self.fail( +# os.path.basename(output_filename) +# + " output doesn't match:\n" +# + msg +# ) +# if not KEEP_DEBUG_OUTPUT: +# os.remove(output_filename) +# if current_document != "": +# FreeCAD.closeDocument(current_document) class TestPathPostUtils(unittest.TestCase): @@ -664,15 +603,6 @@ class TestPathPostUtils(unittest.TestCase): ) -# def dumpgroup(group): -# print("====Dump Group======") -# for i in group: -# print(i[0]) -# for j in i[1]: -# print(f"--->{j.Name}") -# print("====================") - - class TestBuildPostList(unittest.TestCase): """ The postlist is the list of postprocessable elements from the job. @@ -692,13 +622,21 @@ class TestBuildPostList(unittest.TestCase): """ + @classmethod + def setUpClass(cls): + cls.testfile = FreeCAD.getHomePath() + "Mod/CAM/Tests/test_filenaming.fcstd" + cls.doc = FreeCAD.open(cls.testfile) + cls.job = cls.doc.getObjectsByLabel("MainJob")[0] + + @classmethod + def tearDownClass(cls): + FreeCAD.closeDocument(cls.doc.Name) + def setUp(self): - self.testfile = FreeCAD.getHomePath() + "Mod/CAM/Tests/test_filenaming.fcstd" - self.doc = FreeCAD.open(self.testfile) - self.job = self.doc.getObjectsByLabel("MainJob")[0] + self.pp = PathPost.PostProcessor(self.job, "generic", "", "") def tearDown(self): - FreeCAD.closeDocument(self.doc.Name) + pass def test000(self): @@ -711,7 +649,7 @@ class TestBuildPostList(unittest.TestCase): self.job.OrderOutputBy = "Operation" def test010(self): - postlist = PathPost.buildPostList(self.job) + postlist = self.pp._buildPostList() self.assertTrue(type(postlist) is list) @@ -724,14 +662,14 @@ class TestBuildPostList(unittest.TestCase): # Without splitting, result should be list of one item self.job.SplitOutput = False self.job.OrderOutputBy = "Operation" - postlist = PathPost.buildPostList(self.job) + postlist = self.pp._buildPostList() self.assertTrue(len(postlist) == 1) def test030(self): # No splitting should include all ops, tools, and fixtures self.job.SplitOutput = False self.job.OrderOutputBy = "Operation" - postlist = PathPost.buildPostList(self.job) + postlist = self.pp._buildPostList() firstoutputitem = postlist[0] firstoplist = firstoutputitem[1] self.assertTrue(len(firstoplist) == 14) @@ -743,7 +681,7 @@ class TestBuildPostList(unittest.TestCase): self.job.SplitOutput = True self.job.PostProcessorOutputFile = teststring self.job.OrderOutputBy = "Tool" - postlist = PathPost.buildPostList(self.job) + postlist = self.pp._buildPostList() firstoutputitem = postlist[0] self.assertTrue(firstoutputitem[0] == str(5)) @@ -758,7 +696,7 @@ class TestBuildPostList(unittest.TestCase): self.job.SplitOutput = True self.job.PostProcessorOutputFile = teststring self.job.OrderOutputBy = "Tool" - postlist = PathPost.buildPostList(self.job) + postlist = self.pp._buildPostList() firstoutputitem = postlist[0] self.assertTrue(firstoutputitem[0] == "TC__7_16__two_flute") @@ -769,272 +707,9 @@ class TestBuildPostList(unittest.TestCase): self.job.SplitOutput = True self.job.PostProcessorOutputFile = teststring self.job.OrderOutputBy = "Fixture" + postlist = self.pp._buildPostList() - postlist = PathPost.buildPostList(self.job) firstoutputitem = postlist[0] firstoplist = firstoutputitem[1] self.assertTrue(len(firstoplist) == 6) self.assertTrue(firstoutputitem[0] == "G54") - - -class TestOutputNameSubstitution(unittest.TestCase): - - """ - String substitution allows the following: - %D ... directory of the active document - %d ... name of the active document (with extension) - %M ... user macro directory - %j ... name of the active Job object - - - The Following can be used if output is being split. If Output is not split - these will be ignored. - %S ... Sequence Number (default) - - %T ... Tool Number - %t ... Tool Controller label - - %W ... Work Coordinate System - %O ... Operation Label - - self.job.Fixtures = ["G54"] - self.job.SplitOutput = False - self.job.OrderOutputBy = "Fixture" - - Assume: - active document: self.assertTrue(filename, f"{home}/testdoc.fcstd - user macro: ~/.local/share/FreeCAD/Macro - Job: MainJob - Operations: - OutsideProfile - DrillAllHoles - TC: 7/16" two flute (5) - TC: Drill (2) - Fixtures: (G54, G55) - - Strings should be sanitized like this to ensure valid filenames - # import re - # filename="TC: 7/16" two flute" - # >>> re.sub(r"[^\w\d-]","_",filename) - # "TC__7_16__two_flute" - - """ - - def setUp(self): - self.testfile = FreeCAD.getHomePath() + "Mod/CAM/Tests/test_filenaming.fcstd" - self.testfilepath, self.testfilename = os.path.split(self.testfile) - self.testfilename, self.ext = os.path.splitext(self.testfilename) - - self.doc = FreeCAD.open(self.testfile) - self.job = self.doc.getObjectsByLabel("MainJob")[0] - self.macro = FreeCAD.getUserMacroDir() - self.job.SplitOutput = False - - def tearDown(self): - FreeCAD.closeDocument(self.doc.Name) - - def test000(self): - # Test basic name generation with empty string - FreeCAD.setActiveDocument(self.doc.Label) - teststring = "" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - - self.assertTrue(len(outlist) == 1) - subpart, objs = outlist[0] - - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, f"{self.testfilename}.nc") - - def test015(self): - # Test basic string substitution without splitting - teststring = "~/Desktop/%j.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - - self.assertTrue(len(outlist) == 1) - subpart, objs = outlist[0] - - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual( - os.path.normpath(filename), os.path.normpath("~/Desktop/MainJob.nc") - ) - - def test010(self): - # Substitute current file path - teststring = "%D/testfile.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual( - os.path.normpath(filename), - os.path.normpath(f"{self.testfilepath}/testfile.nc"), - ) - - def test020(self): - teststring = "%d.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, f"{self.testfilename}.nc") - - def test030(self): - teststring = "%M/outfile.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual( - os.path.normpath(filename), os.path.normpath(f"{self.macro}outfile.nc") - ) - - def test040(self): - # unused substitution strings should be ignored - teststring = "%d%T%t%W%O/testdoc.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual( - os.path.normpath(filename), - os.path.normpath(f"{self.testfilename}/testdoc.nc"), - ) - - def test050(self): - # explicitly using the sequence number should include it where indicated. - teststring = "%S-%d.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, "0-test_filenaming.nc") - - def test060(self): - # # Split by Tool - self.job.SplitOutput = True - self.job.OrderOutputBy = "Tool" - outlist = PathPost.buildPostList(self.job) - - # substitute jobname and use default sequence numbers - teststring = "%j.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, "MainJob-0.nc") - subpart, objs = outlist[1] - filename = PathPost.resolveFileName(self.job, subpart, 1) - self.assertEqual(filename, "MainJob-1.nc") - - # Use Toolnumbers and default sequence numbers - teststring = "%T.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, "5-0.nc") - subpart, objs = outlist[1] - filename = PathPost.resolveFileName(self.job, subpart, 1) - self.assertEqual(filename, "2-1.nc") - - # Use Tooldescriptions and default sequence numbers - teststring = "%t.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - outlist = PathPost.buildPostList(self.job) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, "TC__7_16__two_flute-0.nc") - subpart, objs = outlist[1] - filename = PathPost.resolveFileName(self.job, subpart, 1) - self.assertEqual(filename, "TC__Drill-1.nc") - - def test070(self): - # Split by WCS - self.job.SplitOutput = True - self.job.OrderOutputBy = "Fixture" - outlist = PathPost.buildPostList(self.job) - - teststring = "%j.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, "MainJob-0.nc") - subpart, objs = outlist[1] - filename = PathPost.resolveFileName(self.job, subpart, 1) - self.assertEqual(filename, "MainJob-1.nc") - - teststring = "%W-%j.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, "G54-MainJob-0.nc") - subpart, objs = outlist[1] - filename = PathPost.resolveFileName(self.job, subpart, 1) - self.assertEqual(filename, "G55-MainJob-1.nc") - - def test080(self): - # Split by Operation - self.job.SplitOutput = True - self.job.OrderOutputBy = "Operation" - outlist = PathPost.buildPostList(self.job) - - teststring = "%j.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, "MainJob-0.nc") - subpart, objs = outlist[1] - filename = PathPost.resolveFileName(self.job, subpart, 1) - self.assertEqual(filename, "MainJob-1.nc") - - teststring = "%O-%j.nc" - self.job.PostProcessorOutputFile = teststring - Path.Preferences.setOutputFileDefaults( - teststring, "Append Unique ID on conflict" - ) - subpart, objs = outlist[0] - filename = PathPost.resolveFileName(self.job, subpart, 0) - self.assertEqual(filename, "OutsideProfile-MainJob-0.nc") - subpart, objs = outlist[1] - filename = PathPost.resolveFileName(self.job, subpart, 1) - self.assertEqual(filename, "DrillAllHoles-MainJob-1.nc")