def test_parse_register_data_compressed(self): """Test parsing a sample ljmmm register description.""" # Jeez. I should make this test less fragile. EXTLINK_ICON = '<img style="margin-right: -1;" src="https://ljsimpleregisterlookup.herokuapp.com/static/images/ui-icons-extlink.png" />' expected = [ { "address": 2000, "name": "FIO#(0:2)", "type": "UINT16", "type_index":"0", "devices":[ {"device":"U3", "fwmin":0}, {"device":"U6", "fwmin":0}, {"device":"T7", "fwmin":0.80}, {"device":"UE9", "fwmin":0} ], "readwrite": {"read": True, "write": True}, "tags": ["DIO"], "description": "test <a target=\"_blank\" href=\"https://labjack.com/support/\">https://labjack.com/support/</a>%s. <a target=\"_blank\" href=\"http://imgur.com/gallery/zwK7XG6\">http://imgur.com/gallery/zwK7XG6</a>%s, end." % (EXTLINK_ICON, EXTLINK_ICON), "constants": [], "streamable": False, "default": None, "isBuffer": False, "altnames": ["DIO#(0:2)", "TEST#(0:2)"], 'usesRAM': False, }, ] result = ljmmm.parse_register_data( { "address":2000, "name":"FIO#(0:2)", "type":"UINT16", "devices":[ "U3", "U6", {"device":"T7", "fwmin":0.80}, "UE9" ], "readwrite":"RW", "tags":["DIO"], "altnames":["DIO#(0:2)", "TEST#(0:2)"], "description": "test https://labjack.com/support/. http://imgur.com/gallery/zwK7XG6, end.", 'usesRAM': False }, expand_names = False ) self.assertEqual(1, len(expected)) self.assertEqual(1, len(result)) self.assertTrue(cmp(expected[0], result[0]))
def test_parse_register_data_expand_with_nothing_to_expand(self): expected = [ { "address": 5010, "name": "SPI_DATA_TX", "type": "BYTE", "type_index": "99", "devices": [ { "device": "T7", "fwmin": 0.80 }, ], "readwrite": { "read": False, "write": True }, "tags": ["SPI"], "description": "test", "constants": [], "streamable": False, "default": None, "isBuffer": True, "altnames": ["SPI_DATA_WRITE"], 'usesRAM': False, }, ] result = ljmmm.parse_register_data( { "address": 5010, "name": "SPI_DATA_TX", "type": "BYTE", "devices": [ { "device": "T7", "fwmin": 0.80 }, ], "readwrite": "W", "tags": ["SPI"], "altnames": ["SPI_DATA_WRITE"], "description": "test", "isBuffer": True, 'usesRAM': False, }, expand_names=False) self.assertIterableContentsEqual(expected, result)
def test_description_with_dots_should_not_yield_links(self): expected = [{ "address":60662, "name":"FILE_IO_LUA_SWITCH_FILE", "type":"UINT32", "type_index":"1", "devices":[ {"device":"T7", "fwmin":1.0168} ], "readwrite": {"read": True, "write": True}, "tags":["LUA", "FILE_IO"], "description":"Write any value to this register to instruct Lua scripts to switch to a new file. Lua script should periodically check LJ.CheckFileFlag() to receive instruction, then call LJ.ClearFileFlag() after file switch is complete. Useful for applications that require continuous logging in a Lua script, and on-demand file access from a host.", "constants": [], "streamable": False, "default": None, "isBuffer": False, "altnames": [], 'usesRAM': False, }] result = ljmmm.parse_register_data({ "address":60662, "name":"FILE_IO_LUA_SWITCH_FILE", "type":"UINT32", "devices":[ {"device":"T7", "fwmin":1.0168} ], "readwrite":"RW", "tags":["LUA", "FILE_IO"], "description":"Write any value to this register to instruct Lua scripts to switch to a new file. Lua script should periodically check LJ.CheckFileFlag() to receive instruction, then call LJ.ClearFileFlag() after file switch is complete. Useful for applications that require continuous logging in a Lua script, and on-demand file access from a host." }) self.assertIterableContentsEqual(expected, result) self.assertEqual(1, len(ljmmm.FIND_URLS.findall('this desc has website.org as the single link'))) self.assertEqual(1, len(ljmmm.FIND_URLS.findall('this desc has website.co.uk as the single link'))) self.assertEqual(1, len(ljmmm.FIND_URLS.findall('this desc has website.net as the single link'))) self.assertEqual(1, len(ljmmm.FIND_URLS.findall('this desc has website.edu as the single link'))) self.assertEqual(1, len(ljmmm.FIND_URLS.findall('this desc has website.gov as the single link'))) self.assertEqual(0, len(ljmmm.FIND_URLS.findall('this desc has website.fake as the not a link'))) self.assertEqual(0, len(ljmmm.FIND_URLS.findall('this desc has https://labjack.nope as the not a link')))
def test_parse_register_data_expand(self): """Test expanding a sample ljmmm register description.""" expected = [ { "address": 2000, "name": "FIO0", "type": "UINT16", "type_index":"0", "devices":[ {"device":"U3", "fwmin":0}, {"device":"U6", "fwmin":0}, {"device":"T7", "fwmin":0.80}, {"device":"UE9", "fwmin":0} ], "readwrite": {"read": True, "write": True}, "tags": ["DIO"], "description": "test", "constants": [], "streamable": False, "default": None, "isBuffer": False, "altnames": ["DIO0", "TEST0"], 'usesRAM': False, }, { "address": 2001, "name": "FIO1", "type": "UINT16", "type_index":"0", "devices":[ {"device":"U3", "fwmin":0}, {"device":"U6", "fwmin":0}, {"device":"T7", "fwmin":0.80}, {"device":"UE9", "fwmin":0} ], "readwrite": {"read": True, "write": True}, "tags": ["DIO"], "description": "test", "constants": [], "streamable": False, "default": None, "isBuffer": False, "altnames": ["DIO1", "TEST1"], 'usesRAM': False, }, { "address": 2002, "name": "FIO2", "type": "UINT16", "type_index":"0", "devices":[ {"device":"U3", "fwmin":0}, {"device":"U6", "fwmin":0}, {"device":"T7", "fwmin":0.80}, {"device":"UE9", "fwmin":0} ], "readwrite": {"read": True, "write": True}, "tags": ["DIO"], "description": "test", "constants": [], "streamable": False, "default": None, "isBuffer": False, "altnames": ["DIO2", "TEST2"], 'usesRAM': False, }, ] result = ljmmm.parse_register_data( { "address":2000, "name":"FIO#(0:2)", "type":"UINT16", "devices":[ "U3", "U6", {"device":"T7", "fwmin":0.80}, "UE9" ], "readwrite":"RW", "tags":["DIO"], "altnames":["DIO#(0:2)", "TEST#(0:2)"], "description": "test", 'usesRAM': False }, expand_names = True ) self.assertIterableContentsEqual(expected, result)