Skip to content

Commit bfe5219

Browse files
committed
Added new sanity test for Part 21 parser.
1 parent ae6f9d9 commit bfe5219

2 files changed

Lines changed: 111 additions & 1 deletion

File tree

src/exp2python/python/SCL/ConstructedDataTypes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3030
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131

32-
import sys
3332
from enum import Enum
3433
import BaseType
3534

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Copyright (c) 2021, Devon Sparks (devonsparks.com)
2+
# All rights reserved.
3+
4+
# This file is part StepClassLibrary (SCL).
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
#
9+
# Redistributions of source code must retain the above copyright notice,
10+
# this list of conditions and the following disclaimer.
11+
#
12+
# Redistributions in binary form must reproduce the above copyright notice,
13+
# this list of conditions and the following disclaimer in the documentation
14+
# and/or other materials provided with the distribution.
15+
#
16+
# Neither the name of the <ORGANIZATION> nor the names of its contributors may
17+
# be used to endorse or promote products derived from this software without
18+
# specific prior written permission.
19+
20+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
# ARE DISCLAIMED.
24+
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
25+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30+
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
import unittest
33+
from SCL.Part21 import Parser
34+
35+
ShapesSample ="""
36+
ISO-10303-21;
37+
HEADER;
38+
FILE_DESCRIPTION(('simple example file'),'1');
39+
FILE_NAME('testfile.step','1997-10-06T16:15:42',('long forgotten'),('nist'),'0','1','2');
40+
FILE_SCHEMA(('example_schema'));
41+
ENDSEC;
42+
DATA;
43+
#0=SQUARE('Square9',.BROWN.,13,15.,51.);
44+
#1=CIRCLE('Circle8',.ORANGE.,19,12.);
45+
#2=TRIANGLE('Triangle7',.BLACK.,67,84.,60.,25.);
46+
#3=LINE(#6,#7);
47+
#4=SHAPE('Shape4',.WHITE.,83);
48+
#5=RECTANGLE('Rectangle8',.BROWN.,66,78.,95.);
49+
#6=CARTESIAN_POINT(11.,67.,54.);
50+
#7=CARTESIAN_POINT(1.,2.,3.);
51+
ENDSEC;
52+
END-ISO-10303-21;
53+
"""
54+
55+
class TestSample(unittest.TestCase):
56+
def setUp(self):
57+
self.parser = Parser()
58+
def tearDown(self):
59+
self.parser = None
60+
61+
62+
class TestShapesParse(TestSample):
63+
"""
64+
Tests whether we're able to parse the shapes sample at all
65+
"""
66+
def test_parse(self):
67+
model = self.parser.parse(ShapesSample)
68+
self.assertIsNotNone(model)
69+
70+
71+
class TestShapesHeader(TestSample):
72+
"""
73+
Test basic structure and payload of Header section
74+
"""
75+
def test_header_name(self):
76+
model = self.parser.parse(ShapesSample)
77+
self.assertEqual(model.header.file_name.params[0][0], "testfile.step")
78+
79+
def test_header_schema(self):
80+
model = self.parser.parse(ShapesSample)
81+
self.assertEqual(model.header.file_schema.params[0][0][0], "example_schema")
82+
83+
84+
class TestShapesData(TestSample):
85+
"""
86+
Test basic structure and shape of data section
87+
"""
88+
def test_data_section_form(self):
89+
model = self.parser.parse(ShapesSample)
90+
self.assertEqual(len(model.sections), 1)
91+
self.assertEqual(len(model.sections[0].entities), 8)
92+
93+
94+
class TestEntity(TestSample):
95+
"""
96+
Test structure and contents of several entities within the DATA section
97+
"""
98+
def test_line(self):
99+
model = self.parser.parse(ShapesSample)
100+
line = model.sections[0].entities[3]
101+
self.assertEqual(line.type_name, "LINE")
102+
self.assertEqual(line.ref, "#3")
103+
self.assertEqual(line.params[0], ["#6", "#7"])
104+
105+
def test_rectangle8(self):
106+
model = self.parser.parse(ShapesSample)
107+
rect8 = model.sections[0].entities[5]
108+
self.assertEqual(rect8.type_name, "RECTANGLE")
109+
self.assertEqual(rect8.ref, "#5")
110+
self.assertEqual(rect8.params[0], ['Rectangle8', '.BROWN.', 66, 78.0, 95.0])
111+

0 commit comments

Comments
 (0)