| import tempfile | |
| import unittest | |
| from pathlib import Path | |
| from src.cad_parser import parse_dxf | |
| class DxfParserTests(unittest.TestCase): | |
| def test_parse_simple_meter_dxf_boundary(self): | |
| content = """0 | |
| SECTION | |
| 2 | |
| HEADER | |
| 9 | |
| $INSUNITS | |
| 70 | |
| 6 | |
| 0 | |
| ENDSEC | |
| 0 | |
| SECTION | |
| 2 | |
| ENTITIES | |
| 0 | |
| LWPOLYLINE | |
| 8 | |
| site boundry | |
| 90 | |
| 4 | |
| 70 | |
| 1 | |
| 10 | |
| 0 | |
| 20 | |
| 0 | |
| 10 | |
| 10 | |
| 20 | |
| 0 | |
| 10 | |
| 10 | |
| 20 | |
| 5 | |
| 10 | |
| 0 | |
| 20 | |
| 5 | |
| 0 | |
| ENDSEC | |
| 0 | |
| EOF | |
| """ | |
| with tempfile.TemporaryDirectory() as tmp: | |
| path = Path(tmp) / "site.dxf" | |
| path.write_text(content) | |
| parsed = parse_dxf(path) | |
| self.assertEqual(parsed["unit"], "meters") | |
| self.assertEqual(len(parsed["boundary_candidates"]), 1) | |
| self.assertAlmostEqual(parsed["boundary_candidates"][0].area_sqm, 50) | |
| def test_parse_simple_millimeter_dxf_boundary(self): | |
| content = """0 | |
| SECTION | |
| 2 | |
| HEADER | |
| 9 | |
| $INSUNITS | |
| 70 | |
| 4 | |
| 0 | |
| ENDSEC | |
| 0 | |
| SECTION | |
| 2 | |
| ENTITIES | |
| 0 | |
| LWPOLYLINE | |
| 8 | |
| site boundary | |
| 90 | |
| 4 | |
| 70 | |
| 1 | |
| 10 | |
| 0 | |
| 20 | |
| 0 | |
| 10 | |
| 10000 | |
| 20 | |
| 0 | |
| 10 | |
| 10000 | |
| 20 | |
| 5000 | |
| 10 | |
| 0 | |
| 20 | |
| 5000 | |
| 0 | |
| ENDSEC | |
| 0 | |
| EOF | |
| """ | |
| with tempfile.TemporaryDirectory() as tmp: | |
| path = Path(tmp) / "site_mm.dxf" | |
| path.write_text(content) | |
| parsed = parse_dxf(path) | |
| self.assertEqual(parsed["unit"], "millimeters") | |
| self.assertEqual(len(parsed["boundary_candidates"]), 1) | |
| self.assertAlmostEqual(parsed["boundary_candidates"][0].area_sqm, 50) | |
| if __name__ == "__main__": | |
| unittest.main() | |