pull/248/head
migo101 2023-07-07 11:30:32 +02:00
rodzic d71cf333b5
commit 8334af83d3
1 zmienionych plików z 14 dodań i 18 usunięć

Wyświetl plik

@ -26,8 +26,6 @@ class BlenderCAMTest(unittest.TestCase):
}
self.test_cases.append(test_case)
return self.test_cases
@staticmethod
def get_gcode_from_file(file):
with open(file, 'r') as f:
@ -36,30 +34,28 @@ class BlenderCAMTest(unittest.TestCase):
lines = gcode.splitlines()
return '\n'.join(lines[1:])
def test_gcode_generation(self):
def test_operation(self):
for test_case in self.test_cases:
with self.subTest(blend_file=test_case['subdir_name']):
original_dir = os.getcwd() # Get the original working directory
original_dir = os.getcwd() # Get the original working directory
blend_dir = f'test_data/{test_case["subdir_name"]}'
os.chdir(blend_dir) # Change the current working directory to the blend file directory
blend_dir = f'test_data/{test_case["subdir_name"]}'
os.chdir(blend_dir) # Change the current working directory to the blend file directory
# Run Blender in the background to generate GCode
command = f"blender -b {test_case['blend_file']} -P ../../gcode_generator.py"
subprocess.run(command, shell=True, check=True)
# Run Blender in the background to generate GCode
command = f"blender -b {test_case['blend_file']} -P ../../gcode_generator.py"
subprocess.run(command, shell=True, check=True)
for ref_file in test_case['gcode_files']:
generated_file = ref_file[1:]
generated_gcode = self.get_gcode_from_file(generated_file)
expected_gcode = self.get_gcode_from_file(ref_file)
for gcode_file in test_case['gcode_files']:
generated_gcode = self.get_gcode_from_file(gcode_file[1:])
expected_gcode = self.get_gcode_from_file(gcode_file)
# Check if the generated GCode matches the expected output
with self.subTest(operation= f"{test_case['subdir_name']}/{gcode_file}"):
self.assertEqual(generated_gcode, expected_gcode)
# Delete the generated GCode file after test
os.remove(generated_file)
os.remove(gcode_file[1:])
os.chdir(original_dir) # Return to the original working directory
os.chdir(original_dir) # Return to the original working directory
if __name__ == '__main__':
unittest.main()
unittest.main()