def test_compile_require_ports(self): compiler = apx.Compiler() node = apx.Node('TestNode') node.append(apx.DataType('TestType1_T', 'S(0,1000)')) node.append(apx.DataType('TestType2_T', 'a[32]')) port = node.append(apx.RequirePort('Signal1', 'C', '=255')) prog = compiler.exec(port) expected = bytes([ apx.OPCODE_UNPACK_PROG, 1, 0, 0, 0, apx.OPCODE_UNPACK_U8, ]) self.assertEqual(prog, expected) port = node.append(apx.RequirePort('Signal2', 'T[0]', '=255')) prog = compiler.exec(port) expected = bytes([ apx.OPCODE_UNPACK_PROG, 2, 0, 0, 0, apx.OPCODE_UNPACK_U16, ]) self.assertEqual(prog, expected) port = node.append( apx.RequirePort('Signal3', 'T["TestType2_T"]', '=""')) prog = compiler.exec(port) expected = bytes([ apx.OPCODE_UNPACK_PROG, 32, 0, 0, 0, apx.OPCODE_UNPACK_STR, 32, 0 ]) self.assertEqual(prog, expected)
def test_compile_record_require_port(self): compiler = apx.Compiler() node = apx.Node('TestNode') node.append(apx.DataType('SoundId_T', 'S')) node.append(apx.DataType('Volume_T', 'C')) node.append(apx.DataType('Repetitions_T', 'C')) node.append( apx.DataType( 'SoundRequest_T', '{"SoundId"T["SoundId_T"]"Volume"T["Volume_T"]"Repetitions"T["Repetitions_T"]}' )) node.append( apx.RequirePort('SoundRequest', 'T["SoundRequest_T"]', '={65535,255,255}')) prog = compiler.exec(node.find('SoundRequest')) expected = bytes([ apx.OPCODE_UNPACK_PROG, (apx.UINT16_LEN + apx.UINT8_LEN + apx.UINT8_LEN), 0, 0, 0, apx.OPCODE_RECORD_ENTER, apx.OPCODE_RECORD_SELECT ]) + "SoundId\0".encode('ascii') + bytes([ apx.OPCODE_UNPACK_U16, apx.OPCODE_RECORD_SELECT ]) + "Volume\0".encode('ascii') + bytes([ apx.OPCODE_UNPACK_U8, apx.OPCODE_RECORD_SELECT ]) + "Repetitions\0".encode('ascii') + bytes([ apx.OPCODE_UNPACK_U8, apx.OPCODE_RECORD_LEAVE, ]) self.assertEqual(prog, expected)
def test_raw_ports_2(self): node = apx.Node('TestSWC') datatype = node.append(apx.DataType('InactiveActive_T', 'C(0,3)')) self.assertIsInstance(datatype, apx.DataType) port = node.append(apx.ProvidePort('VehicleSpeed', 'S', '=65535')) self.assertIsInstance(port, apx.ProvidePort) port = node.append(apx.ProvidePort('MainBeam', 'T[0]', '=3')) self.assertIsInstance(port, apx.ProvidePort) port = node.append(apx.ProvidePort('FuelLevel', 'C')) self.assertIsInstance(port, apx.ProvidePort) port = node.append(apx.ProvidePort('ParkBrakeActive', 'T[0]', '=3')) self.assertIsInstance(port, apx.ProvidePort) port = node.append(apx.RequirePort('RheostatLevelRqst', 'C', '=255')) self.assertIsInstance(port, apx.RequirePort) port = node.append(apx.RequirePort('StrSignal', 'a[4]', '=""')) self.assertIsInstance(port, apx.RequirePort) port = node.append( apx.RequirePort('RecordSignal', '{"Name"a[8]"Id"L"Data"S[3]}', '={"",0xFFFFFFFF,{0,0,0}}')) self.assertIsInstance(port, apx.RequirePort) node.finalize(sort=False) lines = node.lines() self.assertEqual(len(lines), 9) self.assertEqual(lines[0], 'N"TestSWC"') self.assertEqual(lines[1], 'T"InactiveActive_T"C(0,3)') self.assertEqual(lines[2], 'P"VehicleSpeed"S:=65535') self.assertEqual(lines[3], 'P"MainBeam"T[0]:=3') self.assertEqual(lines[4], 'P"FuelLevel"C') self.assertEqual(lines[5], 'P"ParkBrakeActive"T[0]:=3') self.assertEqual(lines[6], 'R"RheostatLevelRqst"C:=255') self.assertEqual(lines[7], 'R"StrSignal"a[4]:=""') self.assertEqual( lines[8], 'R"RecordSignal"{"Name"a[8]"Id"L"Data"S[3]}:={"",0xFFFFFFFF,{0,0,0}}' )
def test_clone_ref_type(self): dt1 = apx.DataType('MyRef_T', 'T["MyU8_T"]') dt2 = dt1.clone() self.assertIsInstance(dt2, apx.DataType) self.assertEqual(dt2.dataElement.typeCode, apx.REFERENCE_TYPE_CODE) self.assertEqual(dt2.dataElement.typeReference, 'MyU8_T') self.assertEqual(str(dt2), 'T"MyRef_T"T["MyU8_T"]')
def test_create_typeref(self): dataType = apx.DataType('TestType_T', 'C(0,1)') elem = apx.DataElement.TypeReference(dataType) self.assertIsNone(elem.name) self.assertEqual(elem.typeCode, apx.REFERENCE_TYPE_CODE) self.assertIs(elem.typeReference, dataType) self.assertIsNone(elem.minVal) self.assertIsNone(elem.maxVal) self.assertIsNone(elem.arrayLen) self.assertIsNone(elem.elements)
def test_typeRef(self): type_list = [apx.DataType('TestType_T', 'S(0,10000)')] (dataElement, remain) = apx.DataSignature.parseDataSignature('T[0]', type_list) self.assertIsInstance(dataElement, apx.DataElement) self.assertEqual(dataElement.typeCode, apx.REFERENCE_TYPE_CODE) self.assertIs(dataElement.typeReference, type_list[0]) (dataElement, remain) = apx.DataSignature.parseDataSignature('T["TestType_T"]', type_list) self.assertIsInstance(dataElement, apx.DataElement) self.assertEqual(dataElement.typeCode, apx.REFERENCE_TYPE_CODE) self.assertEqual(dataElement.typeReference, type_list[0])
def test_reference(self): typeList = [] typeList.append(apx.DataType("TestType1", "C[8]")) #0 typeList.append(apx.DataType("TestType2", "a[18]")) #1 typeList.append(apx.DataType("TestType3", '{"Name"a[16]"ID"L}')) #2 typeList.append(apx.DataType("TestType3", 'C')) #3 typeList.append(apx.DataType("TestType4", 'S')) #4 typeList.append(apx.DataType("TestType5", 'L')) #5 dsg = apx.DataSignature('T[0]', typeList) self.assertEqual(dsg.packLen(), 8) self.assertTrue(dsg.isComplexType()) dsg = apx.DataSignature('T[1]', typeList) self.assertEqual(dsg.packLen(), 18) self.assertTrue(dsg.isComplexType()) dsg = apx.DataSignature('T[2]', typeList) self.assertEqual(dsg.packLen(), 20) self.assertTrue(dsg.isComplexType()) dsg = apx.DataSignature('T[3]', typeList) self.assertEqual(dsg.packLen(), 1) self.assertFalse(dsg.isComplexType()) dsg = apx.DataSignature('T[4]', typeList) self.assertEqual(dsg.packLen(), 2) self.assertFalse(dsg.isComplexType()) dsg = apx.DataSignature('T[5]', typeList) self.assertEqual(dsg.packLen(), 4) self.assertFalse(dsg.isComplexType())
def create_node_and_data(): node = apx.Node('TestNode') node.add_type(apx.DataType('InactiveActive_T', 'C(0,3)')) node.append(apx.ProvidePort('VehicleSpeed', 'S', '=65535')) node.append(apx.ProvidePort('MainBeam', 'T[0]', '=3')) node.append(apx.ProvidePort('TotalDistance', 'L', '=0xFFFFFFFF')) node.append( apx.ProvidePort('ComplexRecordSignal', '{"SensorData"{"x"S"y"S"z"S}"TimeStamp"L}', '={{65535,65535,65535},0xFFFFFFFF}')) node.append(apx.RequirePort('RheostatLevelRqst', 'C', '=255')) node.append(apx.RequirePort('StrSignal', 'a[8]', '=""')) node.append( apx.RequirePort('RecordSignal', '{"Name"a[8]"Id"L"Data"S[3]}', '={"",0xFFFFFFFF,{0,0,0}}')) return node
def test_compile_provide_ports(self): compiler = apx.Compiler() node = apx.Node('TestNode') node.append(apx.DataType('TestType1_T', 'C')) node.append(apx.DataType('TestType2_T', 'C[10]')) node.append(apx.DataType('TestType3_T', 'S')) node.append(apx.DataType('TestType4_T', 'S[10]')) node.append(apx.DataType('TestType5_T', 'L')) node.append(apx.DataType('TestType6_T', 'L[10]')) node.append(apx.ProvidePort('U8Signal', 'T["TestType1_T"]')) node.append(apx.ProvidePort('U8ArraySignal', 'T["TestType2_T"]')) node.append(apx.ProvidePort('U16Signal', 'T["TestType3_T"]')) node.append(apx.ProvidePort('U16ArraySignal', 'T["TestType4_T"]')) node.append(apx.ProvidePort('U32Signal', 'T["TestType5_T"]')) node.append(apx.ProvidePort('U32ArraySignal', 'T["TestType6_T"]')) prog = compiler.exec(node.find('U8Signal')) expected = bytes( [apx.OPCODE_PACK_PROG, apx.UINT8_LEN, 0, 0, 0, apx.OPCODE_PACK_U8]) self.assertEqual(prog, expected) prog = compiler.exec(node.find('U8ArraySignal')) expected = bytes([ apx.OPCODE_PACK_PROG, apx.UINT8_LEN * 10, 0, 0, 0, apx.OPCODE_PACK_U8AR, 10, 0 ]) self.assertEqual(prog, expected) prog = compiler.exec(node.find('U16Signal')) expected = bytes([ apx.OPCODE_PACK_PROG, apx.UINT16_LEN, 0, 0, 0, apx.OPCODE_PACK_U16 ]) self.assertEqual(prog, expected) prog = compiler.exec(node.find('U16ArraySignal')) expected = bytes([ apx.OPCODE_PACK_PROG, apx.UINT16_LEN * 10, 0, 0, 0, apx.OPCODE_PACK_U16AR, 10, 0 ]) self.assertEqual(prog, expected) prog = compiler.exec(node.find('U32Signal')) expected = bytes([ apx.OPCODE_PACK_PROG, apx.UINT32_LEN, 0, 0, 0, apx.OPCODE_PACK_U32 ]) self.assertEqual(prog, expected) prog = compiler.exec(node.find('U32ArraySignal')) expected = bytes([ apx.OPCODE_PACK_PROG, apx.UINT32_LEN * 10, 0, 0, 0, apx.OPCODE_PACK_U32AR, 10, 0 ]) self.assertEqual(prog, expected)
def test_load_dumped_apx_text(self): node1 = apx.Node('Simulator') node1.dataTypes.append(apx.DataType('InactiveActive_T','C(0,3)')) node1.providePorts.append(apx.ProvidePort('VehicleSpeed','S','=65535')) node1.providePorts.append(apx.ProvidePort('MainBeam','T[0]','=3')) node1.providePorts.append(apx.ProvidePort('FuelLevel','C')) node1.providePorts.append(apx.ProvidePort('ParkBrakeActive','T[0]','=3')) node1.requirePorts.append(apx.RequirePort('RheostatLevelRqst','C','=255')) self.assertFalse(node1.providePorts[0].dsg.isComplexType()) node1.finalize() context = apx.Context() context.append(node1) text=context.dumps() apx_parser = apx.Parser() node2 = apx_parser.loads(text) self.assertFalse(node2.providePorts[0].dsg.isComplexType())
def test_fileManagerWithNode(self): node = apx.Node('Simulator') node.dataTypes.append(apx.DataType('InactiveActive_T','C(0,3)')) node.append(apx.ProvidePort('VehicleSpeed','S','=65535')) node.append(apx.ProvidePort('MainBeam','T[0]','=3')) node.append(apx.ProvidePort('FuelLevel','C')) node.append(apx.ProvidePort('ParkBrakeActive','T[0]','=3')) node.append(apx.RequirePort('RheostatLevelRqst','C','=255')) nodeData = apx.NodeData(node) with apx.FileManager() as file_manager: file_manager.attachNodeData(nodeData) self.assertEqual(len(file_manager.localFileMap), 2) self.assertEqual(len(file_manager.requestedFiles), 1) file_manager.start() mockHandler = MockTransmitHandler() file_manager.onConnected(mockHandler) time.sleep(0.1) self.assertEqual(len(mockHandler.transmittedData), 4+63*2)
def test_code_generator(self): node = apx.Node("Test") node.append(apx.DataType('SoundRequest_T', '{"SoundId"S"Volume"C}')) node.append(apx.RequirePort('U8Port', 'C', '=255')) node.append(apx.RequirePort('U8ARPort', 'C[3]', '={255, 255, 255}')) node.append( apx.RequirePort('SoundRequest', 'T["SoundRequest_T"]', '={65535,255}')) node.append( apx.ProvidePort('U16ARPort', 'S[4]', '={65535, 65535, 65535, 65535}')) node.append(apx.ProvidePort('U32Port', 'L', '=4294967295')) output_dir = 'derived' output_dir_full = os.path.join(os.path.dirname(__file__), output_dir) if not os.path.exists(output_dir_full): os.makedirs(output_dir_full) time.sleep(0.1) apx.NodeGenerator().generate(output_dir_full, node) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) shutil.rmtree(output_dir_full)
def test_dumps_from_raw(self): node = apx.Node('Simulator') node.dataTypes.append(apx.DataType('InactiveActive_T','C(0,3)')) node.providePorts.append(apx.ProvidePort('VehicleSpeed','S','=65535')) node.providePorts.append(apx.ProvidePort('MainBeam','T[0]','=3')) node.providePorts.append(apx.ProvidePort('FuelLevel','C')) node.providePorts.append(apx.ProvidePort('ParkBrakeActive','T[0]','=3')) node.requirePorts.append(apx.RequirePort('RheostatLevelRqst','C','=255')) node.finalize() context = apx.Context() context.append(node) text=context.dumps() lines=re.compile(r'\r\n|\n').split(text) self.assertEqual(len(lines),9) self.assertEqual(lines[0],'APX/1.2') self.assertEqual(lines[1],'N"Simulator"') self.assertEqual(lines[2],'T"InactiveActive_T"C(0,3)') self.assertEqual(lines[3],'P"VehicleSpeed"S:=65535') self.assertEqual(lines[4],'P"MainBeam"T[0]:=3') self.assertEqual(lines[5],'P"FuelLevel"C') self.assertEqual(lines[6],'P"ParkBrakeActive"T[0]:=3') self.assertEqual(lines[7],'R"RheostatLevelRqst"C:=255') self.assertEqual(lines[8],'')
import apx node = apx.Node('Example') node.append(apx.DataType('BatteryVoltage_T', 'S')) node.append(apx.DataType('Date_T', '{"Year"C"Month"C(1,13)"Day"C(1,32)}')) node.append( apx.DataType( 'InactiveActive_T', 'C(0,3)', 'VT("InactiveActive_Inactive", "InactiveActive_Active", "InactiveActive_Error", "InactiveActive_NotAvailable")' )) node.append( apx.ProvidePort('BatteryVoltage', 'T["BatteryVoltage_T"]', '=65535')) node.append(apx.RequirePort('CurrentDate', 'T["Date_T"]', '={255, 13, 32}')) node.append( apx.RequirePort('ExteriorLightsActive', 'T["InactiveActive_T"]', '=3')) print(apx.Context().append(node).dumps())
def test_record_type(self): dt = apx.DataType('MyRecord_T', '{"Name"a[8]"Id"L"Data"S[3]}') self.assertIsInstance(dt, apx.DataType) self.assertEqual(dt.dataElement.typeCode, apx.RECORD_TYPE_CODE) self.assertEqual(str(dt), 'T"MyRecord_T"{"Name"a[8]"Id"L"Data"S[3]}')
def _processLine(self, line): parts = apx_split_line(line) if parts is None: return if len(parts) > 0: if self.cs == START_SECTION: if parts[0] == 'N': #Node Line self.cs = NODE_SECTION apxNode = apx.Node(parts[1]) self._applyNode(apxNode) else: raise apx.ParseError( 'Syntax error on line {:d}. Expected Node definition'. format(self.lineNumber, line)) elif self.cs == NODE_SECTION: if parts[0] == 'T': self.cs = TYPE_SECTION apxType = apx.DataType(parts[1], parts[2], parts[3]) self._applyType(apxType) elif parts[0] == 'P': self.cs = PROVIDE_SECTION portLine = apx.ProvidePort(parts[1], parts[2], parts[3]) self._applyPort(portLine) elif parts[0] == 'R': self.cs = REQUIRE_SECTION portLine = apx.RequirePort(parts[1], parts[2], parts[3]) self._applyPort(portLine) else: raise apx.ParseError( 'Syntax error on line {:d}: {}'.format( self.lineNumber, line)) elif self.cs == TYPE_SECTION: if parts[0] == 'T': typeLine = apx.DataType(parts[1], parts[2], parts[3]) self._applyType(typeLine) elif parts[0] == 'P': self.cs = PROVIDE_SECTION portLine = apx.ProvidePort(parts[1], parts[2], parts[3]) self._applyPort(portLine) elif parts[0] == 'R': self.cs = REQUIRE_SECTION portLine = apx.RequirePort(parts[1], parts[2], parts[3]) self._applyPort(portLine) else: raise apx.ParseError( 'Syntax error on line {:d}: {}'.format( self.lineNumber, line)) elif self.cs == PROVIDE_SECTION: if parts[0] == 'P': portLine = apx.ProvidePort(parts[1], parts[2], parts[3]) self._applyPort(portLine) elif parts[0] == 'R': self.cs = REQUIRE_SECTION portLine = apx.RequirePort(parts[1], parts[2], parts[3]) self._applyPort(portLine) elif self.cs == REQUIRE_SECTION: if parts[0] == 'R': portLine = apx.RequirePort(parts[1], parts[2], parts[3]) self._applyPort(portLine) elif parts[0] == 'P': self.cs = PROVIDE_SECTION portLine = apx.ProvidePort(parts[1], parts[2], parts[3]) self._applyPort(portLine) else: raise apx.ParseError( 'Syntax error on line {:d}: {}'.format( self.lineNumber, line)) else: raise RuntimeError("Internal parser error, line={:d}".format( self.lineNumber)) else: raise apx.ParseError('Syntax error on line {:d}: {}'.format( self.lineNumber, line))
def test_create_ref_type(self): dt = apx.DataType('MyRef_T', 'T["MyU8_T"]') self.assertIsInstance(dt, apx.DataType) self.assertEqual(dt.dataElement.typeCode, apx.REFERENCE_TYPE_CODE) self.assertEqual(dt.dataElement.typeReference, 'MyU8_T') self.assertEqual(str(dt), 'T"MyRef_T"T["MyU8_T"]')
def test_clone_uint32_type(self): dt1 = apx.DataType('MyU32_T', 'L') dt2 = dt1.clone() self.assertIsInstance(dt2, apx.DataType) self.assertEqual(dt2.dataElement.typeCode, apx.UINT32_TYPE_CODE) self.assertEqual(str(dt2), 'T"MyU32_T"L')
def test_create_uint32_type(self): dt = apx.DataType('MyU32_T', 'L') self.assertIsInstance(dt, apx.DataType) self.assertEqual(dt.dataElement.typeCode, apx.UINT32_TYPE_CODE)
def test_create_uint8_array_type(self): dt = apx.DataType('MyU8_T', 'C[8]') self.assertIsInstance(dt, apx.DataType) self.assertEqual(dt.dataElement.typeCode, apx.UINT8_TYPE_CODE) self.assertEqual(str(dt), 'T"MyU8_T"C[8]')
def test_code_generator(self): node = apx.Node("Test") node.append(apx.DataType('SoundRequest_T', '{"SoundId"S"Volume"C}')) node.append(apx.DataType('LightRequest_T', '{"LightId"S"Intensity"C}')) node.append( apx.DataType('HapticRequest_T', '{"HapticId"S"Intensity"C}')) node.append(apx.RequirePort('RU8FirstPort', 'C', '=12')) node.append(apx.RequirePort('RS16ARPort', 's[3]', '={32767, 1, 0}')) node.append(apx.RequirePort('RS32Port', 'l', '=1')) node.append(apx.RequirePort('RU8Port', 'C', '=255')) node.append(apx.RequirePort('RU8ARPort', 'C[3]', '={255, 255, 255}')) node.append( apx.RequirePort('LightRequest', 'T["LightRequest_T"]', '={65535,255}')) node.append( apx.RequirePort('SoundRequest', 'T["SoundRequest_T"]', '={65535,255}')) node.append(apx.RequirePort('RU8LastPort', 'C', '=210')) node.append( apx.ProvidePort('SoundRequestAck', 'T["SoundRequest_T"]', '={65535,255}')) node.append( apx.ProvidePort('HapticRequest', 'T["HapticRequest_T"]', '={65535,255}')) node.append(apx.ProvidePort('PS8ARPort', 'c[1]', '={1}')) node.append(apx.ProvidePort('PS8Port', 'c', '=0')) node.append( apx.ProvidePort('PU16ARPort', 'S[4]', '={65535, 65535, 65535, 65535}')) node.append(apx.ProvidePort('PU32Port', 'L', '=4294967295')) callback_map = { 'RU8Port': 'RU8Port_cb_func', 'RS16ARPort': 'RS16ARPort_cb_func', 'SoundRequest': 'SoundRequest_cb_func' } output_dir = 'derived' output_dir_full = os.path.join(os.path.dirname(__file__), output_dir) if not os.path.exists(output_dir_full): os.makedirs(output_dir_full) time.sleep(0.1) # If we want ports in the order appended; explicitly finalize the node before generator node.finalize(sort=False, compact=True) apx.NodeGenerator().generate(output_dir_full, node, callbacks=callback_map) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}_Cbk.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}_Cbk.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) node.name = "Test_compact" apx.NodeGenerator().generate(output_dir_full, node, callbacks=callback_map, compact=True) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}.c'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}.c'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) with open( os.path.join(os.path.dirname(__file__), output_dir, 'ApxNode_{0.name}_Cbk.h'.format(node)), "r") as fp: generated = fp.read() with open( os.path.join(os.path.dirname(__file__), 'expected_gen', 'ApxNode_{0.name}_Cbk.h'.format(node)), "r") as fp: expected = fp.read() self.assertEqual(expected, generated) shutil.rmtree(output_dir_full)
import apx if __name__ == '__main__': node = apx.Node('ButtonStatus') node.append(apx.DataType('PushButtonStatus_T', 'C(0,1)')) node.append(apx.DataType('VehicleMode_T', 'C(0,15)')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Back', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Down', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Enter', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Home', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Left', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Right', 'T["PushButtonStatus_T"]', '=0')) node.append( apx.ProvidePort('SWS_PushbuttonStatus_Up', 'T["PushButtonStatus_T"]', '=0')) node.append(apx.RequirePort('VehicleMode', 'T["VehicleMode_T"]', '=15')) node.finalize() apx.NodeGenerator().generate('.', node, includes=['ApxTypeDefs.h']) apx.NodeGenerator().generate('.',