diff --git a/tests/spydrnet/compare/tests/test_compare_netlists.py b/tests/spydrnet/compare/tests/test_compare_netlists.py index 9a74125c..7eb865c7 100644 --- a/tests/spydrnet/compare/tests/test_compare_netlists.py +++ b/tests/spydrnet/compare/tests/test_compare_netlists.py @@ -11,7 +11,9 @@ class TestCompareNetlists(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.dir_of_edif_netlists = Path(sdn.example_netlists_path, "EDIF_netlists") - cls.dir_of_verilog_netlists = Path(sdn.example_netlists_path, "verilog_netlists") + cls.dir_of_verilog_netlists = Path( + sdn.example_netlists_path, "verilog_netlists" + ) cls.edif_files = sorted(Path.glob(cls.dir_of_edif_netlists, "*.edf.zip")) cls.verilog_files = sorted(Path.glob(cls.dir_of_verilog_netlists, "*.v.zip")) @@ -34,16 +36,16 @@ def test_large_verilog(self): if Path(filename).stat().st_size <= 1024 * 10: continue self.compare_parser_and_composer(filename, ii, "v") - #assert False + # assert False def test_small_verilog(self): for ii, filename in enumerate(self.verilog_files): if Path(filename).stat().st_size > 1024 * 10: continue self.compare_parser_and_composer(filename, ii, "v") - #assert False + # assert False - def compare_parser_and_composer(self,filename, ii, target_format_extension = None): + def compare_parser_and_composer(self, filename, ii, target_format_extension=None): with self.subTest(i=ii): if Path("temp").exists(): shutil.rmtree("temp") @@ -53,9 +55,14 @@ def compare_parser_and_composer(self,filename, ii, target_format_extension = Non orig_netlist = sdn.parse(filename) basename_without_final_ext = Path(Path(filename).name).stem if target_format_extension is None: - composer_filename = Path(tempdirname, basename_without_final_ext) + composer_filename = Path( + tempdirname, basename_without_final_ext + ) else: - composer_filename = Path(tempdirname, basename_without_final_ext + "." + target_format_extension) + composer_filename = Path( + tempdirname, + basename_without_final_ext + "." + target_format_extension, + ) orig_netlist.compose(composer_filename) print(composer_filename) composer_netlist = sdn.parse(composer_filename) @@ -71,16 +78,18 @@ def test_large_verilog_to_edif(self): if Path(filename).stat().st_size <= 1024 * 10: continue self.compare_parser_and_composer(filename, ii, "edf") - #assert False + # assert False - @unittest.skip("currently not working properly for the number of cables on some examples please use with caution") + @unittest.skip( + "currently not working properly for the number of cables on some examples please use with caution" + ) def test_small_verilog_to_edif(self): for ii, filename in enumerate(self.verilog_files): if Path(filename).stat().st_size > 1024 * 10: continue self.compare_parser_and_composer(filename, ii, "edf") - #assert False - + # assert False + def test_empty_netlists(self): nl1 = sdn.ir.Netlist() nl2 = sdn.ir.Netlist() @@ -88,5 +97,5 @@ def test_empty_netlists(self): comp.compare() -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/spydrnet/compare/tests/test_composers.py b/tests/spydrnet/compare/tests/test_composers.py index 764af741..9328a309 100644 --- a/tests/spydrnet/compare/tests/test_composers.py +++ b/tests/spydrnet/compare/tests/test_composers.py @@ -1,6 +1,7 @@ import unittest import spydrnet as sdn + class TestComposers(unittest.TestCase): def test_compose(self): netlist = sdn.Netlist() diff --git a/tests/spydrnet/composers/eblif/tests/test_eblif_composer.py b/tests/spydrnet/composers/eblif/tests/test_eblif_composer.py index 8a444591..8374f8ed 100644 --- a/tests/spydrnet/composers/eblif/tests/test_eblif_composer.py +++ b/tests/spydrnet/composers/eblif/tests/test_eblif_composer.py @@ -8,49 +8,68 @@ Test the EBLIF composer. The best way I can think to do this is to parse a netlist, compose it, then parse it again to see if anything changed. It should all be the same """ + class TestEBLIFComposer(unittest.TestCase): def setUp(self): - self.netlist_1 = sdn.parse(Path(example_netlists_path, 'eblif_netlists', "toggle.eblif.zip")) - self.definition_list = ["INV","BUFG","FDRE","IBUF","OBUF","toggle", "logic-gate_0"] - sdn.compose(self.netlist_1,"temp_for_composer_test.eblif") - sdn.compose(self.netlist_1,"temp_for_composer_test_no_blackbox.eblif",write_blackbox=False) + self.netlist_1 = sdn.parse( + Path(example_netlists_path, "eblif_netlists", "toggle.eblif.zip") + ) + self.definition_list = [ + "INV", + "BUFG", + "FDRE", + "IBUF", + "OBUF", + "toggle", + "logic-gate_0", + ] + sdn.compose(self.netlist_1, "temp_for_composer_test.eblif") + sdn.compose( + self.netlist_1, + "temp_for_composer_test_no_blackbox.eblif", + write_blackbox=False, + ) self.netlist_2 = sdn.parse("temp_for_composer_test.eblif") self.netlist_3 = sdn.parse("temp_for_composer_test_no_blackbox.eblif") os.remove("temp_for_composer_test.eblif") os.remove("temp_for_composer_test_no_blackbox.eblif") - + def test_netlist_name(self): - self.assertEqual(self.netlist_1.name,self.netlist_2.name) - + self.assertEqual(self.netlist_1.name, self.netlist_2.name) + def test_top_instance(self): - self.assertEqual(self.netlist_1.top_instance.name,self.netlist_2.top_instance.name) - + self.assertEqual( + self.netlist_1.top_instance.name, self.netlist_2.top_instance.name + ) + def test_instances(self): instances_1 = list(instance.name for instance in self.netlist_1.get_instances()) instances_2 = list(instance.name for instance in self.netlist_2.get_instances()) instances_1.sort() instances_2.sort() - self.assertEqual(instances_1,instances_2) - self.assertEqual(len(instances_1),len(instances_2)) - + self.assertEqual(instances_1, instances_2) + self.assertEqual(len(instances_1), len(instances_2)) + def test_definitions(self): - definitions_1 = list(definition.name for definition in self.netlist_1.get_definitions()) - definitions_2 = list(definition.name for definition in self.netlist_2.get_definitions()) + definitions_1 = list( + definition.name for definition in self.netlist_1.get_definitions() + ) + definitions_2 = list( + definition.name for definition in self.netlist_2.get_definitions() + ) definitions_1.sort() definitions_2.sort() - self.assertEqual(definitions_1,definitions_2) - self.assertEqual(len(definitions_1),len(definitions_2)) - + self.assertEqual(definitions_1, definitions_2) + self.assertEqual(len(definitions_1), len(definitions_2)) + def test_cables(self): cables_1 = list(cable.name for cable in self.netlist_1.get_cables()) cables_2 = list(cable.name for cable in self.netlist_2.get_cables()) cables_1.sort() cables_2.sort() - self.assertEqual(cables_1,cables_2) - self.assertEqual(len(cables_1),len(cables_2)) + self.assertEqual(cables_1, cables_2) + self.assertEqual(len(cables_1), len(cables_2)) - # TODO add wires and connections tests # test the composing of each individual part - \ No newline at end of file diff --git a/tests/spydrnet/composers/edif/tests/test_edifify_names.py b/tests/spydrnet/composers/edif/tests/test_edifify_names.py index 6389b874..4be21d2e 100644 --- a/tests/spydrnet/composers/edif/tests/test_edifify_names.py +++ b/tests/spydrnet/composers/edif/tests/test_edifify_names.py @@ -4,7 +4,6 @@ class TestEdififyNames(unittest.TestCase): - def test_simple_conversion(self): ed = EdififyNames() l = [] @@ -19,16 +18,15 @@ def test_invalid_name(self): i = sdn.Instance() i.name = "*this_is+an$*`id[0:3]" l = [i] - assert ed.make_valid( - i, l) == "&_this_is_an___id_0_3_" + assert ed.make_valid(i, l) == "&_this_is_an___id_0_3_" def test_duplicate_name(self): ed = EdififyNames() l = [] i = sdn.Instance() - i.name = 'name' + i.name = "name" i2 = sdn.Instance() - i2.name = 'name' + i2.name = "name" l = [i, i2] assert ed.make_valid(i2, l) == "name_sdn_1_" @@ -36,11 +34,11 @@ def test_duplicate_number_increment(self): ed = EdififyNames() l = [] i = sdn.Instance() - i.name = 'name' + i.name = "name" i_duplicate = sdn.Instance() - i_duplicate.name = 'name' + i_duplicate.name = "name" i2 = sdn.Instance() - i2.name = 'name_sdn_1_' + i2.name = "name_sdn_1_" l = [i, i2, i_duplicate] assert ed.make_valid(i_duplicate, l) == "name_sdn_2_" @@ -50,9 +48,9 @@ def test_length(self): test_str = "" answer_str = "" for _ in range(ed.name_length_target + 5): - test_str = test_str + 'a' + test_str = test_str + "a" for _ in range(ed.name_length_target): - answer_str = answer_str + 'a' + answer_str = answer_str + "a" i = sdn.Instance() i.name = test_str l = [i] @@ -64,9 +62,9 @@ def test_length_2(self): test_str = "$" answer_str = "&_" for _ in range(ed.name_length_target + 5): - test_str = test_str + 'a' + test_str = test_str + "a" for _ in range(ed.name_length_target - 2): - answer_str = answer_str + 'a' + answer_str = answer_str + "a" i = sdn.Instance() i.name = test_str l = [i] @@ -77,27 +75,27 @@ def test_length_3(self): l = [] instance_1 = sdn.Instance() - name_1 = '&_' + name_1 = "&_" for _ in range(ed.name_length_target - 2): - name_1 = name_1 + 'a' + name_1 = name_1 + "a" instance_1.name = name_1 instance_2 = sdn.Instance() - name_2 = '&_' + name_2 = "&_" for _ in range(ed.name_length_target - 9): - name_2 = name_2 + 'a' - name_2 = name_2 + '_sdn_1_' + name_2 = name_2 + "a" + name_2 = name_2 + "_sdn_1_" instance_2.name = name_2 - test_str = '$' - answer_str = '&_' + test_str = "$" + answer_str = "&_" for _ in range(ed.name_length_target + 5): - test_str = test_str + 'a' + test_str = test_str + "a" for _ in range(ed.name_length_target - 9): - answer_str = answer_str + 'a' + answer_str = answer_str + "a" - answer_str = answer_str + '_sdn_2_' + answer_str = answer_str + "_sdn_2_" instance_3 = sdn.Instance() instance_3.name = test_str diff --git a/tests/spydrnet/composers/edif/tests/test_topological_sort.py b/tests/spydrnet/composers/edif/tests/test_topological_sort.py index 70eefa32..9c85d8ee 100644 --- a/tests/spydrnet/composers/edif/tests/test_topological_sort.py +++ b/tests/spydrnet/composers/edif/tests/test_topological_sort.py @@ -4,9 +4,9 @@ class TestTopologicalSort(unittest.TestCase): - def test_top_sort(self): ce = ComposeEdif() + def library_dependence(library): depend_set = set() for definition in library.definitions: @@ -33,7 +33,7 @@ def library_dependence(library): lib_b.name = "lib_b" definition_b = lib_b.create_definition() definition_b.name = "def_b" - + instance_b = definition_b.create_child() instance_b.name = "relies_on_lib_a" instance_b.reference = definition_a @@ -58,7 +58,7 @@ def library_dependence(library): print("dependencies") for lib in libraries: - print(lib.name, end = "") + print(lib.name, end="") print(" relies on") for l in library_dependence(lib): print("\t" + l.name) @@ -73,4 +73,4 @@ def library_dependence(library): for l in libraries: found_libraries.add(l) for l_dep in library_dependence(l): - assert l_dep in found_libraries \ No newline at end of file + assert l_dep in found_libraries diff --git a/tests/spydrnet/composers/verilog/tests/test_composer.py b/tests/spydrnet/composers/verilog/tests/test_composer.py index 0bab56f0..488ee003 100644 --- a/tests/spydrnet/composers/verilog/tests/test_composer.py +++ b/tests/spydrnet/composers/verilog/tests/test_composer.py @@ -6,11 +6,13 @@ from pathlib import Path import zipfile -class TestVerilogComposer(unittest.TestCase): +class TestVerilogComposer(unittest.TestCase): @classmethod def setUpClass(cls) -> None: - cls.dir_of_verilog_netlists = Path(sdn.example_netlists_path, "verilog_netlists") + cls.dir_of_verilog_netlists = Path( + sdn.example_netlists_path, "verilog_netlists" + ) cls.verilog_files = sorted(Path.glob(cls.dir_of_verilog_netlists, "*.v.zip")) @unittest.skip("Test takes a long time right now.") @@ -24,25 +26,34 @@ def test_large_verilog_compose(self): if zipfile.is_zipfile(filepath): with tempfile.TemporaryDirectory() as tempdirectory: # try: - print("*********************"+filepath.name+"*********************") - # vp = sdn.parsers.verilog.parser.VerilogParser.from_filename(os.path.join(directory, filename)) - # netlist = vp.parse() - netlist = parsers.parse(filepath) - composers.compose(netlist, Path(tempdirectory).joinpath(filepath.name + "-spydrnet.v")) - #comp.run(netlist,"temp2/"+filename[:len(filename)-6] + "-spydrnet.v") - # comp.run(netlist,os.path.join(tempdirectory, filename[:len(filename)-6] + "-spydrnet.v")) - i+=1 - print("pass") - # except Exception as identifier: - # print("FAIL") - # print(identifier) - # errors += 1 + print( + "*********************" + + filepath.name + + "*********************" + ) + # vp = sdn.parsers.verilog.parser.VerilogParser.from_filename(os.path.join(directory, filename)) + # netlist = vp.parse() + netlist = parsers.parse(filepath) + composers.compose( + netlist, + Path(tempdirectory).joinpath(filepath.name + "-spydrnet.v"), + ) + # comp.run(netlist,"temp2/"+filename[:len(filename)-6] + "-spydrnet.v") + # comp.run(netlist,os.path.join(tempdirectory, filename[:len(filename)-6] + "-spydrnet.v")) + i += 1 + print("pass") + # except Exception as identifier: + # print("FAIL") + # print(identifier) + # errors += 1 else: continue - print("processed",i,"errors", errors) - - assert errors == 0, "there were errors while parsing and composing files. Please see the output." + print("processed", i, "errors", errors) + + assert ( + errors == 0 + ), "there were errors while parsing and composing files. Please see the output." def test_small_verilog_compose(self): i = 0 @@ -55,60 +66,70 @@ def test_small_verilog_compose(self): if zipfile.is_zipfile(filepath): with tempfile.TemporaryDirectory() as tempdirectory: # try: - print("*********************"+filepath.name+"*********************") - # vp = sdn.parsers.verilog.parser.VerilogParser.from_filename(os.path.join(directory, filename)) - # netlist = vp.parse() - netlist = parsers.parse(filepath) - composers.compose(netlist, Path(tempdirectory).joinpath(filepath.name + "-spydrnet.v")) - #comp.run(netlist,"temp2/"+filename[:len(filename)-6] + "-spydrnet.v") - # comp.run(netlist,os.path.join(tempdirectory, filename[:len(filename)-6] + "-spydrnet.v")) - i+=1 - print("pass") - # except Exception as identifier: - # print("FAIL") - # print(identifier) - # errors += 1 + print( + "*********************" + + filepath.name + + "*********************" + ) + # vp = sdn.parsers.verilog.parser.VerilogParser.from_filename(os.path.join(directory, filename)) + # netlist = vp.parse() + netlist = parsers.parse(filepath) + composers.compose( + netlist, + Path(tempdirectory).joinpath(filepath.name + "-spydrnet.v"), + ) + # comp.run(netlist,"temp2/"+filename[:len(filename)-6] + "-spydrnet.v") + # comp.run(netlist,os.path.join(tempdirectory, filename[:len(filename)-6] + "-spydrnet.v")) + i += 1 + print("pass") + # except Exception as identifier: + # print("FAIL") + # print(identifier) + # errors += 1 else: continue - print("processed",i,"errors", errors) - - assert errors == 0, "there were errors while parsing and composing files. Please see the output." + print("processed", i, "errors", errors) + + assert ( + errors == 0 + ), "there were errors while parsing and composing files. Please see the output." def test_definition_list_option(self): for filename in Path.glob(self.dir_of_verilog_netlists, "*4bitadder.v.zip"): with tempfile.TemporaryDirectory() as tempdirectory: netlist = parsers.parse(filename) - out_file = Path( - tempdirectory, Path(filename).name + "-spydrnet.v") - composers.compose(netlist, out_file, definition_list=['adder']) + out_file = Path(tempdirectory, Path(filename).name + "-spydrnet.v") + composers.compose(netlist, out_file, definition_list=["adder"]) with open(out_file, "r") as fp: lines = fp.readlines() print(len(lines)) - m = list(filter(lambda x: x.startswith('module'), lines)) + m = list(filter(lambda x: x.startswith("module"), lines)) self.assertGreater(len(m), 0, "Adder module not written") self.assertLess(len(m), 2, "Failed to write only definition_list") return - raise AssertionError("Adder design not found " + - "definition_list options not tested,") + raise AssertionError( + "Adder design not found " + "definition_list options not tested," + ) def test_write_blackbox_option(self): for filename in Path.glob(self.dir_of_verilog_netlists, "*4bitadder.v.zip"): print(filename) with tempfile.TemporaryDirectory() as tempdirectory: netlist = parsers.parse(filename) - out_file = Path( - tempdirectory, Path(filename).name + "-spydrnet.v") + out_file = Path(tempdirectory, Path(filename).name + "-spydrnet.v") composers.compose(netlist, out_file, write_blackbox=False) with open(out_file, "r") as fp: lines = fp.readlines() print(len(lines)) - m = list(filter(lambda x: x.startswith('module'), lines)) + m = list(filter(lambda x: x.startswith("module"), lines)) self.assertGreater(len(m), 0, "Adder module not written") - self.assertLess(len(m), 2, "Failed to write only definition_list" + - "%s" % m) + self.assertLess( + len(m), 2, "Failed to write only definition_list" + "%s" % m + ) return - raise AssertionError("definition_list options not test," + - "Adder design not found") + raise AssertionError( + "definition_list options not test," + "Adder design not found" + ) diff --git a/tests/spydrnet/composers/verilog/tests/test_composer_unit.py b/tests/spydrnet/composers/verilog/tests/test_composer_unit.py index 2c808207..204a92fd 100644 --- a/tests/spydrnet/composers/verilog/tests/test_composer_unit.py +++ b/tests/spydrnet/composers/verilog/tests/test_composer_unit.py @@ -1,8 +1,8 @@ -#Copyright 2021 -#Author Dallin Skouson -#see the license for details +# Copyright 2021 +# Author Dallin Skouson +# see the license for details # -#Tests the verilog composers functions and output +# Tests the verilog composers functions and output from collections import OrderedDict import unittest @@ -11,12 +11,13 @@ from spydrnet.composers.verilog.composer import Composer from collections import OrderedDict -class TestVerilogComposerUnit(unittest.TestCase): +class TestVerilogComposerUnit(unittest.TestCase): class TestFile: - '''represents a file (has a write function for the composer) + """represents a file (has a write function for the composer) can be used as a drop in replacement for the composer file.write function - saves all written stuff to a string''' + saves all written stuff to a string""" + def __init__(self): self.written = "" @@ -26,7 +27,7 @@ def write(self, text): def clear(self): self.written = "" - def compare(self, text, should_match = True): + def compare(self, text, should_match=True): self.written = self.written.lstrip() if (text == self.written) == should_match: return True @@ -42,7 +43,6 @@ def compare(self, text, should_match = True): print("\n") return False - def initialize_tests(self): composer = Composer() composer.file = self.TestFile() @@ -90,7 +90,6 @@ def initialize_instance_port_connections(self, instance, definition): single_bit_cable.is_downto = True single_bit_cable.create_wire() - multi_bit_port = ref_def.create_port() multi_bit_port.is_downto = True multi_bit_port.create_pins(4) @@ -112,7 +111,6 @@ def initialize_instance_port_connections(self, instance, definition): multi_bit_cable.name = "multi_bit_cable" multi_bit_cable.is_downto = True - concatenated_port = ref_def.create_port() concatenated_port.create_pins(4) concatenated_port.name = "concatenated_port" @@ -125,44 +123,90 @@ def initialize_instance_port_connections(self, instance, definition): cable.name = "cc_" + str(i) ccs.append(cable) - single_bit_cable.wires[0].connect_pin(instance.pins[single_bit_port.pins[0]]) for i in range(4): multi_bit_cable.wires[i].connect_pin(instance.pins[multi_bit_port.pins[i]]) - multi_bit_cable.wires[i].connect_pin(instance.pins[multi_bit_port_offset.pins[i]]) + multi_bit_cable.wires[i].connect_pin( + instance.pins[multi_bit_port_offset.pins[i]] + ) ccs[i].wires[0].connect_pin(instance.pins[concatenated_port.pins[i]]) for i in range(2): multi_bit_cable.wires[i].connect_pin(instance.pins[partial_port.pins[i]]) - single_bit_expected = "." + single_bit_port.name + "(" + single_bit_cable.name + ")" - - multi_bit_expected = "." + multi_bit_port.name + "(" + multi_bit_cable.name + "[" + str(len(multi_bit_cable.wires) - 1 + multi_bit_cable.lower_index) + ":" + \ - str(multi_bit_cable.lower_index) + "]"")" - - offset_expected = "." + multi_bit_port_offset.name + "(" + multi_bit_cable.name + "[" + str(len(multi_bit_cable.wires) - 1 + multi_bit_cable.lower_index) + ":" + \ - str(multi_bit_cable.lower_index) + "]"")" - - partial_expected = "." + partial_port.name + "(" + multi_bit_cable.name + "[1:0])" - - concatenated_expected = "." + concatenated_port.name + "({" + ccs[3].name + ', ' + ccs[2].name + ', ' + ccs[1].name + ', ' + ccs[0].name + "})" - - return single_bit_port, single_bit_expected, \ - multi_bit_port, multi_bit_expected, \ - multi_bit_port_offset, offset_expected, \ - partial_port, partial_expected,\ - concatenated_port, concatenated_expected\ + single_bit_expected = ( + "." + single_bit_port.name + "(" + single_bit_cable.name + ")" + ) + + multi_bit_expected = ( + "." + + multi_bit_port.name + + "(" + + multi_bit_cable.name + + "[" + + str(len(multi_bit_cable.wires) - 1 + multi_bit_cable.lower_index) + + ":" + + str(multi_bit_cable.lower_index) + + "]" + ")" + ) + + offset_expected = ( + "." + + multi_bit_port_offset.name + + "(" + + multi_bit_cable.name + + "[" + + str(len(multi_bit_cable.wires) - 1 + multi_bit_cable.lower_index) + + ":" + + str(multi_bit_cable.lower_index) + + "]" + ")" + ) + + partial_expected = ( + "." + partial_port.name + "(" + multi_bit_cable.name + "[1:0])" + ) + + concatenated_expected = ( + "." + + concatenated_port.name + + "({" + + ccs[3].name + + ", " + + ccs[2].name + + ", " + + ccs[1].name + + ", " + + ccs[0].name + + "})" + ) + + return ( + single_bit_port, + single_bit_expected, + multi_bit_port, + multi_bit_expected, + multi_bit_port_offset, + offset_expected, + partial_port, + partial_expected, + concatenated_port, + concatenated_expected, + ) def test_write_header(self): composer = self.initialize_tests() netlist = sdn.Netlist() netlist.name = "Netlist_name" composer._write_header(netlist) - assert composer.file.compare("//Generated from netlist by SpyDrNet\n//netlist name: Netlist_name\n") + assert composer.file.compare( + "//Generated from netlist by SpyDrNet\n//netlist name: Netlist_name\n" + ) def test_write_brackets_single_bit(self): - #def _write_brackets(self, bundle, low_index, high_index): + # def _write_brackets(self, bundle, low_index, high_index): composer = self.initialize_tests() port = sdn.Port() @@ -202,10 +246,10 @@ def test_write_brackets_single_bit(self): composer._write_brackets(cable, 0, 0) assert composer.file.compare("") composer.file.clear() - #none of these should write because they are all single bit. + # none of these should write because they are all single bit. def test_write_brackets_single_bit_offset(self): - #def _write_brackets(self, bundle, low_index, high_index): + # def _write_brackets(self, bundle, low_index, high_index): composer = self.initialize_tests() port = sdn.Port() @@ -248,7 +292,7 @@ def test_write_brackets_single_bit_offset(self): composer._write_brackets(cable, 4, 4) assert composer.file.compare("") composer.file.clear() - #none of these should write because they are all single bit. + # none of these should write because they are all single bit. def test_write_brackets_multi_bit(self): composer = self.initialize_tests() @@ -262,9 +306,9 @@ def test_write_brackets_multi_bit(self): port.name = port_name cable.name = cable_name - port.create_pins(4) #input [3:0] my_input; + port.create_pins(4) # input [3:0] my_input; port.is_downto = True - cable.create_wires(4) #wire [3:0] my_wire; + cable.create_wires(4) # wire [3:0] my_wire; cable.is_downto = True composer._write_brackets(port, None, None) @@ -305,7 +349,6 @@ def test_write_brackets_multi_bit(self): assert composer.file.compare("[2:1]") composer.file.clear() - def test_write_brackets_multi_bit_offset(self): composer = self.initialize_tests() @@ -318,10 +361,10 @@ def test_write_brackets_multi_bit_offset(self): port.name = port_name cable.name = cable_name - port.create_pins(4) #input [3:0] my_input; + port.create_pins(4) # input [3:0] my_input; port.is_downto = True port.lower_index = 4 - cable.create_wires(4) #wire [3:0] my_wire; + cable.create_wires(4) # wire [3:0] my_wire; cable.is_downto = True cable.lower_index = 4 @@ -364,16 +407,15 @@ def test_write_brackets_multi_bit_offset(self): composer.file.clear() def test_write_brackets_fail(self): - pass #we should add some tests to test out of bounds on the brackets. + pass # we should add some tests to test out of bounds on the brackets. def test_write_brackets_defining(self): - composer = self.initialize_tests() def initialize_bundle(bundle, offset, width): if isinstance(bundle, sdn.Port): bundle.create_pins(width) - else: #it's a cable + else: # it's a cable bundle.create_wires(width) bundle.is_downto = True bundle.lower_index = offset @@ -402,7 +444,7 @@ def initialize_bundle(bundle, offset, width): def test_write_name(self): composer = self.initialize_tests() - o = sdn.Cable() #Type of this shouldn't really matter + o = sdn.Cable() # Type of this shouldn't really matter valid_names = ["basic_name", "\\escaped ", "\\fads#@%!$!@#%$[0:4320] "] for n in valid_names: o.name = n @@ -428,12 +470,18 @@ def test_write_instance_port(self): instance = definition.create_child() instance.name = "ports_test" - single_bit_port, single_bit_expected, \ - multi_bit_port, multi_bit_expected, \ - multi_bit_port_offset, offset_expected, \ - partial_port, partial_expected, \ - concatenated_port, concatenated_expected\ - = self.initialize_instance_port_connections(instance, definition) + ( + single_bit_port, + single_bit_expected, + multi_bit_port, + multi_bit_expected, + multi_bit_port_offset, + offset_expected, + partial_port, + partial_expected, + concatenated_port, + concatenated_expected, + ) = self.initialize_instance_port_connections(instance, definition) composer._write_instance_port(instance, single_bit_port) assert composer.file.compare(single_bit_expected) @@ -458,11 +506,17 @@ def test_write_instance_port(self): composer._write_instance_ports(instance) expected = "(\n" first = True - expected_strs = [single_bit_expected, multi_bit_expected, offset_expected, partial_expected, concatenated_expected] + expected_strs = [ + single_bit_expected, + multi_bit_expected, + offset_expected, + partial_expected, + concatenated_expected, + ] for i in expected_strs: if not first: expected += ",\n" - expected += " " + expected += " " expected += i first = False expected += "\n );" @@ -476,8 +530,8 @@ def test_write_instance_parameters(self): ref_def = definition.library.create_definition() instance.reference = ref_def - expected1, expected2 =self.initialize_instance_parameters(instance) - #instance["VERILOG.Parameters"]["no_value"] = None #always has value? + expected1, expected2 = self.initialize_instance_parameters(instance) + # instance["VERILOG.Parameters"]["no_value"] = None #always has value? composer._write_instance_parameter("key", "value") assert composer.file.compare(expected1) @@ -487,7 +541,6 @@ def test_write_instance_parameters(self): assert composer.file.compare(expected2) composer.file.clear() - # composer._write_instance_parameter("no_value", None) # expected3 = ".key()" # assert composer.file.compare(expected2) @@ -497,7 +550,6 @@ def test_write_instance_parameters(self): expected = "#(\n " + expected1 + ",\n " + expected2 + "\n )\n" assert composer.file.compare(expected) - def test_write_full_instance(self): composer = self.initialize_tests() definition = self.initialize_definition() @@ -505,28 +557,50 @@ def test_write_full_instance(self): instance.name = "instance_test" expected1, expected2 = self.initialize_instance_parameters(instance) - parameters_expected = "#(\n " + expected1 + ",\n " + expected2 + "\n )\n" - single_bit_port, single_bit_expected, \ - multi_bit_port, multi_bit_expected, \ - multi_bit_port_offset, offset_expected, \ - partial_port, partial_expected, \ - concatenated_port, concatenated_expected\ - = self.initialize_instance_port_connections(instance, definition) + parameters_expected = ( + "#(\n " + expected1 + ",\n " + expected2 + "\n )\n" + ) + ( + single_bit_port, + single_bit_expected, + multi_bit_port, + multi_bit_expected, + multi_bit_port_offset, + offset_expected, + partial_port, + partial_expected, + concatenated_port, + concatenated_expected, + ) = self.initialize_instance_port_connections(instance, definition) port_expected = "\n (\n" first = True - expected_strs = [single_bit_expected, multi_bit_expected, offset_expected, partial_expected, concatenated_expected] + expected_strs = [ + single_bit_expected, + multi_bit_expected, + offset_expected, + partial_expected, + concatenated_expected, + ] for i in expected_strs: if not first: port_expected += ",\n" - port_expected += " " + port_expected += " " port_expected += i first = False port_expected += "\n );" composer._write_module_body_instance(instance) - expected = instance.reference.name + " " + parameters_expected + " " + instance.name + port_expected + "\n" + expected = ( + instance.reference.name + + " " + + parameters_expected + + " " + + instance.name + + port_expected + + "\n" + ) assert composer.file.compare(expected) def test_write_module_header(self): @@ -548,7 +622,11 @@ def test_write_module_header(self): port.direction = sdn.Port.Direction.IN composer._write_module_header(definition) - expected = "module " + definition.name + "\n#(\n parameter key = value,\n parameter no_default\n)(\n my_port,\n my_port2\n);\n\n" + expected = ( + "module " + + definition.name + + "\n#(\n parameter key = value,\n parameter no_default\n)(\n my_port,\n my_port2\n);\n\n" + ) assert composer.file.compare(expected) def test_write_module_ports_header_and_body_alias(self): @@ -569,13 +647,16 @@ def test_write_module_ports_header_and_body_alias(self): c2.wires[0].connect_pin(port_alias.pins[1]) composer._write_module_header_port(port_alias) - assert composer.file.compare("." + port_alias.name + "({"+ c2.name + ", " + c1.name +"})") + assert composer.file.compare( + "." + port_alias.name + "({" + c2.name + ", " + c1.name + "})" + ) composer.file.clear() composer._write_module_body_port(port_alias) - assert composer.file.compare("input " + c1.name + ";\n " + "input " + c2.name + ";\n") + assert composer.file.compare( + "input " + c1.name + ";\n " + "input " + c2.name + ";\n" + ) composer.file.clear() - def test_write_module_ports_header_and_body_multi(self): composer = self.initialize_tests() definition = self.initialize_definition() @@ -598,7 +679,6 @@ def test_write_module_ports_header_and_body_multi(self): assert composer.file.compare("output [3:0]" + port_multi.name + ";\n") composer.file.clear() - def test_write_module_ports_header_and_body_disconnect(self): composer = self.initialize_tests() definition = self.initialize_definition() @@ -611,23 +691,21 @@ def test_write_module_ports_header_and_body_disconnect(self): assert composer.file.compare(port_disconnect.name) composer.file.clear() composer._write_module_body_port(port_disconnect) - assert composer.file.compare("inout " + port_disconnect.name + ';\n') + assert composer.file.compare("inout " + port_disconnect.name + ";\n") composer.file.clear() def test_write_module_body_cables(self): composer = self.initialize_tests() definition = self.initialize_definition() - cable = definition.create_cable(name = "test_cable", is_downto = True) + cable = definition.create_cable(name="test_cable", is_downto=True) cable.create_wires(4) composer._write_module_body_cable(cable) assert composer.file.compare("wire [3:0]" + cable.name + ";\n") - def test_assignment_single_bit(self): pass def test_assignment_multi_bit(self): pass - diff --git a/tests/spydrnet/global_state/tests/test_global_callback.py b/tests/spydrnet/global_state/tests/test_global_callback.py index 933d8dc5..86e87bad 100644 --- a/tests/spydrnet/global_state/tests/test_global_callback.py +++ b/tests/spydrnet/global_state/tests/test_global_callback.py @@ -20,83 +20,188 @@ def setUp(self) -> None: self.callcount = 0 self.callcount2 = 0 - def mycall(self, a1, a2, ka = 0): + def mycall(self, a1, a2, ka=0): self.callcount += 1 - assert(a1 is self.arg1) - assert(a2 is self.arg2) - assert(ka is self.kwarg) + assert a1 is self.arg1 + assert a2 is self.arg2 + assert ka is self.kwarg - def mycall2(self, a1, a2, ka = 0): + def mycall2(self, a1, a2, ka=0): self.callcount2 += 1 - assert(a1 is self.arg1) - assert(a2 is self.arg2) - assert(ka is self.kwarg) + assert a1 is self.arg1 + assert a2 is self.arg2 + assert ka is self.kwarg def test_cable_add_wire(self): - self.call_for_each(gc._container_cable_add_wire, gc.register_cable_add_wire, gc._call_cable_add_wire, gc.deregister_cable_add_wire) + self.call_for_each( + gc._container_cable_add_wire, + gc.register_cable_add_wire, + gc._call_cable_add_wire, + gc.deregister_cable_add_wire, + ) def test_cable_remove_wire(self): - self.call_for_each(gc._container_cable_remove_wire, gc.register_cable_remove_wire, gc._call_cable_remove_wire, gc.deregister_cable_remove_wire) + self.call_for_each( + gc._container_cable_remove_wire, + gc.register_cable_remove_wire, + gc._call_cable_remove_wire, + gc.deregister_cable_remove_wire, + ) def test_definition_add_port(self): - self.call_for_each(gc._container_definition_add_port, gc.register_definition_add_port, gc._call_definition_add_port, gc.deregister_definition_add_port) + self.call_for_each( + gc._container_definition_add_port, + gc.register_definition_add_port, + gc._call_definition_add_port, + gc.deregister_definition_add_port, + ) def test_definition_remove_port(self): - self.call_for_each(gc._container_definition_remove_port, gc.register_definition_remove_port, gc._call_definition_remove_port, gc.deregister_definition_remove_port) + self.call_for_each( + gc._container_definition_remove_port, + gc.register_definition_remove_port, + gc._call_definition_remove_port, + gc.deregister_definition_remove_port, + ) def test_definition_add_child(self): - self.call_for_each(gc._container_definition_add_child, gc.register_definition_add_child, gc._call_definition_add_child, gc.deregister_definition_add_child) + self.call_for_each( + gc._container_definition_add_child, + gc.register_definition_add_child, + gc._call_definition_add_child, + gc.deregister_definition_add_child, + ) def test_definition_remove_child(self): - self.call_for_each(gc._container_definition_remove_child, gc.register_definition_remove_child, gc._call_definition_remove_child, gc.deregister_definition_remove_child) + self.call_for_each( + gc._container_definition_remove_child, + gc.register_definition_remove_child, + gc._call_definition_remove_child, + gc.deregister_definition_remove_child, + ) def test_definition_add_cable(self): - self.call_for_each(gc._container_definition_add_cable, gc.register_definition_add_cable, gc._call_definition_add_cable, gc.deregister_definition_add_cable) + self.call_for_each( + gc._container_definition_add_cable, + gc.register_definition_add_cable, + gc._call_definition_add_cable, + gc.deregister_definition_add_cable, + ) def test_definition_remove_cable(self): - self.call_for_each(gc._container_definition_remove_cable, gc.register_definition_remove_cable, gc._call_definition_remove_cable, gc.deregister_definition_remove_cable) + self.call_for_each( + gc._container_definition_remove_cable, + gc.register_definition_remove_cable, + gc._call_definition_remove_cable, + gc.deregister_definition_remove_cable, + ) def test_instance_reference(self): - self.call_for_each(gc._container_instance_reference, gc.register_instance_reference, gc._call_instance_reference, gc.deregister_instance_reference) + self.call_for_each( + gc._container_instance_reference, + gc.register_instance_reference, + gc._call_instance_reference, + gc.deregister_instance_reference, + ) def test_library_add_definition(self): - self.call_for_each(gc._container_library_add_definition, gc.register_library_add_definition, gc._call_library_add_definition, gc.deregister_library_add_definition) + self.call_for_each( + gc._container_library_add_definition, + gc.register_library_add_definition, + gc._call_library_add_definition, + gc.deregister_library_add_definition, + ) def test_library_remove_definition(self): - self.call_for_each(gc._container_library_remove_definition, gc.register_library_remove_definition, gc._call_library_remove_definition, gc.deregister_library_remove_definition) + self.call_for_each( + gc._container_library_remove_definition, + gc.register_library_remove_definition, + gc._call_library_remove_definition, + gc.deregister_library_remove_definition, + ) def test_netlist_top_instance(self): - self.call_for_each(gc._container_netlist_top_instance, gc.register_netlist_top_instance, gc._call_netlist_top_instance, gc.deregister_netlist_top_instance) + self.call_for_each( + gc._container_netlist_top_instance, + gc.register_netlist_top_instance, + gc._call_netlist_top_instance, + gc.deregister_netlist_top_instance, + ) def test_netlist_add_library(self): - self.call_for_each(gc._container_netlist_add_library, gc.register_netlist_add_library, gc._call_netlist_add_library, gc.deregister_netlist_add_library) + self.call_for_each( + gc._container_netlist_add_library, + gc.register_netlist_add_library, + gc._call_netlist_add_library, + gc.deregister_netlist_add_library, + ) def test_netlist_remove_library(self): - self.call_for_each(gc._container_netlist_remove_library, gc.register_netlist_remove_library, gc._call_netlist_remove_library, gc.deregister_netlist_remove_library) + self.call_for_each( + gc._container_netlist_remove_library, + gc.register_netlist_remove_library, + gc._call_netlist_remove_library, + gc.deregister_netlist_remove_library, + ) def test_port_add_pin(self): - self.call_for_each(gc._container_port_add_pin, gc.register_port_add_pin, gc._call_port_add_pin, gc.deregister_port_add_pin) + self.call_for_each( + gc._container_port_add_pin, + gc.register_port_add_pin, + gc._call_port_add_pin, + gc.deregister_port_add_pin, + ) def test_port_remove_pin(self): - self.call_for_each(gc._container_port_remove_pin, gc.register_port_remove_pin, gc._call_port_remove_pin, gc.deregister_port_remove_pin) + self.call_for_each( + gc._container_port_remove_pin, + gc.register_port_remove_pin, + gc._call_port_remove_pin, + gc.deregister_port_remove_pin, + ) def test_wire_connect_pin(self): - self.call_for_each(gc._container_wire_connect_pin, gc.register_wire_connect_pin, gc._call_wire_connect_pin, gc.deregister_wire_connect_pin) + self.call_for_each( + gc._container_wire_connect_pin, + gc.register_wire_connect_pin, + gc._call_wire_connect_pin, + gc.deregister_wire_connect_pin, + ) def test_wire_disconnect_pin(self): - self.call_for_each(gc._container_wire_disconnect_pin, gc.register_wire_disconnect_pin, gc._call_wire_disconnect_pin, gc.deregister_wire_disconnect_pin) + self.call_for_each( + gc._container_wire_disconnect_pin, + gc.register_wire_disconnect_pin, + gc._call_wire_disconnect_pin, + gc.deregister_wire_disconnect_pin, + ) def test_dictionary_delete(self): - self.call_for_each(gc._container_dictionary_delete, gc.register_dictionary_delete, gc._call_dictionary_delete, gc.deregister_dictionary_delete) + self.call_for_each( + gc._container_dictionary_delete, + gc.register_dictionary_delete, + gc._call_dictionary_delete, + gc.deregister_dictionary_delete, + ) def test_dictionary_pop(self): - self.call_for_each(gc._container_dictionary_pop, gc.register_dictionary_pop, gc._call_dictionary_pop, gc.deregister_dictionary_pop) - + self.call_for_each( + gc._container_dictionary_pop, + gc.register_dictionary_pop, + gc._call_dictionary_pop, + gc.deregister_dictionary_pop, + ) + def test_dictionary_add(self): - self.call_for_each(gc._container_dictionary_set, gc.register_dictionary_set, gc._call_dictionary_set, gc.deregister_dictionary_set) + self.call_for_each( + gc._container_dictionary_set, + gc.register_dictionary_set, + gc._call_dictionary_set, + gc.deregister_dictionary_set, + ) def call_for_each(self, container, register, call, deregister): - ''' + """ general strategy: check to make sure the _container is empty register a function @@ -107,7 +212,7 @@ def call_for_each(self, container, register, call, deregister): check to make sure the function was deregistered call the function check to make sure the funciton was not called - ''' + """ assert self.mycall not in container assert self.mycall2 not in container register(self.mycall) @@ -123,4 +228,4 @@ def call_for_each(self, container, register, call, deregister): deregister(self.mycall2) assert self.mycall2 not in container call(self.arg1, self.arg2, ka=self.kwarg) - assert self.callcount == 1 and self.callcount2 == 2 \ No newline at end of file + assert self.callcount == 1 and self.callcount2 == 2 diff --git a/tests/spydrnet/global_state/tests/test_global_service.py b/tests/spydrnet/global_state/tests/test_global_service.py index 4911ec0d..1e895f7f 100644 --- a/tests/spydrnet/global_state/tests/test_global_service.py +++ b/tests/spydrnet/global_state/tests/test_global_service.py @@ -1,6 +1,7 @@ import unittest import spydrnet as sdn + class TestGlobalServiceWithoutPlugins(unittest.TestCase): @classmethod def setUpClass(cls) -> None: @@ -13,6 +14,7 @@ def tearDownClass(cls) -> None: def test_double_register_lookup(self): from spydrnet.global_state.global_service import register_lookup + register_lookup("TEST", None) self.assertRaises(ValueError, register_lookup, "TEST", None) @@ -21,11 +23,13 @@ def test_lookup_library(self): library_name = library.name lib1 = next(self.netlist.get_libraries(library_name)) self.assertEqual(library, lib1) - lib2 = next(self.netlist.get_libraries(library_name, key='EDIF.identifier')) + lib2 = next(self.netlist.get_libraries(library_name, key="EDIF.identifier")) self.assertEqual(library, lib2) lib3 = next(sdn.get_libraries(self.netlist, library_name)) self.assertEqual(library, lib3) - lib4 = next(sdn.get_libraries(self.netlist, library_name, key='EDIF.identifier')) + lib4 = next( + sdn.get_libraries(self.netlist, library_name, key="EDIF.identifier") + ) self.assertEqual(library, lib4) def test_lookup_definition(self): @@ -34,19 +38,25 @@ def test_lookup_definition(self): definition_name = definition.name def1 = next(self.netlist.get_definitions(definition_name)) self.assertEqual(definition, def1) - def2 = next(self.netlist.get_definitions(definition_name, key='EDIF.identifier')) + def2 = next( + self.netlist.get_definitions(definition_name, key="EDIF.identifier") + ) self.assertEqual(definition, def2) def3 = next(sdn.get_definitions(self.netlist, definition_name)) self.assertEqual(definition, def3) - def4 = next(sdn.get_definitions(self.netlist, definition_name, key='EDIF.identifier')) + def4 = next( + sdn.get_definitions(self.netlist, definition_name, key="EDIF.identifier") + ) self.assertEqual(definition, def4) def5 = next(library.get_definitions(definition_name)) self.assertEqual(definition, def5) - def6 = next(library.get_definitions(definition_name, key='EDIF.identifier')) + def6 = next(library.get_definitions(definition_name, key="EDIF.identifier")) self.assertEqual(definition, def6) def7 = next(sdn.get_definitions(library, definition_name)) self.assertEqual(definition, def7) - def8 = next(sdn.get_definitions(library, definition_name, key='EDIF.identifier')) + def8 = next( + sdn.get_definitions(library, definition_name, key="EDIF.identifier") + ) self.assertEqual(definition, def8) def test_lookup_port_cables_instances(self): diff --git a/tests/spydrnet/ir/tests/__init__.py b/tests/spydrnet/ir/tests/__init__.py index 101786e3..a7223972 100644 --- a/tests/spydrnet/ir/tests/__init__.py +++ b/tests/spydrnet/ir/tests/__init__.py @@ -1,4 +1,3 @@ from pathlib import Path data_dir = Path(Path(Path(__file__).parent, "data")).absolute() - diff --git a/tests/spydrnet/ir/tests/test_bundle.py b/tests/spydrnet/ir/tests/test_bundle.py index 0d4665df..6abd65a2 100644 --- a/tests/spydrnet/ir/tests/test_bundle.py +++ b/tests/spydrnet/ir/tests/test_bundle.py @@ -10,10 +10,16 @@ def setUp(self) -> None: self.bundle = Bundle() def test_constructor(self): - self.assertIsInstance(self.bundle, FirstClassElement, "Bundle is not an element.") - self.assertTrue(self.bundle, "Constructor returns None type or empty collection.") + self.assertIsInstance( + self.bundle, FirstClassElement, "Bundle is not an element." + ) + self.assertTrue( + self.bundle, "Constructor returns None type or empty collection." + ) bundle2 = Bundle() - self.assertNotEqual(self.bundle, bundle2, "Unique objects are considered equal.") + self.assertNotEqual( + self.bundle, bundle2, "Unique objects are considered equal." + ) def test_definition(self): self.assertIsNone(self.bundle.definition) diff --git a/tests/spydrnet/ir/tests/test_cable.py b/tests/spydrnet/ir/tests/test_cable.py index 3039f934..df8cbf21 100644 --- a/tests/spydrnet/ir/tests/test_cable.py +++ b/tests/spydrnet/ir/tests/test_cable.py @@ -53,4 +53,4 @@ def test_scalar_false(self): cable = sdn.Cable() cable.create_wire() cable.create_wire() - self.assertTrue('is_scalar: False;' in cable.__str__()) + self.assertTrue("is_scalar: False;" in cable.__str__()) diff --git a/tests/spydrnet/ir/tests/test_definition.py b/tests/spydrnet/ir/tests/test_definition.py index 8fe4b007..a9df5f72 100644 --- a/tests/spydrnet/ir/tests/test_definition.py +++ b/tests/spydrnet/ir/tests/test_definition.py @@ -9,10 +9,16 @@ def setUp(self): self.definition = sdn.Definition() def test_constructor(self): - self.assertIsInstance(self.definition, FirstClassElement, "Definition is not an element.") - self.assertTrue(self.definition, "Constructor returns None type or empty collection.") + self.assertIsInstance( + self.definition, FirstClassElement, "Definition is not an element." + ) + self.assertTrue( + self.definition, "Constructor returns None type or empty collection." + ) definition2 = sdn.Definition() - self.assertNotEqual(self.definition, definition2, "Unique objects are considered equal.") + self.assertNotEqual( + self.definition, definition2, "Unique objects are considered equal." + ) @unittest.expectedFailure def test_assign_library(self): @@ -49,7 +55,7 @@ def test_remove_port(self): def test_remove_multiple_ports(self): port = self.definition.create_port() port_2 = self.definition.create_port() - self.definition.remove_ports_from([port,port_2]) + self.definition.remove_ports_from([port, port_2]) self.assertFalse(port in self.definition.ports) self.assertFalse(port_2 in self.definition.ports) self.assertIsNone(port.definition) @@ -163,22 +169,31 @@ def test_remove_children_from(self): self.assertEqual(instance_included.parent, self.definition) def test_is_leaf(self): - self.assertTrue(self.definition.is_leaf()), "Empty definition is not considered a leaf cell" + self.assertTrue( + self.definition.is_leaf() + ), "Empty definition is not considered a leaf cell" self.definition.create_port() - self.assertTrue(self.definition.is_leaf()), "Empty definition with a port is not considered a leaf cell" + self.assertTrue( + self.definition.is_leaf() + ), "Empty definition with a port is not considered a leaf cell" self.definition.create_cable() - self.assertFalse(self.definition.is_leaf()), "Definition with a cable is considered a leaf cell" + self.assertFalse( + self.definition.is_leaf() + ), "Definition with a cable is considered a leaf cell" self.definition.remove_cables_from(self.definition.cables) self.definition.create_child() - self.assertFalse(self.definition.is_leaf()), "Definition with a child instance is considered a leaf cell" + self.assertFalse( + self.definition.is_leaf() + ), "Definition with a child instance is considered a leaf cell" self.definition.create_cable() - self.assertFalse(self.definition.is_leaf()), "Definition with a cable and child instance is considered a leaf" \ - " cell" + self.assertFalse( + self.definition.is_leaf() + ), "Definition with a cable and child instance is considered a leaf" " cell" def test_library_name(self): definition = sdn.Definition() library = sdn.Library() library.add_definition(definition) - self.assertTrue('Library.name undefined' in definition.__str__()) - library.name = 'library' - self.assertTrue('Library.name \'library\'' in definition.__str__()) + self.assertTrue("Library.name undefined" in definition.__str__()) + library.name = "library" + self.assertTrue("Library.name 'library'" in definition.__str__()) diff --git a/tests/spydrnet/ir/tests/test_element.py b/tests/spydrnet/ir/tests/test_element.py index 0f05baae..729022d6 100644 --- a/tests/spydrnet/ir/tests/test_element.py +++ b/tests/spydrnet/ir/tests/test_element.py @@ -14,15 +14,15 @@ def test_constructor(self): self.assertNotEqual(element1, element2, "Unique objects are considered equal.") def test_dictionary(self): - self.assertFalse('NAME' in self.element) - self.element['NAME'] = "TestName" - self.assertTrue('NAME' in self.element) + self.assertFalse("NAME" in self.element) + self.element["NAME"] = "TestName" + self.assertTrue("NAME" in self.element) for key in self.element: self.assertEqual(self.element[key], "TestName") - del self.element['NAME'] - self.assertFalse('NAME' in self.element) - self.element['NAME'] = "DifferentName" - name = self.element.pop('NAME') + del self.element["NAME"] + self.assertFalse("NAME" in self.element) + self.element["NAME"] = "DifferentName" + name = self.element.pop("NAME") self.assertEqual(name, "DifferentName") def test_name(self): @@ -41,5 +41,5 @@ def test_del_name(self): self.assertFalse(".NAME" in self.element) def test_data_view(self): - self.element['NAME'] = "TestName" - self.assertEqual(self.element.data, {'NAME': 'TestName'}) + self.element["NAME"] = "TestName" + self.assertEqual(self.element.data, {"NAME": "TestName"}) diff --git a/tests/spydrnet/ir/tests/test_innerpin.py b/tests/spydrnet/ir/tests/test_innerpin.py index 2d5240f8..d582ae7e 100644 --- a/tests/spydrnet/ir/tests/test_innerpin.py +++ b/tests/spydrnet/ir/tests/test_innerpin.py @@ -19,4 +19,4 @@ def test_port(self): @unittest.expectedFailure def test_port_set(self): - self.pin.port = None \ No newline at end of file + self.pin.port = None diff --git a/tests/spydrnet/ir/tests/test_instance.py b/tests/spydrnet/ir/tests/test_instance.py index ebf071e0..d5de7ea4 100644 --- a/tests/spydrnet/ir/tests/test_instance.py +++ b/tests/spydrnet/ir/tests/test_instance.py @@ -9,9 +9,13 @@ def setUp(self) -> None: self.instance = sdn.Instance() def test_constructor(self): - self.assertIsInstance(self.instance, FirstClassElement, "Instance should extend element") + self.assertIsInstance( + self.instance, FirstClassElement, "Instance should extend element" + ) instance2 = sdn.Instance() - self.assertNotEqual(self.instance, instance2, "Unique objects are considered equal") + self.assertNotEqual( + self.instance, instance2, "Unique objects are considered equal" + ) def test_reference_assignment(self): definition = sdn.Definition() @@ -148,7 +152,7 @@ def test_reference_removal(self): self.assertIsNone(outer_pin2.inner_pin) def test_is_top_instance(self): - netlist = sdn.load_example_netlist_by_name('toggle') + netlist = sdn.load_example_netlist_by_name("toggle") self.assertTrue(netlist.top_instance.is_top_instance) original_top_instance = netlist.top_instance random_instance = next(netlist.get_instances()) @@ -160,14 +164,14 @@ def test_reference_name_is_none(self): definition = sdn.Definition() instance = sdn.Instance() instance.reference = definition - self.assertTrue('reference definition.name undefined' in instance.__str__()) + self.assertTrue("reference definition.name undefined" in instance.__str__()) def test_reference_name_is_not_none(self): - netlist = sdn.load_example_netlist_by_name('toggle') - out_reg = next(netlist.get_instances('*out_reg*')) + netlist = sdn.load_example_netlist_by_name("toggle") + out_reg = next(netlist.get_instances("*out_reg*")) instance = sdn.Instance() instance.reference = out_reg.reference - self.assertTrue('reference definition.name \'FDRE\'' in instance.__str__()) + self.assertTrue("reference definition.name 'FDRE'" in instance.__str__()) def test_instance_parent_name_none(self): definition = sdn.Definition() @@ -176,26 +180,24 @@ def test_instance_parent_name_none(self): self.assertTrue("parent definition.name undefined" in instance.__str__()) def test_instance_parent_name_is_not_none(self): - netlist = sdn.load_example_netlist_by_name('toggle') - out_reg = next(netlist.get_instances('*out_reg*')) + netlist = sdn.load_example_netlist_by_name("toggle") + out_reg = next(netlist.get_instances("*out_reg*")) instance = sdn.Instance() out_reg.reference.add_child(instance) - self.assertTrue('parent definition.name \'FDRE\'' in instance.__str__()) + self.assertTrue("parent definition.name 'FDRE'" in instance.__str__()) def test_instance_is_leaf_but_no_reference(self): instance = sdn.Instance() self.assertFalse(instance.is_leaf()) def test_instance_is_unique(self): - definition = sdn.Definition(name='a_definition') + definition = sdn.Definition(name="a_definition") instance_3 = sdn.Instance() definition.add_child(instance_3) - instance_1 = sdn.Instance(name='instance_1') + instance_1 = sdn.Instance(name="instance_1") instance_1.reference = definition self.assertTrue(instance_1.is_unique()) - instance_2 = sdn.Instance(name='instance_2') + instance_2 = sdn.Instance(name="instance_2") instance_2.reference = definition self.assertFalse(instance_1.is_unique()) self.assertFalse(instance_2.is_unique()) - - \ No newline at end of file diff --git a/tests/spydrnet/ir/tests/test_library.py b/tests/spydrnet/ir/tests/test_library.py index f44c2d2b..1f3a97a3 100644 --- a/tests/spydrnet/ir/tests/test_library.py +++ b/tests/spydrnet/ir/tests/test_library.py @@ -9,10 +9,16 @@ def setUp(self): self.library = sdn.Library() def test_constructor(self): - self.assertIsInstance(self.library, FirstClassElement, "Netlist is not an element.") - self.assertTrue(self.library, "Constructor return None type or empty collection") + self.assertIsInstance( + self.library, FirstClassElement, "Netlist is not an element." + ) + self.assertTrue( + self.library, "Constructor return None type or empty collection" + ) library2 = sdn.Netlist() - self.assertNotEqual(self.library, library2, "Unique objects are considered equal.") + self.assertNotEqual( + self.library, library2, "Unique objects are considered equal." + ) def test_definitions_set(self): definition1 = self.library.create_definition() @@ -62,10 +68,10 @@ def test_remove_definitions_from(self): def test_no_parent_netlist(self): library = sdn.Library() - self.assertTrue('parent netlist undefined' in library.__str__()) + self.assertTrue("parent netlist undefined" in library.__str__()) def test_no_parent_netlist_name(self): netlist = sdn.Netlist() library = sdn.Library() netlist.add_library(library) - self.assertTrue('parent netlist.name undefined' in library.__str__()) + self.assertTrue("parent netlist.name undefined" in library.__str__()) diff --git a/tests/spydrnet/ir/tests/test_netlist.py b/tests/spydrnet/ir/tests/test_netlist.py index 506929f7..71056dd7 100644 --- a/tests/spydrnet/ir/tests/test_netlist.py +++ b/tests/spydrnet/ir/tests/test_netlist.py @@ -4,15 +4,22 @@ from spydrnet.ir import FirstClassElement from spydrnet.uniquify import uniquify + class TestNetlist(unittest.TestCase): def setUp(self): self.netlist = sdn.Netlist() def test_constructor(self): - self.assertIsInstance(self.netlist, FirstClassElement, "Netlist is not an element.") - self.assertTrue(self.netlist, "Constructor return None type or empty collection") + self.assertIsInstance( + self.netlist, FirstClassElement, "Netlist is not an element." + ) + self.assertTrue( + self.netlist, "Constructor return None type or empty collection" + ) netlist2 = sdn.Netlist() - self.assertNotEqual(self.netlist, netlist2, "Unique objects are considered equal.") + self.assertNotEqual( + self.netlist, netlist2, "Unique objects are considered equal." + ) def test_libraries(self): self.assertEqual(len(tuple(self.netlist.libraries)), 0) @@ -78,8 +85,8 @@ def test_remove_libraries_from(self): self.assertEqual(library_included.netlist, self.netlist) def test_top_instance_name(self): - netlist = sdn.load_example_netlist_by_name('toggle') - self.assertTrue('top_instance.name \'toggle\'' in netlist.__str__()) + netlist = sdn.load_example_netlist_by_name("toggle") + self.assertTrue("top_instance.name 'toggle'" in netlist.__str__()) def test_set_top_instance_using_instance(self): netlist = sdn.Netlist() @@ -94,7 +101,7 @@ def test_set_top_instance_using_definition(self): self.assertTrue(netlist.top_instance.reference is definition) def test_is_unique(self): - example_name = 'unique_challenge' + example_name = "unique_challenge" netlist = sdn.load_example_netlist_by_name(example_name) self.assertFalse(netlist.is_unique()) uniquify(netlist) diff --git a/tests/spydrnet/ir/tests/test_outerpin.py b/tests/spydrnet/ir/tests/test_outerpin.py index 9fa93ee5..a9027bfe 100644 --- a/tests/spydrnet/ir/tests/test_outerpin.py +++ b/tests/spydrnet/ir/tests/test_outerpin.py @@ -30,4 +30,4 @@ def test_hash(self): instance = sdn.Instance() outer_pin1 = sdn.OuterPin.from_instance_and_inner_pin(instance, inner_pin) outer_pin2 = sdn.OuterPin.from_instance_and_inner_pin(instance, inner_pin) - self.assertEqual(hash(outer_pin1), hash(outer_pin2)) \ No newline at end of file + self.assertEqual(hash(outer_pin1), hash(outer_pin2)) diff --git a/tests/spydrnet/ir/tests/test_pin.py b/tests/spydrnet/ir/tests/test_pin.py index c49448b8..f73a43be 100644 --- a/tests/spydrnet/ir/tests/test_pin.py +++ b/tests/spydrnet/ir/tests/test_pin.py @@ -23,4 +23,4 @@ def test_wire_set(self): def test_no_wire(self): pin = Pin() - self.assertTrue('Wire connected undefined' in pin.__str__()) + self.assertTrue("Wire connected undefined" in pin.__str__()) diff --git a/tests/spydrnet/ir/tests/test_port.py b/tests/spydrnet/ir/tests/test_port.py index a20ac25b..43d3e857 100644 --- a/tests/spydrnet/ir/tests/test_port.py +++ b/tests/spydrnet/ir/tests/test_port.py @@ -31,7 +31,7 @@ def test_direction(self): for ii in range(4): self.port.direction = ii self.assertEqual(self.port.direction.value, ii) - directions = ['undefined', 'in', 'out', 'inout'] + directions = ["undefined", "in", "out", "inout"] for direction in directions: self.port.direction = direction self.assertEqual(self.port.direction.name.lower(), direction.lower()) diff --git a/tests/spydrnet/ir/tests/test_print.py b/tests/spydrnet/ir/tests/test_print.py index 9f3c73b5..1b7aa64f 100644 --- a/tests/spydrnet/ir/tests/test_print.py +++ b/tests/spydrnet/ir/tests/test_print.py @@ -4,16 +4,15 @@ class TestPrint(unittest.TestCase): - - netlist = sdn.Netlist(name='netlist') - cable = sdn.Cable(name='cable', is_downto=False) + netlist = sdn.Netlist(name="netlist") + cable = sdn.Cable(name="cable", is_downto=False) instance = sdn.Instance() print(netlist) netlist.top_instance = instance print(netlist) print(cable) print(instance) - library = netlist.create_library(name='lib') + library = netlist.create_library(name="lib") print(library) definition = sdn.Definition() print(definition) diff --git a/tests/spydrnet/ir/tests/test_shortcuts.py b/tests/spydrnet/ir/tests/test_shortcuts.py index 4320eb7f..6f1264d7 100644 --- a/tests/spydrnet/ir/tests/test_shortcuts.py +++ b/tests/spydrnet/ir/tests/test_shortcuts.py @@ -11,154 +11,184 @@ from spydrnet.ir import Library from spydrnet.ir import Port + class TestShortcuts(unittest.TestCase): def test_hRef_shortcut(self): item = Instance("myCable") def2 = Definition("Hello") item.reference = def2 hr = HRef(item) - self.assertEqual(hr.item.name,item.name,'Href item shorcut error') - + self.assertEqual(hr.item.name, item.name, "Href item shorcut error") def test_netlist_top_instance_definition_shortcut(self): - top_definition = Definition('this is my name') + top_definition = Definition("this is my name") netlist = Netlist() netlist.top_instance = top_definition - self.assertEqual(netlist.top_instance.reference.name,top_definition.name,'Netlist\'s top instance\'s shorcut error') + self.assertEqual( + netlist.top_instance.reference.name, + top_definition.name, + "Netlist's top instance's shorcut error", + ) def test_if_leaf_shortcut(self): instance = Instance() definition = Definition() instance.reference = definition - self.assertEqual(definition.is_leaf(), instance.is_leaf(), 'is_leaf shortcut error') + self.assertEqual( + definition.is_leaf(), instance.is_leaf(), "is_leaf shortcut error" + ) definition.create_cable() instance.reference = definition - self.assertEqual(definition.is_leaf(), instance.is_leaf(), 'is_leaf shortcut error') + self.assertEqual( + definition.is_leaf(), instance.is_leaf(), "is_leaf shortcut error" + ) def test_wire_index_shortcut(self): cable = Cable() cable.create_wires(3) wire = Wire() - cable.add_wire(wire,1) - self.assertEqual(wire.cable.wires.index(wire), wire.index(), 'wire index shorcut error') - self.assertEqual(wire.index(), 1, 'wire index shorcut error') + cable.add_wire(wire, 1) + self.assertEqual( + wire.cable.wires.index(wire), wire.index(), "wire index shorcut error" + ) + self.assertEqual(wire.index(), 1, "wire index shorcut error") wire2 = Wire() - cable.add_wire(wire2,3) - self.assertEqual(wire2.cable.wires.index(wire2), wire2.index(), 'wire index shorcut error') - self.assertEqual(wire2.index(), 3, 'wire index shorcut error') + cable.add_wire(wire2, 3) + self.assertEqual( + wire2.cable.wires.index(wire2), wire2.index(), "wire index shorcut error" + ) + self.assertEqual(wire2.index(), 3, "wire index shorcut error") def test_name_init_shortcut(self): - d = Definition('d_name') - self.assertEqual(d.name, 'd_name', 'Definition name init shorcut error') - l = Library('l_name') - self.assertEqual(l.name, 'l_name', 'Library name init shorcut error') - n = Netlist('n_name') - self.assertEqual(n.name, 'n_name', 'Netlist name init shorcut error') - i = Instance('i_name') - self.assertEqual(i.name, 'i_name', 'Instance name init shorcut error') - c = Cable('c_name') - self.assertEqual(c.name, 'c_name', 'Cable name init shorcut error') - p = Port('p_name') - self.assertEqual(p.name, 'p_name', 'Port name init shorcut error') + d = Definition("d_name") + self.assertEqual(d.name, "d_name", "Definition name init shorcut error") + l = Library("l_name") + self.assertEqual(l.name, "l_name", "Library name init shorcut error") + n = Netlist("n_name") + self.assertEqual(n.name, "n_name", "Netlist name init shorcut error") + i = Instance("i_name") + self.assertEqual(i.name, "i_name", "Instance name init shorcut error") + c = Cable("c_name") + self.assertEqual(c.name, "c_name", "Cable name init shorcut error") + p = Port("p_name") + self.assertEqual(p.name, "p_name", "Port name init shorcut error") def test_cable_shortcut(self): - c = Cable('c_name', None, False, True, 2) - self.assertEqual(c.name, 'c_name', 'Cable name init shorcut error') - self.assertEqual(c.is_downto, False, 'Cable is_downto init shorcut error') - self.assertEqual(c.is_scalar, True, 'Cable is_scalar init shorcut error') - self.assertEqual(c.lower_index, 2, 'Cable lower_index init shorcut error') - - c2 = Cable(is_scalar = False) - self.assertEqual(c2.name, None, 'Cable name init shorcut error') - self.assertEqual(c2.is_downto, True, 'Cable is_downto init shorcut error') - self.assertEqual(c2.is_scalar, False, 'Cable is_scalar init shorcut error') - self.assertEqual(c2.lower_index, 0, 'Cable lower_index init shorcut error') - + c = Cable("c_name", None, False, True, 2) + self.assertEqual(c.name, "c_name", "Cable name init shorcut error") + self.assertEqual(c.is_downto, False, "Cable is_downto init shorcut error") + self.assertEqual(c.is_scalar, True, "Cable is_scalar init shorcut error") + self.assertEqual(c.lower_index, 2, "Cable lower_index init shorcut error") + + c2 = Cable(is_scalar=False) + self.assertEqual(c2.name, None, "Cable name init shorcut error") + self.assertEqual(c2.is_downto, True, "Cable is_downto init shorcut error") + self.assertEqual(c2.is_scalar, False, "Cable is_scalar init shorcut error") + self.assertEqual(c2.lower_index, 0, "Cable lower_index init shorcut error") def test_port_shortcut(self): - p = Port('p_name', None, False, True, 4) + p = Port("p_name", None, False, True, 4) - self.assertEqual(p.name, 'p_name', 'Port name init shorcut error') - self.assertEqual(p.is_downto, False, 'Port is_downto init shorcut error') - self.assertEqual(p.is_scalar, True, 'Port is_scalar init shorcut error') - self.assertEqual(p.lower_index, 4, 'Port lower_index init shorcut error') + self.assertEqual(p.name, "p_name", "Port name init shorcut error") + self.assertEqual(p.is_downto, False, "Port is_downto init shorcut error") + self.assertEqual(p.is_scalar, True, "Port is_scalar init shorcut error") + self.assertEqual(p.lower_index, 4, "Port lower_index init shorcut error") - p2 = Port(is_downto = False) - self.assertEqual(p2.name, None, 'Port name init shorcut error') - self.assertEqual(p2.is_downto, False, 'Port is_downto init shorcut error') - self.assertEqual(p2.is_scalar, True, 'Port is_scalar init shorcut error') - self.assertEqual(p2.lower_index, 0, 'Port lower_index init shorcut error') + p2 = Port(is_downto=False) + self.assertEqual(p2.name, None, "Port name init shorcut error") + self.assertEqual(p2.is_downto, False, "Port is_downto init shorcut error") + self.assertEqual(p2.is_scalar, True, "Port is_scalar init shorcut error") + self.assertEqual(p2.lower_index, 0, "Port lower_index init shorcut error") def test_properties_init_shortcut(self): + d = Definition("d_name", {"key1": 1, "key2": "value2"}) + self.assertEqual(d["key1"], 1, "Definition properties init shorcut error") - d = Definition('d_name',{'key1':1, 'key2':'value2' }) - self.assertEqual(d['key1'], 1, 'Definition properties init shorcut error') - - l = Library('l_name',{'key1':'value1', 'key2':'value2' }) - self.assertEqual(l['key1'], 'value1', 'Library properties init shorcut error') + l = Library("l_name", {"key1": "value1", "key2": "value2"}) + self.assertEqual(l["key1"], "value1", "Library properties init shorcut error") - n = Netlist('n_name',{'key1':'value1', 'key2': 63 }) - self.assertEqual(n['key2'], 63, 'Netlist properties init shorcut error') + n = Netlist("n_name", {"key1": "value1", "key2": 63}) + self.assertEqual(n["key2"], 63, "Netlist properties init shorcut error") - i = Instance('i_name',{'key1':'value1', 'key2':'value2' }) - self.assertEqual(i['key1'], 'value1', 'Instance properties init shorcut error') + i = Instance("i_name", {"key1": "value1", "key2": "value2"}) + self.assertEqual(i["key1"], "value1", "Instance properties init shorcut error") - c = Cable('c_name',{'key1':'value1', 'key2':'value2' }) - self.assertEqual(c['key2'], 'value2', 'Cable properties init shorcut error') + c = Cable("c_name", {"key1": "value1", "key2": "value2"}) + self.assertEqual(c["key2"], "value2", "Cable properties init shorcut error") - p = Port('p_name',{'key1':'value1', 'key2':'value2' }) - self.assertEqual(p['key1'], 'value1', 'Port properties init shorcut error') + p = Port("p_name", {"key1": "value1", "key2": "value2"}) + self.assertEqual(p["key1"], "value1", "Port properties init shorcut error") def test_library_child_instance_creation(self): - l = Library('l_name',{'key1':'value1', 'key2':'value2' }) - self.assertEqual(l['key1'], 'value1', 'Library properties init shorcut error') - - l.create_definition("l_d_name", {'key1': 50, 'key2':'value2' }) - self.assertEqual('l_d_name', l.definitions[0].name, 'library\'s definition cretion shorcut error') - self.assertEqual(l.definitions[0]['key1'], 50, 'library\'s definition cretion shorcut error') + l = Library("l_name", {"key1": "value1", "key2": "value2"}) + self.assertEqual(l["key1"], "value1", "Library properties init shorcut error") + + l.create_definition("l_d_name", {"key1": 50, "key2": "value2"}) + self.assertEqual( + "l_d_name", + l.definitions[0].name, + "library's definition cretion shorcut error", + ) + self.assertEqual( + l.definitions[0]["key1"], 50, "library's definition cretion shorcut error" + ) l2 = Library() - l2.create_definition(properties = {'key1': 50, 'key2':'value2' }) - self.assertEqual(l2.definitions[0]['key1'], 50, 'library\'s definition cretion shorcut error') + l2.create_definition(properties={"key1": 50, "key2": "value2"}) + self.assertEqual( + l2.definitions[0]["key1"], 50, "library's definition cretion shorcut error" + ) def test_definition_child_instance_creation(self): - d = Definition('d_name',{'key1':1, 'key2':'value2' }) - self.assertEqual(d['key1'], 1, 'Definition properties init shorcut error') - - d.create_port('p_name') - self.assertEqual(d.ports[0].name, 'p_name', 'Port name init shorcut error') - d.create_port(properties = {'key1':'value1', 'key2':'value2' }) - self.assertEqual(d.ports[1]['key1'], 'value1', 'Port properties init shorcut error') - - d.create_port(properties = {'key1':'value1', 'key2':'value2' }) - self.assertEqual(d.ports[1]['key1'], 'value1', 'Port properties init shorcut error') - - d.create_child('d_c_name', {'key1':1, 'key2':'value2' }) - self.assertEqual(d.children[0]['key1'], 1, 'Definition properties init shorcut error') - self.assertEqual(d['key1'], 1, 'Definition properties init shorcut error') - - d.create_cable('c_name', None, False, True, 2) - self.assertEqual(d.cables[0].name, 'c_name', 'Cable name init shorcut error') - self.assertEqual(d.cables[0].is_downto, False, 'Cable is_downto init shorcut error') - self.assertEqual(d.cables[0].is_scalar, True, 'Cable is_scalar init shorcut error') - self.assertEqual(d.cables[0].lower_index, 2, 'Cable lower_index init shorcut error') - - d.create_cable(is_scalar = False) - self.assertEqual(d.cables[1].name, None, 'Cable name init shorcut error') - self.assertEqual(d.cables[1].is_downto, True, 'Cable is_downto init shorcut error') - self.assertEqual(d.cables[1].is_scalar, False, 'Cable is_scalar init shorcut error') - self.assertEqual(d.cables[1].lower_index, 0, 'Cable lower_index init shorcut error') + d = Definition("d_name", {"key1": 1, "key2": "value2"}) + self.assertEqual(d["key1"], 1, "Definition properties init shorcut error") + + d.create_port("p_name") + self.assertEqual(d.ports[0].name, "p_name", "Port name init shorcut error") + d.create_port(properties={"key1": "value1", "key2": "value2"}) + self.assertEqual( + d.ports[1]["key1"], "value1", "Port properties init shorcut error" + ) + + d.create_port(properties={"key1": "value1", "key2": "value2"}) + self.assertEqual( + d.ports[1]["key1"], "value1", "Port properties init shorcut error" + ) + + d.create_child("d_c_name", {"key1": 1, "key2": "value2"}) + self.assertEqual( + d.children[0]["key1"], 1, "Definition properties init shorcut error" + ) + self.assertEqual(d["key1"], 1, "Definition properties init shorcut error") + + d.create_cable("c_name", None, False, True, 2) + self.assertEqual(d.cables[0].name, "c_name", "Cable name init shorcut error") + self.assertEqual( + d.cables[0].is_downto, False, "Cable is_downto init shorcut error" + ) + self.assertEqual( + d.cables[0].is_scalar, True, "Cable is_scalar init shorcut error" + ) + self.assertEqual( + d.cables[0].lower_index, 2, "Cable lower_index init shorcut error" + ) + + d.create_cable(is_scalar=False) + self.assertEqual(d.cables[1].name, None, "Cable name init shorcut error") + self.assertEqual( + d.cables[1].is_downto, True, "Cable is_downto init shorcut error" + ) + self.assertEqual( + d.cables[1].is_scalar, False, "Cable is_scalar init shorcut error" + ) + self.assertEqual( + d.cables[1].lower_index, 0, "Cable lower_index init shorcut error" + ) def test_netlist_child_instance_creation(self): - n = Netlist('n_name') - self.assertEqual(n.name, 'n_name', 'Netlist name init shorcut error') - n.create_library('l_name',{'key1':'value1', 'key2':'value2' }) - self.assertEqual(n.libraries[0]['key1'], 'value1', 'Library properties init shorcut error') - - - - - - - - + n = Netlist("n_name") + self.assertEqual(n.name, "n_name", "Netlist name init shorcut error") + n.create_library("l_name", {"key1": "value1", "key2": "value2"}) + self.assertEqual( + n.libraries[0]["key1"], "value1", "Library properties init shorcut error" + ) diff --git a/tests/spydrnet/ir/tests/test_wire.py b/tests/spydrnet/ir/tests/test_wire.py index 2d6752ce..a28d4e80 100644 --- a/tests/spydrnet/ir/tests/test_wire.py +++ b/tests/spydrnet/ir/tests/test_wire.py @@ -4,6 +4,7 @@ from spydrnet.ir import FirstClassElement from spydrnet.util.selection import Selection + class TestWire(unittest.TestCase): def setUp(self): self.definition_top = sdn.Definition() @@ -19,16 +20,24 @@ def setUp(self): self.instance.reference = self.definition_leaf def test_constructor(self): - self.assertFalse(isinstance(self.wire, FirstClassElement), "Wire should not extend element") + self.assertFalse( + isinstance(self.wire, FirstClassElement), "Wire should not extend element" + ) wire2 = sdn.Wire() self.assertNotEqual(self.wire, wire2, "Unique items are considered equal") def test_pins_assignement(self): self.wire.connect_pin(self.instance.pins[self.pin1]) self.wire.connect_pin(self.instance.pins[self.pin2]) - self.assertEqual(self.wire.pins, [self.instance.pins[self.pin1], self.instance.pins[self.pin2]]) + self.assertEqual( + self.wire.pins, + [self.instance.pins[self.pin1], self.instance.pins[self.pin2]], + ) self.wire.pins = [self.instance.pins[self.pin2], self.instance.pins[self.pin1]] - self.assertEqual(self.wire.pins, [self.instance.pins[self.pin2], self.instance.pins[self.pin1]]) + self.assertEqual( + self.wire.pins, + [self.instance.pins[self.pin2], self.instance.pins[self.pin1]], + ) def test_connect_and_disconnect_inner_port(self): self.wire.connect_pin(self.inner_pin) @@ -56,7 +65,10 @@ def test_connect_and_disconnect_outer_pin_by_reference(self): self.assertTrue(self.pin1 in self.instance.pins) def test_connect_and_disconnect_outer_pin_by_object(self): - self.wire.connect_pin(sdn.OuterPin.from_instance_and_inner_pin(self.instance, self.pin2), position=0) + self.wire.connect_pin( + sdn.OuterPin.from_instance_and_inner_pin(self.instance, self.pin2), + position=0, + ) self.assertEqual(len(self.wire.pins), 1) self.assertTrue(all(x is self.instance.pins[x] for x in self.wire.pins)) self.assertTrue(all(x.wire is self.wire for x in self.wire.pins)) @@ -73,34 +85,48 @@ def test_disconnect_pin_from(self): self.wire.connect_pin(self.inner_pin) self.wire.connect_pin(self.instance.pins[self.pin1]) self.wire.connect_pin(self.instance.pins[self.pin2]) - self.wire.disconnect_pins_from(iter((self.inner_pin, self.instance.pins[self.pin1]))) + self.wire.disconnect_pins_from( + iter((self.inner_pin, self.instance.pins[self.pin1])) + ) self.wire.disconnect_pins_from({self.instance.pins[self.pin2]}) self.assertEqual(len(self.wire.pins), 0) - self.assertTrue(self.pin1 in self.instance.pins and isinstance(self.instance.pins[self.pin1], sdn.OuterPin) and - self.instance.pins[self.pin1].inner_pin == self.pin1) + self.assertTrue( + self.pin1 in self.instance.pins + and isinstance(self.instance.pins[self.pin1], sdn.OuterPin) + and self.instance.pins[self.pin1].inner_pin == self.pin1 + ) self.assertIsNone(self.inner_pin.wire) self.assertIsNone(self.instance.pins[self.pin1].wire) self.assertIsNone(self.instance.pins[self.pin2].wire) - self.assertTrue(self.pin1 in self.instance.pins and isinstance(self.instance.pins[self.pin2], sdn.OuterPin) and - self.instance.pins[self.pin2].inner_pin == self.pin2) + self.assertTrue( + self.pin1 in self.instance.pins + and isinstance(self.instance.pins[self.pin2], sdn.OuterPin) + and self.instance.pins[self.pin2].inner_pin == self.pin2 + ) def test_get_driver(self): - netlist = sdn.load_example_netlist_by_name('toggle') - instance = next(netlist.get_instances('out_reg')) - input_pin = next(instance.get_pins(selection=Selection.OUTSIDE,filter=lambda x: x.inner_pin.port.direction is sdn.IN and 'D' in x.inner_pin.port.name)) + netlist = sdn.load_example_netlist_by_name("toggle") + instance = next(netlist.get_instances("out_reg")) + input_pin = next( + instance.get_pins( + selection=Selection.OUTSIDE, + filter=lambda x: x.inner_pin.port.direction is sdn.IN + and "D" in x.inner_pin.port.name, + ) + ) driver = list(x for x in input_pin.wire.get_driver()) self.assertTrue(len(driver) == 1) - self.assertTrue('out_i_1' in driver[0].instance.name) - self.assertEqual(driver[0].inner_pin.port.name, 'O') + self.assertTrue("out_i_1" in driver[0].instance.name) + self.assertEqual(driver[0].inner_pin.port.name, "O") def test_get_driver_2(self): - netlist = sdn.load_example_netlist_by_name('adder') - instance = next(netlist.get_instances('a')) - cable = next(instance.get_cables('a')) + netlist = sdn.load_example_netlist_by_name("adder") + instance = next(netlist.get_instances("a")) + cable = next(instance.get_cables("a")) wire = cable.wires[0] driver = list(x for x in wire.get_driver()) self.assertTrue(len(driver) == 1) - self.assertTrue('a[8:0]' in driver[0].port.name) + self.assertTrue("a[8:0]" in driver[0].port.name) @unittest.expectedFailure def test_disconnect_inner_pin_from_outside_wire(self): @@ -114,9 +140,9 @@ def test_disconnect_outer_pin_from_outside_wire(self): def test_print_no_cable(self): wire = sdn.Wire() - self.assertTrue('Not contained by any Cable' in wire.__str__()) + self.assertTrue("Not contained by any Cable" in wire.__str__()) def test_print_cable_name(self): - cable = sdn.Cable('cable') + cable = sdn.Cable("cable") wire = cable.create_wire() self.assertTrue("Contained by Cable.name 'cable'" in wire.__str__()) diff --git a/tests/spydrnet/ir/views/tests/test_dictview.py b/tests/spydrnet/ir/views/tests/test_dictview.py index 7b9e0b71..629f2a5f 100644 --- a/tests/spydrnet/ir/views/tests/test_dictview.py +++ b/tests/spydrnet/ir/views/tests/test_dictview.py @@ -1,6 +1,7 @@ import unittest from spydrnet.ir.views.dictview import DictView + class TestDictView(unittest.TestCase): def setUp(self) -> None: self.dict_1 = dict(map(lambda x: (x, str(x)), range(10))) @@ -47,13 +48,18 @@ def test_iter(self): def test_get(self): for ii in range(11): - self.assertTrue(self.dict_view_1.get(ii, '10') == str(ii)) + self.assertTrue(self.dict_view_1.get(ii, "10") == str(ii)) def test_copy(self): - self.assertEqual(dict(map(lambda x: (x, str(x)), range(10))), self.dict_view_1.copy()) + self.assertEqual( + dict(map(lambda x: (x, str(x)), range(10))), self.dict_view_1.copy() + ) def test_fromkeys(self): - self.assertEqual(self.dict_view_1.fromkeys(range(10), 5), dict(map(lambda x: (x, 5), range(10)))) + self.assertEqual( + self.dict_view_1.fromkeys(range(10), 5), + dict(map(lambda x: (x, 5), range(10))), + ) def test_keys(self): for ii, jj in zip(self.dict_view_1.keys(), range(10)): diff --git a/tests/spydrnet/ir/views/tests/test_outerpinsview.py b/tests/spydrnet/ir/views/tests/test_outerpinsview.py index dae7eb5a..f75d79a9 100644 --- a/tests/spydrnet/ir/views/tests/test_outerpinsview.py +++ b/tests/spydrnet/ir/views/tests/test_outerpinsview.py @@ -13,16 +13,33 @@ def setUp(self) -> None: def test_contains(self): self.assertTrue(all(x in self.outer_pins_view for x in self.inner_pins)) - self.assertTrue(all(sdn.OuterPin(self.instance, x) in self.outer_pins_view for x in self.inner_pins)) + self.assertTrue( + all( + sdn.OuterPin(self.instance, x) in self.outer_pins_view + for x in self.inner_pins + ) + ) def test_equal(self): - self.assertEqual(self.outer_pins_view, dict(map(lambda x: (x, sdn.OuterPin(self.instance, x)), - self.inner_pins))) + self.assertEqual( + self.outer_pins_view, + dict(map(lambda x: (x, sdn.OuterPin(self.instance, x)), self.inner_pins)), + ) def test_getitem(self): - self.assertTrue(all(self.outer_pins_view[x] == sdn.OuterPin(self.instance, x) for x in self.inner_pins)) - self.assertTrue(all(self.outer_pins_view[x] is self.outer_pins_view[sdn.OuterPin(self.instance, x)] for x in - self.inner_pins)) + self.assertTrue( + all( + self.outer_pins_view[x] == sdn.OuterPin(self.instance, x) + for x in self.inner_pins + ) + ) + self.assertTrue( + all( + self.outer_pins_view[x] + is self.outer_pins_view[sdn.OuterPin(self.instance, x)] + for x in self.inner_pins + ) + ) def test_iter(self): self.assertTrue(all(isinstance(x, sdn.OuterPin) for x in self.outer_pins_view)) @@ -31,6 +48,11 @@ def test_len(self): self.assertEqual(len(self.outer_pins_view), 10) def test_get(self): - self.assertEqual(self.outer_pins_view.get(self.inner_pins[0]), sdn.OuterPin(self.instance, self.inner_pins[0])) - self.assertEqual(self.outer_pins_view.get(sdn.OuterPin(self.instance, self.inner_pins[0])), - sdn.OuterPin(self.instance, self.inner_pins[0])) + self.assertEqual( + self.outer_pins_view.get(self.inner_pins[0]), + sdn.OuterPin(self.instance, self.inner_pins[0]), + ) + self.assertEqual( + self.outer_pins_view.get(sdn.OuterPin(self.instance, self.inner_pins[0])), + sdn.OuterPin(self.instance, self.inner_pins[0]), + ) diff --git a/tests/spydrnet/ir/views/tests/test_setview.py b/tests/spydrnet/ir/views/tests/test_setview.py index 1e78a45a..bb9731a4 100644 --- a/tests/spydrnet/ir/views/tests/test_setview.py +++ b/tests/spydrnet/ir/views/tests/test_setview.py @@ -94,8 +94,10 @@ def test_issuperset(self): self.assertTrue(self.set_view.issuperset(set(range(5)))) def test_symmetric_difference(self): - self.assertTrue(set(range(10)) ^ set(range(5, 20)), self.set_view.symmetric_difference(set(range(5, 20)))) + self.assertTrue( + set(range(10)) ^ set(range(5, 20)), + self.set_view.symmetric_difference(set(range(5, 20))), + ) def test_union(self): self.assertTrue(set(range(20)), self.set_view.union(set(range(10, 20)))) - diff --git a/tests/spydrnet/parsers/eblif/tests/test_eblif_parser.py b/tests/spydrnet/parsers/eblif/tests/test_eblif_parser.py index c8463089..903296de 100644 --- a/tests/spydrnet/parsers/eblif/tests/test_eblif_parser.py +++ b/tests/spydrnet/parsers/eblif/tests/test_eblif_parser.py @@ -9,60 +9,89 @@ - Everything is there - Everything is working together as a netlist as it should (to be sure things were created and placed in the netlist correctly) """ + + class TestEBLIFParser(unittest.TestCase): def setUp(self): - self.netlist = sdn.parse(Path(example_netlists_path, 'eblif_netlists', "toggle.eblif.zip")) - self.definition_list = ["INV","BUFG","FDRE","IBUF","OBUF","toggle", "logic-gate_0"] + self.netlist = sdn.parse( + Path(example_netlists_path, "eblif_netlists", "toggle.eblif.zip") + ) + self.definition_list = [ + "INV", + "BUFG", + "FDRE", + "IBUF", + "OBUF", + "toggle", + "logic-gate_0", + ] def test_name(self): - self.assertEqual(self.netlist.name,"toggle") + self.assertEqual(self.netlist.name, "toggle") def test_definitions(self): count = 0 for definition in self.netlist.get_definitions(): - self.assertTrue(definition.name in self.definition_list, definition.name + " not found in list") - count+=1 - self.assertEqual(count,len(self.definition_list)) - + self.assertTrue( + definition.name in self.definition_list, + definition.name + " not found in list", + ) + count += 1 + self.assertEqual(count, len(self.definition_list)) + def test_instances(self): - self.assertEqual(self.netlist.top_instance.name,"toggle") + self.assertEqual(self.netlist.top_instance.name, "toggle") for instance in self.netlist.get_instances(): self.assertTrue(instance.reference.name in self.definition_list) self.assertTrue(self.netlist_is_own_netlist(instance)) if "logic-gate_0" in instance.reference.name: - self.assertEqual(instance["EBLIF.type"],"EBLIF.names") + self.assertEqual(instance["EBLIF.type"], "EBLIF.names") else: - self.assertEqual(instance["EBLIF.type"],"EBLIF.subckt") + self.assertEqual(instance["EBLIF.type"], "EBLIF.subckt") def test_top_level_ports(self): - input_port_list = ["clk","reset"] + input_port_list = ["clk", "reset"] output_port_list = ["out"] for port in self.netlist.get_hports(): if port.item.direction is sdn.IN: - self.assertTrue(port.item.name in input_port_list,port.item.name+" is not in "+str(input_port_list)) + self.assertTrue( + port.item.name in input_port_list, + port.item.name + " is not in " + str(input_port_list), + ) self.assertTrue(self.netlist_is_own_netlist(port)) elif port.item.direction is sdn.OUT: - self.assertTrue(port.item.name in output_port_list,port.item.name+" is not in "+str(output_port_list)) + self.assertTrue( + port.item.name in output_port_list, + port.item.name + " is not in " + str(output_port_list), + ) self.assertTrue(self.netlist_is_own_netlist(port)) def test_cables(self): count = 0 for cable in self.netlist.get_cables(): self.assertTrue(self.netlist_is_own_netlist(cable)) - count+=1 + count += 1 self.assertEqual(count, 11) - def netlist_is_own_netlist(self,object): + def netlist_is_own_netlist(self, object): netlist_list = list(x for x in object.get_netlists()) - if (self.netlist in netlist_list): + if self.netlist in netlist_list: return True return False - + def test_flip_flop_connections(self): - instance = next(self.netlist.get_instances(filter=lambda x: x.reference.name == "FDRE")) - pin_connections = {"C":"clk"} - for input_pin in instance.get_pins(selection=Selection.OUTSIDE,filter=lambda x: x.inner_pin.port.direction is sdn.IN): - self.assertTrue(input_pin.wire is not None, input_pin.inner_pin.port.name + " does not have a wire") + instance = next( + self.netlist.get_instances(filter=lambda x: x.reference.name == "FDRE") + ) + pin_connections = {"C": "clk"} + for input_pin in instance.get_pins( + selection=Selection.OUTSIDE, + filter=lambda x: x.inner_pin.port.direction is sdn.IN, + ): + self.assertTrue( + input_pin.wire is not None, + input_pin.inner_pin.port.name + " does not have a wire", + ) # driver_pin = next(pin for pin in input_pin.wire.pins) # get the driver # make sure it's the right driver diff --git a/tests/spydrnet/parsers/edif/tests/test_edif_parser.py b/tests/spydrnet/parsers/edif/tests/test_edif_parser.py index ec62a863..3eafa925 100644 --- a/tests/spydrnet/parsers/edif/tests/test_edif_parser.py +++ b/tests/spydrnet/parsers/edif/tests/test_edif_parser.py @@ -23,7 +23,7 @@ def test_multi_bit_add_out_of_order(self): cable0.create_wire() cable1.create_wire() cable2.create_wire() - + p0 = sdn.InnerPin() p1 = sdn.InnerPin() p2 = sdn.InnerPin() @@ -38,14 +38,13 @@ def test_multi_bit_add_out_of_order(self): ep.multibit_add_cable(definition, cable1) assert len(definition.cables) == 1 - assert len (definition.cables[0].wires) == 3 + assert len(definition.cables[0].wires) == 3 assert len(definition.cables[0].wires[0].pins) == 0 assert len(definition.cables[0].wires[1].pins) == 3 assert len(definition.cables[0].wires[2].pins) == 0 assert p0 in definition.cables[0].wires[1].pins assert p1 in definition.cables[0].wires[1].pins assert p2 in definition.cables[0].wires[1].pins - @classmethod def setUpClass(cls) -> None: @@ -65,7 +64,7 @@ def test_small_edif_cables(self): continue self.ensure_cable_consistency(filename, ii, "edf") - def ensure_cable_consistency(self,filename, ii, target_format_extension = None): + def ensure_cable_consistency(self, filename, ii, target_format_extension=None): with self.subTest(i=ii): if Path("temp").exists(): shutil.rmtree("temp") @@ -78,5 +77,5 @@ def ensure_cable_consistency(self,filename, ii, target_format_extension = None): assert c.definition is not None -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/spydrnet/parsers/edif/tests/test_tokenizer.py b/tests/spydrnet/parsers/edif/tests/test_tokenizer.py index 2ca70e64..e6be817e 100644 --- a/tests/spydrnet/parsers/edif/tests/test_tokenizer.py +++ b/tests/spydrnet/parsers/edif/tests/test_tokenizer.py @@ -7,6 +7,7 @@ from spydrnet.parsers.edif.tokenizer import EdifTokenizer from spydrnet import example_netlists_path + class TestEdifTokenizer(unittest.TestCase): def test_no_constructor_of_zero_argument(self): self.assertRaises(TypeError, EdifTokenizer) @@ -16,7 +17,7 @@ def test_stream(self): test_file = Path(dir_of_edif_netlists, "n_bit_counter.edf.zip") zip = zipfile.ZipFile(test_file) file_name = Path(test_file).name - file_name = file_name[:file_name.rindex(".")] + file_name = file_name[: file_name.rindex(".")] stream = zip.open(file_name) stream = io.TextIOWrapper(stream) tokenizer = EdifTokenizer.from_stream(stream) @@ -25,7 +26,9 @@ def test_stream(self): def test_open_zip_file(self): dir_of_edif_netlists = Path(example_netlists_path, "EDIF_netlists") - test_file = Path(dir_of_edif_netlists, "n_bit_counter.edf.zip") # UnicodeDecodeError + test_file = Path( + dir_of_edif_netlists, "n_bit_counter.edf.zip" + ) # UnicodeDecodeError tokenizer = EdifTokenizer.from_filename(test_file) next_token = tokenizer.next() self.assertEqual("(", next_token) @@ -34,7 +37,7 @@ def test_open_file(self): dir_of_edif_netlists = Path(example_netlists_path, "EDIF_netlists") test_file = Path(dir_of_edif_netlists, "n_bit_counter.edf.zip") file_name = Path(test_file).name - file_name = file_name[:file_name.rindex(".")] + file_name = file_name[: file_name.rindex(".")] zip = zipfile.ZipFile(test_file) with tempfile.TemporaryDirectory() as tempdir: zip.extract(file_name, tempdir) @@ -65,19 +68,19 @@ def test_paren_with_whitespace(self): self.assertRaises(StopIteration, tokenizer.next) def test_string_token(self): - test_string = "\"This is a test string in EDIF\"" + test_string = '"This is a test string in EDIF"' tokenizer = EdifTokenizer.from_string(test_string) next_token = tokenizer.next() self.assertEqual(test_string, next_token) self.assertRaises(StopIteration, tokenizer.next) def test_multiline_string(self): - test_string = "\"This is a test string in EDIF\n with a new line in it.\"" + test_string = '"This is a test string in EDIF\n with a new line in it."' tokenizer = EdifTokenizer.from_string(test_string) next_token = tokenizer.next() self.assertEqual(test_string.replace("\n", ""), next_token) self.assertRaises(StopIteration, tokenizer.next) - + def test_peek_and_token_equals(self): test_id = "VALID_EDIF_ID" tokenizer = EdifTokenizer.from_string(test_id) @@ -94,7 +97,6 @@ def test_peek_and_token_equals(self): class TestTokenTypes(unittest.TestCase): - def test_edif_identifier(self): valid_ids = "&test a a9 a_ Alpha_Numeric_0123456789 &" tokenizer = EdifTokenizer.from_string(valid_ids) @@ -102,10 +104,10 @@ def test_edif_identifier(self): tokenizer.next() self.assertTrue(tokenizer.is_valid_identifier(), tokenizer.token) - invalid_ids = "_ _idenitier_ 9alkjf too_long" + "0"*(256 - 7) + invalid_ids = "_ _idenitier_ 9alkjf too_long" + "0" * (256 - 7) tokenizer = EdifTokenizer.from_string(invalid_ids) while tokenizer.has_next(): tokenizer.next() self.assertFalse(tokenizer.is_valid_identifier(), tokenizer.token) - #TODO Special characters are weird. We should check them out. + # TODO Special characters are weird. We should check them out. diff --git a/tests/spydrnet/parsers/primatives/tests/test_parse_primatives.py b/tests/spydrnet/parsers/primatives/tests/test_parse_primatives.py index 32b24c0e..3af79708 100644 --- a/tests/spydrnet/parsers/primatives/tests/test_parse_primatives.py +++ b/tests/spydrnet/parsers/primatives/tests/test_parse_primatives.py @@ -3,5 +3,4 @@ class TestParsePrimatives(unittest.TestCase): - - None \ No newline at end of file + None diff --git a/tests/spydrnet/parsers/tests/test_parsers.py b/tests/spydrnet/parsers/tests/test_parsers.py index fcdf6906..14daf7b2 100644 --- a/tests/spydrnet/parsers/tests/test_parsers.py +++ b/tests/spydrnet/parsers/tests/test_parsers.py @@ -10,11 +10,10 @@ def test_parse(self): self.assertRaises(RuntimeError, sdn.parse, "fakefile.fakeext") - class TestParseWithArchitecture(unittest.TestCase): def test_verilog(self): netlist = sdn.load_example_netlist_by_name("b13", VERILOG) - netlist.compose("b13.v", write_blackbox = False) + netlist.compose("b13.v", write_blackbox=False) netlist_1 = sdn.parse("b13.v") for definition in netlist_1.get_definitions(): @@ -29,14 +28,17 @@ def test_verilog(self): self.assertNotEqual(port.direction, sdn.UNDEFINED, definition.name) os.remove("b13.v") - + def test_eblif(self): netlist = sdn.load_example_netlist_by_name("toggle", EBLIF) - netlist.compose("toggle.eblif", write_blackbox = False) + netlist.compose("toggle.eblif", write_blackbox=False) netlist_1 = sdn.parse("toggle.eblif") for definition in netlist_1.get_definitions(): - if definition is not netlist_1.top_instance.reference and "logic-gate" not in definition.name: + if ( + definition is not netlist_1.top_instance.reference + and "logic-gate" not in definition.name + ): for port in definition.get_ports(): self.assertEqual(port.direction, sdn.UNDEFINED, definition.name) diff --git a/tests/spydrnet/parsers/verilog/tests/test_token_factory.py b/tests/spydrnet/parsers/verilog/tests/test_token_factory.py index 413a6de1..5a771df6 100644 --- a/tests/spydrnet/parsers/verilog/tests/test_token_factory.py +++ b/tests/spydrnet/parsers/verilog/tests/test_token_factory.py @@ -4,7 +4,7 @@ # these code snippets may have copyright protection other than what the License file entails please use with caution -very_simple = '''// Copyright 1986-2020 Xilinx, Inc. All Rights Reserved. +very_simple = """// Copyright 1986-2020 Xilinx, Inc. All Rights Reserved. // -------------------------------------------------------------------------------- // Tool Version: Vivado v.2020.2 (lin64) Build 3064766 Wed Nov 18 09:12:47 MST 2020 // Date : Wed Mar 17 14:51:06 2021 @@ -24,9 +24,9 @@ input [7:0]XP_IN; -endmodule''' +endmodule""" -very_simple_multi_line = '''/* Copyright 1986-2020 Xilinx, Inc. All Rights Reserved. +very_simple_multi_line = """/* Copyright 1986-2020 Xilinx, Inc. All Rights Reserved. // -------------------------------------------------------------------------------- // Tool Version: Vivado v.2020.2 (lin64) Build 3064766 Wed Nov 18 09:12:47 MST 2020 // Date : Wed Mar 17 14:51:06 2021 @@ -47,9 +47,9 @@ input [7:0]XP_IN; -endmodule''' +endmodule""" -port_remap = ''' +port_remap = """ (* STRUCTURAL_NETLIST = "yes" *) module synth_th1_slaac (.XP_IN({\^XP_IN [0],\^XP_IN [1],\^XP_IN [2],\^XP_IN [3],\^XP_IN [4],\^XP_IN [5],\^XP_IN [6],\^XP_IN [7]})); @@ -59,9 +59,9 @@ wire [7:0]\^XP_IN ; endmodule -''' +""" -comments = ''' +comments = """ /*/ this should be treated as a single comment /*/ @@ -75,20 +75,19 @@ */ -''' +""" -final_comments = ''' +final_comments = """ module synth_th1_slaac (XP_IN); input [7:0]XP_IN; endmodule //* Final design comments -''' +""" class TestVerilogParser(unittest.TestCase): - def run_token_count(self, string): tf = TokenFactory() running_total = 0 @@ -103,13 +102,20 @@ def run_token_count(self, string): return running_total def test_counts(self): - to_run = [(very_simple_multi_line, 24, "very_simple_multi_line"), (very_simple, 35, "very_simple"), - (port_remap, 74, "port_remap"), (comments, 11, "comments"), (final_comments, 16, "port_remap")] + to_run = [ + (very_simple_multi_line, 24, "very_simple_multi_line"), + (very_simple, 35, "very_simple"), + (port_remap, 74, "port_remap"), + (comments, 11, "comments"), + (final_comments, 16, "port_remap"), + ] for p in to_run: s, c, n = p - assert c == self.run_token_count( - s), "the number of expected tokens did not match up with the number parsed " + n + assert c == self.run_token_count(s), ( + "the number of expected tokens did not match up with the number parsed " + + n + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/spydrnet/parsers/verilog/tests/test_tokenizer.py b/tests/spydrnet/parsers/verilog/tests/test_tokenizer.py index 8d393e56..5ec2257b 100644 --- a/tests/spydrnet/parsers/verilog/tests/test_tokenizer.py +++ b/tests/spydrnet/parsers/verilog/tests/test_tokenizer.py @@ -7,24 +7,26 @@ class TestVerilogTokenizer(unittest.TestCase): - - def test_against_4bit_adder(self): - directory = Path(sdn.example_netlists_path).joinpath("verilog_netlists", "4bitadder.v.zip") - + directory = Path(sdn.example_netlists_path).joinpath( + "verilog_netlists", "4bitadder.v.zip" + ) + tokenizer = VerilogTokenizer.from_filename(directory) - while(tokenizer.has_next()): - #print(tokenizer.next()) + while tokenizer.has_next(): + # print(tokenizer.next()) tokenizer.next() def test_spaces(self): - tokenizer = VerilogTokenizer.from_string("wire temp = 1'b1; if something == some2") - while(tokenizer.has_next()): - #print(tokenizer.next()) + tokenizer = VerilogTokenizer.from_string( + "wire temp = 1'b1; if something == some2" + ) + while tokenizer.has_next(): + # print(tokenizer.next()) tokenizer.next() tokenizer = VerilogTokenizer.from_string("wire temp=1'b1 ;if something==some2") - while(tokenizer.has_next()): - #print(tokenizer.next()) + while tokenizer.has_next(): + # print(tokenizer.next()) tokenizer.next() def test_from_stream(self): @@ -32,8 +34,8 @@ def test_from_stream(self): tokenizer = VerilogTokenizer.from_stream(stream) expected_tokens = ["module", "empty", "(", ")", ";", "endmodule"] tokens = [] - while(tokenizer.has_next()): + while tokenizer.has_next(): tokens.append(tokenizer.next()) - + for i in range(len(expected_tokens)): - assert expected_tokens[i] == tokens[i] \ No newline at end of file + assert expected_tokens[i] == tokens[i] diff --git a/tests/spydrnet/parsers/verilog/tests/test_verilogParser.py b/tests/spydrnet/parsers/verilog/tests/test_verilogParser.py index 8604e624..02b21889 100644 --- a/tests/spydrnet/parsers/verilog/tests/test_verilogParser.py +++ b/tests/spydrnet/parsers/verilog/tests/test_verilogParser.py @@ -9,8 +9,8 @@ from spydrnet.util.selection import Selection import os -class TestVerilogParser(unittest.TestCase): +class TestVerilogParser(unittest.TestCase): class TestTokenizer: def __init__(self, tokenlist): self.tokens = tokenlist @@ -28,7 +28,7 @@ def next(self): token = self.tokens[self.index] self.index += 1 return token - + def peek(self): token = self.tokens[self.index] return token @@ -42,9 +42,33 @@ def test_module_header_parameter_parsing(self): expected["INIT"] = "1'h1" expected["[1:0] INIT0"] = "2'h0" expected["[0] INIT1"] = "1'b0" - tokens = ["#", "(", "parameter", "INIT", "=", "1'h1", ",",\ - "parameter", "[", "1", ":", "0", "]", "INIT0", "=", "2'h0", ",",\ - "parameter", "[", "0", "]", "INIT1", "=", "1'b0", ")"] + tokens = [ + "#", + "(", + "parameter", + "INIT", + "=", + "1'h1", + ",", + "parameter", + "[", + "1", + ":", + "0", + "]", + "INIT0", + "=", + "2'h0", + ",", + "parameter", + "[", + "0", + "]", + "INIT1", + "=", + "1'b0", + ")", + ] tokenizer = self.TestTokenizer(tokens) parser = VerilogParser() @@ -53,17 +77,25 @@ def test_module_header_parameter_parsing(self): parser.parse_module_header_parameters() - assert "VERILOG.Parameters" in parser.current_definition, "expected parameters in the definition" + assert ( + "VERILOG.Parameters" in parser.current_definition + ), "expected parameters in the definition" parameters = parser.current_definition["VERILOG.Parameters"] for k, v in expected.items(): - assert k in parameters, "expected to see " + k + " in the definition parameters" - assert parameters[k] == v, "expected value of k to be " + v + " but got instead " + parameters[k] - + assert k in parameters, ( + "expected to see " + k + " in the definition parameters" + ) + assert parameters[k] == v, ( + "expected value of k to be " + v + " but got instead " + parameters[k] + ) + for k, v in parameters.items(): - assert k in expected, "unexpected value " + k + " in the definition parameters" - + assert k in expected, ( + "unexpected value " + k + " in the definition parameters" + ) + def test_module_header_port_name_only(self): - #expected = [(direction, left, right, name)] + # expected = [(direction, left, right, name)] expected = ["PORT0", "PORT1", "PORT2", "PORT3", "PORT4"] tokens = ["("] first_run = True @@ -83,15 +115,25 @@ def test_module_header_port_name_only(self): parser.parse_module_header_ports() - assert len(parser.current_definition.ports) == len(expected), \ - "port count mismatch definition: " + str(len(parser.current_definition.ports)) + " expected: " + str(len(expected)) + assert len(parser.current_definition.ports) == len(expected), ( + "port count mismatch definition: " + + str(len(parser.current_definition.ports)) + + " expected: " + + str(len(expected)) + ) for i in range(len(expected)): assert expected[i] == parser.current_definition.ports[i].name def test_module_header_port_name_and_direction(self): - #expected = [(direction, left, right, name)] - expected = [("PORT0", "output"), ("PORT1", "input"), ("PORT2", "inout"), ("PORT3", "output"), ("PORT4", "input")] + # expected = [(direction, left, right, name)] + expected = [ + ("PORT0", "output"), + ("PORT1", "input"), + ("PORT2", "inout"), + ("PORT3", "output"), + ("PORT4", "input"), + ] tokens = ["("] first_run = True for p in expected: @@ -112,20 +154,38 @@ def test_module_header_port_name_and_direction(self): parser.parse_module_header_ports() - assert len(parser.current_definition.ports) == len(expected), \ - "port count mismatch definition: " + str(len(parser.current_definition.ports)) + " expected: " + str(len(expected)) + assert len(parser.current_definition.ports) == len(expected), ( + "port count mismatch definition: " + + str(len(parser.current_definition.ports)) + + " expected: " + + str(len(expected)) + ) for i in range(len(expected)): - assert expected[i][0] == parser.current_definition.ports[i].name,\ - "ports names don't match. Definition: " + parser.current_definition.ports[i].name + " expected " + expected[i][0] + assert expected[i][0] == parser.current_definition.ports[i].name, ( + "ports names don't match. Definition: " + + parser.current_definition.ports[i].name + + " expected " + + expected[i][0] + ) expected_direction = vt.string_to_port_direction(expected[i][1]) definition_direction = parser.current_definition.ports[i].direction - assert expected_direction == definition_direction, \ - "directions do not match up expected " + str(expected_direction) + " but got " + definition_direction + assert expected_direction == definition_direction, ( + "directions do not match up expected " + + str(expected_direction) + + " but got " + + definition_direction + ) def test_module_heaader_port_name_and_index(self): - #expected = [(direction, left, right, name)] - expected = [("PORT0", "5" , "0"), ("PORT1", "8","-2"), ("PORT2", "0","0"), ("PORT3", "16","8"), ("PORT4", "3","0")] + # expected = [(direction, left, right, name)] + expected = [ + ("PORT0", "5", "0"), + ("PORT1", "8", "-2"), + ("PORT2", "0", "0"), + ("PORT3", "16", "8"), + ("PORT4", "3", "0"), + ] tokens = ["("] first_run = True for p in expected: @@ -148,27 +208,49 @@ def test_module_heaader_port_name_and_index(self): parser.parse_module_header_ports() - assert len(parser.current_definition.ports) == len(expected), \ - "port count mismatch definition: " + str(len(parser.current_definition.ports)) + " expected: " + str(len(expected)) + assert len(parser.current_definition.ports) == len(expected), ( + "port count mismatch definition: " + + str(len(parser.current_definition.ports)) + + " expected: " + + str(len(expected)) + ) for i in range(len(expected)): - assert expected[i][0] == parser.current_definition.ports[i].name,\ - "ports names don't match. Definition: " + parser.current_definition.ports[i].name + " expected " + expected[i][0] + assert expected[i][0] == parser.current_definition.ports[i].name, ( + "ports names don't match. Definition: " + + parser.current_definition.ports[i].name + + " expected " + + expected[i][0] + ) expected_lower = min(int(expected[i][2]), int(expected[i][1])) definition_lower = parser.current_definition.ports[i].lower_index - expected_width = max(int(expected[i][2]), int(expected[i][1])) - expected_lower + 1 + expected_width = ( + max(int(expected[i][2]), int(expected[i][1])) - expected_lower + 1 + ) definition_width = len(parser.current_definition.ports[i].pins) - assert expected_lower == definition_lower, \ - "lower indicies do not match up expected " + str(expected_lower) + " but got " + str(definition_lower) - - assert expected_width == definition_width, \ - "widths do not match up expected " + str(expected_width) + " but got " + str(definition_width) - + assert expected_lower == definition_lower, ( + "lower indicies do not match up expected " + + str(expected_lower) + + " but got " + + str(definition_lower) + ) + + assert expected_width == definition_width, ( + "widths do not match up expected " + + str(expected_width) + + " but got " + + str(definition_width) + ) def test_module_header_all_present(self): - expected = [("PORT0", "5" , "0", "input"), ("PORT1", "8","-2", "output"), ("PORT2", "0","0", "inout"),\ - ("PORT3", "16","8", "input"), ("PORT4", "3","0", "output")] + expected = [ + ("PORT0", "5", "0", "input"), + ("PORT1", "8", "-2", "output"), + ("PORT2", "0", "0", "inout"), + ("PORT3", "16", "8", "input"), + ("PORT4", "3", "0", "output"), + ] tokens = ["("] first_run = True for p in expected: @@ -192,39 +274,79 @@ def test_module_header_all_present(self): parser.parse_module_header_ports() - assert len(parser.current_definition.ports) == len(expected), \ - "port count mismatch definition: " + str(len(parser.current_definition.ports)) + " expected: " + str(len(expected)) + assert len(parser.current_definition.ports) == len(expected), ( + "port count mismatch definition: " + + str(len(parser.current_definition.ports)) + + " expected: " + + str(len(expected)) + ) for i in range(len(expected)): - assert expected[i][0] == parser.current_definition.ports[i].name,\ - "ports names don't match. Definition: " + parser.current_definition.ports[i].name + " expected " + expected[i][0] + assert expected[i][0] == parser.current_definition.ports[i].name, ( + "ports names don't match. Definition: " + + parser.current_definition.ports[i].name + + " expected " + + expected[i][0] + ) expected_lower = min(int(expected[i][2]), int(expected[i][1])) definition_lower = parser.current_definition.ports[i].lower_index - expected_width = max(int(expected[i][2]), int(expected[i][1])) - expected_lower + 1 + expected_width = ( + max(int(expected[i][2]), int(expected[i][1])) - expected_lower + 1 + ) definition_width = len(parser.current_definition.ports[i].pins) - assert expected_lower == definition_lower, \ - "lower indicies do not match up expected " + str(expected_lower) + " but got " + str(definition_lower) - - assert expected_width == definition_width, \ - "widths do not match up expected " + str(expected_width) + " but got " + str(definition_width) + assert expected_lower == definition_lower, ( + "lower indicies do not match up expected " + + str(expected_lower) + + " but got " + + str(definition_lower) + ) + + assert expected_width == definition_width, ( + "widths do not match up expected " + + str(expected_width) + + " but got " + + str(definition_width) + ) expected_direction = vt.string_to_port_direction(expected[i][3]) definition_direction = parser.current_definition.ports[i].direction - assert expected_direction == definition_direction, \ - "directions do not match up expected " + str(expected_direction) + " but got " + definition_direction + assert expected_direction == definition_direction, ( + "directions do not match up expected " + + str(expected_direction) + + " but got " + + definition_direction + ) def test_port_aliasing(self): parser = VerilogParser() - token_list = [".", "portName", "(", "{", "cable1", ",", "cable2", ",", "cable3", "}", ")"] + token_list = [ + ".", + "portName", + "(", + "{", + "cable1", + ",", + "cable2", + ",", + "cable3", + "}", + ")", + ] parser.tokenizer = self.TestTokenizer(token_list) d = sdn.Definition() parser.current_definition = d parser.parse_module_header_port_alias() - assert len(d.ports) == 1, "definition has the wrong number of ports, should have 1 has " + str(len(d.ports)) - assert d.ports[0].name == "portName", "port has the wrong name it should be portName but is " + d.ports[0].name + assert ( + len(d.ports) == 1 + ), "definition has the wrong number of ports, should have 1 has " + str( + len(d.ports) + ) + assert d.ports[0].name == "portName", ( + "port has the wrong name it should be portName but is " + d.ports[0].name + ) assert len(d.ports[0].pins) == 3 assert len(d.cables) == 3 names = [d.cables[0].name, d.cables[1].name, d.cables[2].name] @@ -248,17 +370,33 @@ def test_port_aliasing_single(self): assert d.cables[0].name == "cable1" def test_non_zero_lower_port_index(self): - '''this test based on an issue found while parsing riscv_multi_core.v in the support files - to see the problem lines that caused this test see line 89 and line 41''' + """this test based on an issue found while parsing riscv_multi_core.v in the support files + to see the problem lines that caused this test see line 89 and line 41""" parser = VerilogParser() - token_list = ["module", "alu", "(", "instruction", ")", ";", "output", "[", "27", ":", "26", "]", "instruction", ";", "endmodule"] + token_list = [ + "module", + "alu", + "(", + "instruction", + ")", + ";", + "output", + "[", + "27", + ":", + "26", + "]", + "instruction", + ";", + "endmodule", + ] tokenizer = self.TestTokenizer(token_list) parser.tokenizer = tokenizer - parser.current_library = sdn.Library(name = "TestLibrary") + parser.current_library = sdn.Library(name="TestLibrary") parser.netlist = sdn.Netlist() parser.netlist.add_library(parser.current_library) - + parser.parse_module() assert len(parser.current_definition.ports) == 1 @@ -276,19 +414,35 @@ def test_non_zero_lower_port_index(self): assert w.pins[0] in p.pins def test_port_cable_resize_post_creation(self): - '''we need a test that creates a port and then resizes it on definition - + """we need a test that creates a port and then resizes it on definition + module something(port); input [3:0] port; - endmodule''' + endmodule""" parser = VerilogParser() - token_list = ["module", "alu", "(", "instruction", ")", ";", "output", "[", "3", ":", "0", "]", "instruction", ";", "endmodule"] + token_list = [ + "module", + "alu", + "(", + "instruction", + ")", + ";", + "output", + "[", + "3", + ":", + "0", + "]", + "instruction", + ";", + "endmodule", + ] tokenizer = self.TestTokenizer(token_list) parser.tokenizer = tokenizer - parser.current_library = sdn.Library(name = "TestLibrary") + parser.current_library = sdn.Library(name="TestLibrary") parser.netlist = sdn.Netlist() parser.netlist.add_library(parser.current_library) - + parser.parse_module() assert len(parser.current_definition.ports) == 1 @@ -306,17 +460,42 @@ def test_port_cable_resize_post_creation(self): assert w.pins[0] in p.pins def test_port_resize_on_aliased_port(self): - '''example of this found in sha3_core.v on line 63176 or 63177 something to do with \\byte_num[0] ''' - tokens = ["module", "keccak", "(",\ - '.','byte_num','(','{','\\byte_num[2] ',',','\\byte_num[1] ', ',','\\byte_num[0] ','}',')',\ - ")", ";", "input", '\\byte_num[0] ', ';', 'input', '\\byte_num[1] ', ';', 'input', '\\byte_num[2] ',';', "endmodule"] + """example of this found in sha3_core.v on line 63176 or 63177 something to do with \\byte_num[0]""" + tokens = [ + "module", + "keccak", + "(", + ".", + "byte_num", + "(", + "{", + "\\byte_num[2] ", + ",", + "\\byte_num[1] ", + ",", + "\\byte_num[0] ", + "}", + ")", + ")", + ";", + "input", + "\\byte_num[0] ", + ";", + "input", + "\\byte_num[1] ", + ";", + "input", + "\\byte_num[2] ", + ";", + "endmodule", + ] tokenizer = self.TestTokenizer(tokens) parser = VerilogParser() parser.tokenizer = tokenizer - parser.current_library = sdn.Library(name = "TestLibrary") + parser.current_library = sdn.Library(name="TestLibrary") parser.netlist = sdn.Netlist() parser.netlist.add_library(parser.current_library) - + parser.parse_module() assert len(parser.current_definition.ports) == 1 @@ -325,24 +504,21 @@ def test_port_resize_on_aliased_port(self): for c in parser.current_definition.cables: names.append(c.name) assert len(c.wires) == 1 - assert '\\byte_num[2]' in names - assert '\\byte_num[1]' in names - assert '\\byte_num[0]' in names - assert parser.current_definition.ports[0].name == 'byte_num' - - + assert "\\byte_num[2]" in names + assert "\\byte_num[1]" in names + assert "\\byte_num[0]" in names + assert parser.current_definition.ports[0].name == "byte_num" def test_parse_empty_module_header(self): - '''example in bram.v in the support files on line 18''' + """example in bram.v in the support files on line 18""" tokens = ["(", ")", ";"] tokenizer = self.TestTokenizer(tokens) parser = VerilogParser() parser.tokenizer = tokenizer parser.current_definition = sdn.Definition - parser.parse_module_header() #intent is to just make sure this does not crash - #todo add some aserts to check to make sure the number of cables and ports is still 0 - + parser.parse_module_header() # intent is to just make sure this does not crash + # todo add some aserts to check to make sure the number of cables and ports is still 0 ################################################### ##Array Slicing @@ -356,8 +532,8 @@ def test_array_slicing_good_single(self): parser = VerilogParser() parser.tokenizer = tokenizer left, right = parser.parse_brackets() - assert(left == left_expected) - assert(right == right_expected) + assert left == left_expected + assert right == right_expected def test_array_slicing_good_both(self): left_expected = 2334 @@ -367,8 +543,8 @@ def test_array_slicing_good_both(self): parser = VerilogParser() parser.tokenizer = tokenizer left, right = parser.parse_brackets() - assert(left == left_expected) - assert(right == right_expected) + assert left == left_expected + assert right == right_expected @unittest.expectedFailure def test_array_slicing_bad_colon(self): @@ -379,9 +555,9 @@ def test_array_slicing_bad_colon(self): parser = VerilogParser() parser.tokenizer = tokenizer left, right = parser.parse_brackets() - assert(left == left_expected) - assert(right == right_expected) - + assert left == left_expected + assert right == right_expected + @unittest.expectedFailure def test_array_slicing_bad_ending(self): left_expected = 2334 @@ -391,8 +567,8 @@ def test_array_slicing_bad_ending(self): parser = VerilogParser() parser.tokenizer = tokenizer left, right = parser.parse_brackets() - assert(left == left_expected) - assert(right == right_expected) + assert left == left_expected + assert right == right_expected @unittest.expectedFailure def test_array_slicing_bad_non_numbers(self): @@ -403,9 +579,8 @@ def test_array_slicing_bad_non_numbers(self): parser = VerilogParser() parser.tokenizer = tokenizer left, right = parser.parse_brackets() - assert(left == left_expected) - assert(right == right_expected) - + assert left == left_expected + assert right == right_expected ################################################### ##Cable Creation and modification @@ -413,128 +588,159 @@ def test_array_slicing_bad_non_numbers(self): def init_cable_creation(self): parser = VerilogParser() - + my_def = sdn.Definition() my_def.name = "testing_definition" c1 = my_def.create_cable() - c1.name = "preexisting1" #[15:8] + c1.name = "preexisting1" # [15:8] c1.create_wires(8) c1.lower_index = 8 c2 = my_def.create_cable() - c2.name = "preexisting2" #[15:0] + c2.name = "preexisting2" # [15:0] c2.create_wires(16) c3 = my_def.create_cable() - c3.name = "preexisting3" #[19:16] + c3.name = "preexisting3" # [19:16] c3.is_downto = False c3.lower_index = 16 c3.create_wires(4) - + parser.current_definition = my_def return parser, c1, c2, c3 def add_to_cable_helper(self, tests, parser): - #tests is a list of tuples that contain - #name,left,right,type,cable,expected_lower,expected_width, expected_downto + # tests is a list of tuples that contain + # name,left,right,type,cable,expected_lower,expected_width, expected_downto for entry in tests: - name, left_index, right_index, var_type, cable, expected_lower, expected_width = entry - expected_downto = cable.is_downto #the cable should not update it's downto once that has been decided. + ( + name, + left_index, + right_index, + var_type, + cable, + expected_lower, + expected_width, + ) = entry + expected_downto = ( + cable.is_downto + ) # the cable should not update it's downto once that has been decided. c = parser.create_or_update_cable(name, left_index, right_index, var_type) assert c is cable, "the cable is not the expected cable, " + name - assert len(c.wires) == expected_width, "the cable is not the proper width, " + name - assert c.lower_index == expected_lower, "the cable does not have the proper lower index, " + name + assert len(c.wires) == expected_width, ( + "the cable is not the proper width, " + name + ) + assert c.lower_index == expected_lower, ( + "the cable does not have the proper lower index, " + name + ) assert c.is_downto == expected_downto, "the cable changed downto, " + name - def create_cable_helper(self, tests, parser): - #tests is a list of tuples that contain - #name,left,right,type,cable,expected_lower,expected_width, expected_downto + # tests is a list of tuples that contain + # name,left,right,type,cable,expected_lower,expected_width, expected_downto start_size = len(parser.current_definition.cables) count = 0 for entry in tests: count += 1 - name, left_index, right_index, var_type, cable, expected_lower, expected_width, expected_downto = entry + ( + name, + left_index, + right_index, + var_type, + cable, + expected_lower, + expected_width, + expected_downto, + ) = entry c = parser.create_or_update_cable(name, left_index, right_index, var_type) - assert len(c.wires) == expected_width, "the cable is not the proper width, " + name - assert c.lower_index == expected_lower, "the cable does not have the proper lower index, " + name + assert len(c.wires) == expected_width, ( + "the cable is not the proper width, " + name + ) + assert c.lower_index == expected_lower, ( + "the cable does not have the proper lower index, " + name + ) assert c.is_downto == expected_downto - assert len(parser.current_definition.cables) == count + start_size, "the wrong number of cables were added" - + assert ( + len(parser.current_definition.cables) == count + start_size + ), "the wrong number of cables were added" def test_add_to_front_of_cable(self): parser, c1, c2, c3 = self.init_cable_creation() - - tests =\ - [("preexisting1", 15, 0, None, c1, 0, 16),\ - ("preexisting2", 0, -16, None, c2, -16, 32),\ - ("preexisting3", 17, 0, None, c3, 0, 20)] - self.add_to_cable_helper(tests, parser) + tests = [ + ("preexisting1", 15, 0, None, c1, 0, 16), + ("preexisting2", 0, -16, None, c2, -16, 32), + ("preexisting3", 17, 0, None, c3, 0, 20), + ] + self.add_to_cable_helper(tests, parser) def test_add_to_back_of_cable(self): parser, c1, c2, c3 = self.init_cable_creation() - - tests =\ - [("preexisting1", 31, 16, None, c1, 8, 24),\ - ("preexisting2", 31, 8, None, c2, 0, 32),\ - ("preexisting3", 63, 0, None, c3, 0, 64)] - self.add_to_cable_helper(tests, parser) + tests = [ + ("preexisting1", 31, 16, None, c1, 8, 24), + ("preexisting2", 31, 8, None, c2, 0, 32), + ("preexisting3", 63, 0, None, c3, 0, 64), + ] + self.add_to_cable_helper(tests, parser) def test_create_cable(self): parser, c1, c2, c3 = self.init_cable_creation() - - tests =\ - [("new_cable1", 31, 16, None, None, 16, 16, True),\ - ("new_cable2", 0, -7, None, None, -7, 8, True),\ - ("new_cable3", 63, 0, None, None, 0, 64, True)] - self.create_cable_helper(tests, parser) + tests = [ + ("new_cable1", 31, 16, None, None, 16, 16, True), + ("new_cable2", 0, -7, None, None, -7, 8, True), + ("new_cable3", 63, 0, None, None, 0, 64, True), + ] + self.create_cable_helper(tests, parser) def test_create_cable_downto(self): parser, c1, c2, c3 = self.init_cable_creation() - - tests =\ - [("new_cable1", 7, 0, None, None, 0, 8, True),\ - ("new_cable2", 0, 7, None, None, 0, 8, False)] + + tests = [ + ("new_cable1", 7, 0, None, None, 0, 8, True), + ("new_cable2", 0, 7, None, None, 0, 8, False), + ] self.create_cable_helper(tests, parser) def test_change_cable_type(self): - pass #TODO + pass # TODO def test_dont_change_cable(self): parser, c1, c2, c3 = self.init_cable_creation() - - tests =\ - [("preexisting1", 15, 8, None, c1, 8, 8),\ - ("preexisting2", 15, 0, None, c2, 0, 16),\ - ("preexisting3", 19, 16, None, c3, 16, 4)] + + tests = [ + ("preexisting1", 15, 8, None, c1, 8, 8), + ("preexisting2", 15, 0, None, c2, 0, 16), + ("preexisting3", 19, 16, None, c3, 16, 4), + ] self.add_to_cable_helper(tests, parser) def test_single_index_cable(self): parser, c1, c2, c3 = self.init_cable_creation() - tests_create =\ - [("new_cable1", 31, None, None, None, 31, 1, True),\ - ("new_cable2", 0, None, None, None, 0, 1, True),\ - ("new_cable3", 63, None, None, None, 63, 1, True)] + tests_create = [ + ("new_cable1", 31, None, None, None, 31, 1, True), + ("new_cable2", 0, None, None, None, 0, 1, True), + ("new_cable3", 63, None, None, None, 63, 1, True), + ] self.create_cable_helper(tests_create, parser) parser, c1, c2, c3 = self.init_cable_creation() - tests_modify =\ - [("preexisting1", 0, None, None, c1, 0, 16),\ - ("preexisting2", 8, None, None, c2, 0, 16),\ - ("preexisting3", 0, None, None, c3, 0, 20)] + tests_modify = [ + ("preexisting1", 0, None, None, c1, 0, 16), + ("preexisting2", 8, None, None, c2, 0, 16), + ("preexisting3", 0, None, None, c3, 0, 20), + ] self.add_to_cable_helper(tests_modify, parser) - def test_change_cable_downto(self): - #i don't think the cable downto-ness should ever change. this is tested in the add to cable helper + # i don't think the cable downto-ness should ever change. this is tested in the add to cable helper parser, c1, c2, c3 = self.init_cable_creation() - - tests =\ - [("preexisting1", 15, 8, None, c1, 8, 8),\ - ("preexisting1", 8, 15, None, c1, 8, 8)] + + tests = [ + ("preexisting1", 15, 8, None, c1, 8, 8), + ("preexisting1", 8, 15, None, c1, 8, 8), + ] self.add_to_cable_helper(tests, parser) def test_cable_prepend_wires(self): @@ -557,7 +763,7 @@ def test_cable_prepend_wires(self): print(c1_wires) print() - + prepend_count = 8 parser.prepend_wires(c1, prepend_count) @@ -568,7 +774,9 @@ def test_cable_prepend_wires(self): assert len(c1.wires) == prepend_count + c1_width, "tried to add 8 wires to c1" assert c1.lower_index == c1_lower - prepend_count for wire in c1.wires[:prepend_count]: - assert wire not in c1_wires, "a wire was in the wrong location for the prepend" + assert ( + wire not in c1_wires + ), "a wire was in the wrong location for the prepend" for wire in c1.wires[prepend_count:]: assert wire in c1_wires, "a wire seems to have disappeared" @@ -576,7 +784,9 @@ def test_cable_prepend_wires(self): assert len(c2.wires) == prepend_count + c2_width, "tried to add 8 wires to c2" assert c2.lower_index == c2_lower - prepend_count for wire in c2.wires[:prepend_count]: - assert wire not in c2_wires, "a wire was in the wrong location for the prepend" + assert ( + wire not in c2_wires + ), "a wire was in the wrong location for the prepend" for wire in c2.wires[prepend_count:]: assert wire in c2_wires, "a wire seems to have disappeared" @@ -584,7 +794,9 @@ def test_cable_prepend_wires(self): assert len(c3.wires) == prepend_count + c3_width, "tried to add 8 wires to c3" assert c3.lower_index == c3_lower - prepend_count for wire in c3.wires[:prepend_count]: - assert wire not in c3_wires, "a wire was in the wrong location for the prepend" + assert ( + wire not in c3_wires + ), "a wire was in the wrong location for the prepend" for wire in c3.wires[prepend_count:]: assert wire in c3_wires, "a wire seems to have disappeared" @@ -605,14 +817,16 @@ def test_cable_postpend_wires(self): c3_wires = set() for wire in c3.wires: c3_wires.add(wire) - + postpend_count = 8 parser.postpend_wires(c1, postpend_count) assert len(c1.wires) == postpend_count + c1_width, "tried to add 8 wires to c1" assert c1.lower_index == c1_lower for wire in c1.wires[c1_width:]: - assert wire not in c1_wires, "a wire was in the wrong location for the postpend" + assert ( + wire not in c1_wires + ), "a wire was in the wrong location for the postpend" for wire in c1.wires[:c1_width]: assert wire in c1_wires, "a wire seems to have disappeared" @@ -620,7 +834,9 @@ def test_cable_postpend_wires(self): assert len(c2.wires) == postpend_count + c2_width, "tried to add 8 wires to c2" assert c2.lower_index == c2_lower for wire in c2.wires[c2_width:]: - assert wire not in c2_wires, "a wire was in the wrong location for the postpend" + assert ( + wire not in c2_wires + ), "a wire was in the wrong location for the postpend" for wire in c2.wires[:c2_width]: assert wire in c2_wires, "a wire seems to have disappeared" @@ -628,29 +844,35 @@ def test_cable_postpend_wires(self): assert len(c3.wires) == postpend_count + c3_width, "tried to add 8 wires to c3" assert c3.lower_index == c3_lower for wire in c3.wires[c3_width:]: - assert wire not in c3_wires, "a wire was in the wrong location for the postpend" + assert ( + wire not in c3_wires + ), "a wire was in the wrong location for the postpend" for wire in c3.wires[:c3_width]: assert wire in c3_wires, "a wire seems to have disappeared" def test_populate_new_cable(self): parser = VerilogParser() - - test_data = [("test_name", 2, 0, "wire"), ("\\escaped#$@_[213] ", 15,8,"wire"), ("some_name", 7,4,"reg")] + + test_data = [ + ("test_name", 2, 0, "wire"), + ("\\escaped#$@_[213] ", 15, 8, "wire"), + ("some_name", 7, 4, "reg"), + ] for name, left, right, cable_type in test_data: cable = sdn.Cable() - parser.populate_new_cable(cable,name,left,right,cable_type) + parser.populate_new_cable(cable, name, left, right, cable_type) assert cable.name == name assert cable.is_downto == (left >= right) assert cable["VERILOG.CableType"] == cable_type - assert cable.lower_index == min(left,right) + assert cable.lower_index == min(left, right) def test_parse_variable_instantiation(self): pass def test_parse_cable_concatenation(self): parser = VerilogParser() - + wire_names = ["wire1", "wire2", "wire3", "wire4"] token_list = ["{"] first = True @@ -668,13 +890,27 @@ def test_parse_cable_concatenation(self): wires = parser.parse_cable_concatenation() - assert len(wires) == len(wire_names), "expected " + str(len(wire_names)) + " wires to be created instead got " + str(len(wires)) - assert len(parser.current_definition.cables) == len(wire_names), "expected " + str(len(wire_names)) + " cables to be created instead got " + str(len(parser.current_definition.cables)) + assert len(wires) == len(wire_names), ( + "expected " + + str(len(wire_names)) + + " wires to be created instead got " + + str(len(wires)) + ) + assert len(parser.current_definition.cables) == len(wire_names), ( + "expected " + + str(len(wire_names)) + + " cables to be created instead got " + + str(len(parser.current_definition.cables)) + ) for i in range(len(wire_names)): - assert parser.current_definition.cables[i].name == wire_names[i], " the wires created do not have matching names" - assert wires[i].cable.name == wire_names[i], "the wires returned are not in order." - + assert ( + parser.current_definition.cables[i].name == wire_names[i] + ), " the wires created do not have matching names" + assert ( + wires[i].cable.name == wire_names[i] + ), "the wires returned are not in order." + ############################################################################ ##Instance instantiation ############################################################################ @@ -687,10 +923,12 @@ def test_parse_empty_port_map(self): definition = sdn.Definition() parser.current_definition = definition parser.current_instance = definition.create_child() - parser.current_instance.reference = parser.blackbox_holder.get_blackbox("definition_name") - + parser.current_instance.reference = parser.blackbox_holder.get_blackbox( + "definition_name" + ) + port_name = "port_name" - + tokens = [".", port_name, "(", ")"] tokenizer = self.TestTokenizer(tokens) @@ -707,7 +945,22 @@ def test_parse_empty_port_map(self): def test_parse_parameter_map(self): parser = VerilogParser() - tokens = ["#", "(", ".", "INIT", "(", "1'h123210", ")", ",", ".", "PARAM2", "(", "1'b0", ")", ")"] + tokens = [ + "#", + "(", + ".", + "INIT", + "(", + "1'h123210", + ")", + ",", + ".", + "PARAM2", + "(", + "1'b0", + ")", + ")", + ] tokenizer = self.TestTokenizer(tokens) parser.tokenizer = tokenizer @@ -716,7 +969,7 @@ def test_parse_parameter_map(self): params = parser.parse_parameter_mapping() assert len(params.keys()) == 2 - assert params['INIT'] == "1'h123210" + assert params["INIT"] == "1'h123210" assert params["PARAM2"] == "1'b0" def test_parse_port_map(self): @@ -743,7 +996,9 @@ def test_parse_port_map(self): parser.current_definition = sdn.Definition() parser.current_instance = parser.current_definition.create_child() - parser.current_instance.reference = parser.blackbox_holder.get_blackbox("definition1") + parser.current_instance.reference = parser.blackbox_holder.get_blackbox( + "definition1" + ) parser.parse_port_mapping() @@ -753,33 +1008,31 @@ def test_parse_port_map(self): for p in parser.current_instance.reference.ports: assert len(p.pins) == 1 for c in parser.current_definition.cables: - assert len(c.wires) ==1 + assert len(c.wires) == 1 for i in range(len(port_names)): assert parser.current_definition.cables[i].name == cable_names[i] assert parser.current_instance.reference.ports[i].name == port_names[i] for p in parser.current_definition.cables[i].wires[0].pins: assert p in parser.current_instance.pins - def test_parse_parameter_map_single(self): parser = VerilogParser() - tokens = [".","INIT", "(", "1hABCD1230", ")"] + tokens = [".", "INIT", "(", "1hABCD1230", ")"] tokenizer = self.TestTokenizer(tokens) parser.tokenizer = tokenizer - k,v = parser.parse_parameter_map_single() + k, v = parser.parse_parameter_map_single() assert k == "INIT" assert v == "1hABCD1230" - def test_parse_parameter_map_single_multi_token_value(self): parser = VerilogParser() - tokens = [".","INIT", "(", "200.000000", ")"] + tokens = [".", "INIT", "(", "200.000000", ")"] tokenizer = self.TestTokenizer(tokens) parser.tokenizer = tokenizer - k,v = parser.parse_parameter_map_single() + k, v = parser.parse_parameter_map_single() assert k == "INIT" assert v == "200.000000" @@ -790,7 +1043,9 @@ def test_parse_port_map_single(self): definition = sdn.Definition() parser.current_definition = definition parser.current_instance = definition.create_child() - parser.current_instance.reference = parser.blackbox_holder.get_blackbox("definition_name") + parser.current_instance.reference = parser.blackbox_holder.get_blackbox( + "definition_name" + ) cable = definition.create_cable() cable_name = "cable_name" cable_width = 4 @@ -835,8 +1090,8 @@ def test_parse_implicitly_mapped_ports(self): instance = next(netlist.get_instances("my_inst")) self.assertEqual(instance.name, "my_inst") connections = ["clk_c", "VCC_net", "out"] - for i in range(0,3): - port = next(instance.get_ports("port_"+str(i))) + for i in range(0, 3): + port = next(instance.get_ports("port_" + str(i))) self.assertEqual(len(port.pins), 1) for pin in port.get_pins(selection=Selection.OUTSIDE): self.assertEqual(pin.wire.cable.name, connections[i]) @@ -862,8 +1117,8 @@ def test_parse_empty_mapped_ports(self): # my_inst has nothing attached instance = next(netlist.get_instances("my_inst")) self.assertEqual(instance.name, "my_inst") - for i in range(0,3): - port = next(instance.get_ports("port_"+str(i))) + for i in range(0, 3): + port = next(instance.get_ports("port_" + str(i))) self.assertEqual(len(port.pins), 1) for pin in port.get_pins(selection=Selection.OUTSIDE): self.assertEqual(pin.wire, None) @@ -871,8 +1126,8 @@ def test_parse_empty_mapped_ports(self): # my_whitespace_inst has nothing attached and doesn't immediately have a closing paren instance = next(netlist.get_instances("my_whitespace_inst")) self.assertEqual(instance.name, "my_whitespace_inst") - for i in range(0,3): - port = next(instance.get_ports("port_"+str(i))) + for i in range(0, 3): + port = next(instance.get_ports("port_" + str(i))) self.assertEqual(len(port.pins), 1) for pin in port.get_pins(selection=Selection.OUTSIDE): self.assertEqual(pin.wire, None) @@ -885,130 +1140,175 @@ def test_parse_empty_mapped_ports(self): def init_port_creation(self): parser = VerilogParser() - + my_def = sdn.Definition() my_def.name = "testing_definition" c1 = my_def.create_port() - c1.name = "preexisting1" #[15:8] + c1.name = "preexisting1" # [15:8] c1.create_pins(8) c1.lower_index = 8 c2 = my_def.create_port() - c2.name = "preexisting2" #[15:0] + c2.name = "preexisting2" # [15:0] c2.create_pins(16) c3 = my_def.create_port() - c3.name = "preexisting3" #[19:16] + c3.name = "preexisting3" # [19:16] c3.is_downto = False c3.lower_index = 16 c3.create_pins(4) - + parser.current_definition = my_def return parser, c1, c2, c3 def add_to_port_helper(self, tests, parser): - #tests is a list of tuples that contain - #name,left,right,direction,port,expected_lower,expected_width, expected_downto + # tests is a list of tuples that contain + # name,left,right,direction,port,expected_lower,expected_width, expected_downto for entry in tests: - name, left_index, right_index, direction, port, expected_lower, expected_width = entry - expected_downto = port.is_downto #the port should not update it's downto once that has been decided. + ( + name, + left_index, + right_index, + direction, + port, + expected_lower, + expected_width, + ) = entry + expected_downto = ( + port.is_downto + ) # the port should not update it's downto once that has been decided. c = parser.create_or_update_port(name, left_index, right_index, direction) assert c is port, "the port is not the expected port, " + name - assert len(c.pins) == expected_width, "the port is not the proper width, " + name - assert c.lower_index == expected_lower, "the port does not have the proper lower index, " + name + assert len(c.pins) == expected_width, ( + "the port is not the proper width, " + name + ) + assert c.lower_index == expected_lower, ( + "the port does not have the proper lower index, " + name + ) assert c.is_downto == expected_downto, "the port changed downto, " + name - assert c.direction == direction, "the port is no longer "+ direction+ " it is now "+ c.direction+ " " + name - + assert c.direction == direction, ( + "the port is no longer " + + direction + + " it is now " + + c.direction + + " " + + name + ) def create_port_helper(self, tests, parser): - #tests is a list of tuples that contain - #name,left,right,direction,port,expected_lower,expected_width, expected_downto + # tests is a list of tuples that contain + # name,left,right,direction,port,expected_lower,expected_width, expected_downto start_size = len(parser.current_definition.ports) count = 0 for entry in tests: count += 1 - name, left_index, right_index, direction, port, expected_lower, expected_width, expected_downto = entry + ( + name, + left_index, + right_index, + direction, + port, + expected_lower, + expected_width, + expected_downto, + ) = entry c = parser.create_or_update_port(name, left_index, right_index, direction) - assert len(c.pins) == expected_width, "the port is not the proper width, " + name - assert c.lower_index == expected_lower, "the port does not have the proper lower index, " + name + assert len(c.pins) == expected_width, ( + "the port is not the proper width, " + name + ) + assert c.lower_index == expected_lower, ( + "the port does not have the proper lower index, " + name + ) assert c.is_downto == expected_downto - assert c.direction == direction, "the port is no longer " + direction + " it is now " + c.direction+ " " + name - assert len(parser.current_definition.ports) == count + start_size, "the wrong number of ports were added" - + assert c.direction == direction, ( + "the port is no longer " + + direction + + " it is now " + + c.direction + + " " + + name + ) + assert ( + len(parser.current_definition.ports) == count + start_size + ), "the wrong number of ports were added" def test_add_to_front_of_port(self): parser, c1, c2, c3 = self.init_port_creation() - - tests =\ - [("preexisting1", 15, 0, sdn.Port.Direction.IN, c1, 0, 16),\ - ("preexisting2", 0, -16, sdn.Port.Direction.OUT, c2, -16, 32),\ - ("preexisting3", 17, 0, sdn.Port.Direction.INOUT, c3, 0, 20)] - self.add_to_port_helper(tests, parser) + tests = [ + ("preexisting1", 15, 0, sdn.Port.Direction.IN, c1, 0, 16), + ("preexisting2", 0, -16, sdn.Port.Direction.OUT, c2, -16, 32), + ("preexisting3", 17, 0, sdn.Port.Direction.INOUT, c3, 0, 20), + ] + self.add_to_port_helper(tests, parser) def test_add_to_back_of_port(self): parser, c1, c2, c3 = self.init_port_creation() - - tests =\ - [("preexisting1", 31, 16, sdn.Port.Direction.UNDEFINED, c1, 8, 24),\ - ("preexisting2", 31, 8, sdn.Port.Direction.IN, c2, 0, 32),\ - ("preexisting3", 63, 0, sdn.Port.Direction.OUT, c3, 0, 64)] - self.add_to_port_helper(tests, parser) + tests = [ + ("preexisting1", 31, 16, sdn.Port.Direction.UNDEFINED, c1, 8, 24), + ("preexisting2", 31, 8, sdn.Port.Direction.IN, c2, 0, 32), + ("preexisting3", 63, 0, sdn.Port.Direction.OUT, c3, 0, 64), + ] + self.add_to_port_helper(tests, parser) def test_create_port(self): parser, c1, c2, c3 = self.init_port_creation() - - tests =\ - [("new_port1", 31, 16, sdn.Port.Direction.IN, None, 16, 16, True),\ - ("new_port2", 0, -7, sdn.Port.Direction.INOUT, None, -7, 8, True),\ - ("new_port3", 63, 0, sdn.Port.Direction.UNDEFINED, None, 0, 64, True)] - self.create_port_helper(tests, parser) + tests = [ + ("new_port1", 31, 16, sdn.Port.Direction.IN, None, 16, 16, True), + ("new_port2", 0, -7, sdn.Port.Direction.INOUT, None, -7, 8, True), + ("new_port3", 63, 0, sdn.Port.Direction.UNDEFINED, None, 0, 64, True), + ] + self.create_port_helper(tests, parser) def test_create_port_downto(self): parser, c1, c2, c3 = self.init_port_creation() - - tests =\ - [("new_port1", 7, 0, sdn.Port.Direction.OUT, None, 0, 8, True),\ - ("new_port2", 0, 7, sdn.Port.Direction.INOUT, None, 0, 8, False)] + + tests = [ + ("new_port1", 7, 0, sdn.Port.Direction.OUT, None, 0, 8, True), + ("new_port2", 0, 7, sdn.Port.Direction.INOUT, None, 0, 8, False), + ] self.create_port_helper(tests, parser) def test_change_port_direction(self): - pass #TODO not sure yet how I should deal with this. + pass # TODO not sure yet how I should deal with this. def test_dont_change_port(self): parser, c1, c2, c3 = self.init_port_creation() - - tests =\ - [("preexisting1", 15, 8, sdn.Port.Direction.OUT, c1, 8, 8),\ - ("preexisting2", 15, 0, sdn.Port.Direction.IN, c2, 0, 16),\ - ("preexisting3", 19, 16, sdn.Port.Direction.INOUT, c3, 16, 4)] + + tests = [ + ("preexisting1", 15, 8, sdn.Port.Direction.OUT, c1, 8, 8), + ("preexisting2", 15, 0, sdn.Port.Direction.IN, c2, 0, 16), + ("preexisting3", 19, 16, sdn.Port.Direction.INOUT, c3, 16, 4), + ] self.add_to_port_helper(tests, parser) def test_single_index_port(self): parser, c1, c2, c3 = self.init_port_creation() - tests_create =\ - [("new_port1", 31, None, sdn.Port.Direction.OUT, None, 31, 1, True),\ - ("new_port2", 0, None, sdn.Port.Direction.UNDEFINED, None, 0, 1, True),\ - ("new_port3", 63, None, sdn.Port.Direction.IN, None, 63, 1, True)] + tests_create = [ + ("new_port1", 31, None, sdn.Port.Direction.OUT, None, 31, 1, True), + ("new_port2", 0, None, sdn.Port.Direction.UNDEFINED, None, 0, 1, True), + ("new_port3", 63, None, sdn.Port.Direction.IN, None, 63, 1, True), + ] self.create_port_helper(tests_create, parser) parser, c1, c2, c3 = self.init_port_creation() - tests_modify =\ - [("preexisting1", 0, None, sdn.Port.Direction.INOUT, c1, 0, 16),\ - ("preexisting2", 8, None, sdn.Port.Direction.OUT, c2, 0, 16),\ - ("preexisting3", 0, None, sdn.Port.Direction.IN, c3, 0, 20)] + tests_modify = [ + ("preexisting1", 0, None, sdn.Port.Direction.INOUT, c1, 0, 16), + ("preexisting2", 8, None, sdn.Port.Direction.OUT, c2, 0, 16), + ("preexisting3", 0, None, sdn.Port.Direction.IN, c3, 0, 20), + ] self.add_to_port_helper(tests_modify, parser) - def test_change_port_downto(self): - #i don't think the port downto-ness should ever change. this is tested in the add to port helper + # i don't think the port downto-ness should ever change. this is tested in the add to port helper parser, c1, c2, c3 = self.init_port_creation() - - tests =\ - [("preexisting1", 15, 8, sdn.Port.Direction.UNDEFINED, c1, 8, 8),\ - ("preexisting1", 8, 15, sdn.Port.Direction.UNDEFINED, c1, 8, 8)] + + tests = [ + ("preexisting1", 15, 8, sdn.Port.Direction.UNDEFINED, c1, 8, 8), + ("preexisting1", 8, 15, sdn.Port.Direction.UNDEFINED, c1, 8, 8), + ] self.add_to_port_helper(tests, parser) def test_port_prepend_pins(self): @@ -1031,7 +1331,7 @@ def test_port_prepend_pins(self): print(c1_pins) print() - + prepend_count = 8 parser.prepend_pins(c1, prepend_count) @@ -1079,14 +1379,16 @@ def test_port_postpend_pins(self): c3_pins = set() for pin in c3.pins: c3_pins.add(pin) - + postpend_count = 8 parser.postpend_pins(c1, postpend_count) assert len(c1.pins) == postpend_count + c1_width, "tried to add 8 pins to c1" assert c1.lower_index == c1_lower for pin in c1.pins[c1_width:]: - assert pin not in c1_pins, "a pin was in the wrong location for the postpend" + assert ( + pin not in c1_pins + ), "a pin was in the wrong location for the postpend" for pin in c1.pins[:c1_width]: assert pin in c1_pins, "a pin seems to have disappeared" @@ -1094,7 +1396,9 @@ def test_port_postpend_pins(self): assert len(c2.pins) == postpend_count + c2_width, "tried to add 8 pins to c2" assert c2.lower_index == c2_lower for pin in c2.pins[c2_width:]: - assert pin not in c2_pins, "a pin was in the wrong location for the postpend" + assert ( + pin not in c2_pins + ), "a pin was in the wrong location for the postpend" for pin in c2.pins[:c2_width]: assert pin in c2_pins, "a pin seems to have disappeared" @@ -1102,32 +1406,54 @@ def test_port_postpend_pins(self): assert len(c3.pins) == postpend_count + c3_width, "tried to add 8 pins to c3" assert c3.lower_index == c3_lower for pin in c3.pins[c3_width:]: - assert pin not in c3_pins, "a pin was in the wrong location for the postpend" + assert ( + pin not in c3_pins + ), "a pin was in the wrong location for the postpend" for pin in c3.pins[:c3_width]: assert pin in c3_pins, "a pin seems to have disappeared" def test_populate_new_port(self): parser = VerilogParser() - - test_data = [("test_name", 2, 0, sdn.Port.Direction.IN), ("\\escaped#$@_[213] ", 15,8, sdn.Port.Direction.OUT), ("some_name", 7,4,sdn.Port.Direction.INOUT)] + + test_data = [ + ("test_name", 2, 0, sdn.Port.Direction.IN), + ("\\escaped#$@_[213] ", 15, 8, sdn.Port.Direction.OUT), + ("some_name", 7, 4, sdn.Port.Direction.INOUT), + ] for name, left, right, direction in test_data: port = sdn.Port() - parser.populate_new_port(port,name,left,right,direction) + parser.populate_new_port(port, name, left, right, direction) assert port.name == name assert port.is_downto == (left >= right) assert port.direction == direction - assert port.lower_index == min(left,right) + assert port.lower_index == min(left, right) def test_parse_port_declaration(self): parser = VerilogParser() count = 3 names = ["i", "o", "io"] - token_list = ["input", names[0], ";", "output", "[", "3", ":", "0", "]", names[1], ";", "inout", "wire", names[2], ";"] + token_list = [ + "input", + names[0], + ";", + "output", + "[", + "3", + ":", + "0", + "]", + names[1], + ";", + "inout", + "wire", + names[2], + ";", + ] tokenizer = self.TestTokenizer(token_list) parser.tokenizer = tokenizer d = sdn.Definition() - + parser.current_definition = d for n in names: @@ -1138,32 +1464,49 @@ def test_parse_port_declaration(self): for _ in range(count): parser.parse_port_declaration({}) - @unittest.expectedFailure def test_parse_port_declaration_failure(self): parser = VerilogParser() count = 3 names = ["i", "o", "io"] - token_list = ["input", names[0], ";", "output", "[", "3", ":", "0", "]", names[1], ";", "inout", "wire", names[2], ";"] + token_list = [ + "input", + names[0], + ";", + "output", + "[", + "3", + ":", + "0", + "]", + names[1], + ";", + "inout", + "wire", + names[2], + ";", + ] tokenizer = self.TestTokenizer(token_list) parser.tokenizer = tokenizer d = sdn.Definition() - + parser.current_definition = d for n in names: parser.create_or_update_port(n) - #the ports are in the definition but not connected this should fail + # the ports are in the definition but not connected this should fail for _ in range(count): - parser.parse_port_declaration(properties = {}) + parser.parse_port_declaration(properties={}) def test_create_or_update_port_on_instance(self): parser = VerilogParser() parser.current_definition = sdn.Definition() parser.current_instance = parser.current_definition.create_child() - parser.current_instance.reference = parser.blackbox_holder.get_blackbox("definition1") + parser.current_instance.reference = parser.blackbox_holder.get_blackbox( + "definition1" + ) pins = parser.create_or_update_port_on_instance("port1", 1) @@ -1177,8 +1520,9 @@ def test_create_or_update_port_on_instance(self): ############################################ def test_create_new_assignment_instance(self): - '''make sure the name, and width make sense - also take advantage of the setup to make sure the definition returned is the same for the same width''' + """make sure the name, and width make sense + also take advantage of the setup to make sure the definition returned is the same for the same width + """ parser = VerilogParser() parser.netlist = sdn.Netlist() parser.current_definition = sdn.Definition() @@ -1189,7 +1533,7 @@ def test_create_new_assignment_instance(self): assert instance.reference == parser.get_assignment_definition(width) def test_create_new_assignment_definition(self): - '''make sure the names, width and acutal connectivity make sense''' + """make sure the names, width and acutal connectivity make sense""" parser = VerilogParser() parser.netlist = sdn.Netlist() parser.current_definition = sdn.Definition() @@ -1201,22 +1545,19 @@ def test_create_new_assignment_definition(self): assert len(definition.ports[1].pins) == width assert len(definition.cables) == 0 - - def test_connect_assigned_wires(self): - '''make sure the wires are actually connected to the instance and that the connectivity makes sense''' + """make sure the wires are actually connected to the instance and that the connectivity makes sense""" parser = VerilogParser() parser.netlist = sdn.Netlist() parser.current_definition = sdn.Definition() - o_cable = parser.current_definition.create_cable(name = "c1") - i_cable = parser.current_definition.create_cable(name = "c2") + o_cable = parser.current_definition.create_cable(name="c1") + i_cable = parser.current_definition.create_cable(name="c2") o_cable.create_wires(4) i_cable.create_wires(4) parser.connect_wires_for_assign(o_cable, 1, 0, i_cable, 3, 2) - def test_names_of_instances_are_different(self): - '''make sure the names of multiple instances of the same width are different''' + """make sure the names of multiple instances of the same width are different""" parser = VerilogParser() parser.netlist = sdn.Netlist() parser.current_definition = sdn.Definition() @@ -1230,7 +1571,21 @@ def test_parse_assign(self): parser = VerilogParser() parser.netlist = sdn.Netlist() parser.current_definition = sdn.Definition() - tokens = ["assign", "cable1", "=", "cable2", ";", "assign", "SR2", "[", "2", "]", "=", "\\ ", ";"] + tokens = [ + "assign", + "cable1", + "=", + "cable2", + ";", + "assign", + "SR2", + "[", + "2", + "]", + "=", + "\\ ", + ";", + ] tokenizer = self.TestTokenizer(tokens) parser.tokenizer = tokenizer c1, o_left, o_right, c2, i_left, i_right = parser.parse_assign() @@ -1251,31 +1606,31 @@ def test_parse_assign(self): ############################################ ##Parse star parameters ############################################ - + def test_parse_star_with_value(self): - tokens = ['(', '*', 'key', '=', 'value', '*', ')'] + tokens = ["(", "*", "key", "=", "value", "*", ")"] tokenizer = self.TestTokenizer(tokens) parser = VerilogParser() parser.tokenizer = tokenizer - + stars = parser.parse_star_property() - for k,v in stars.items(): + for k, v in stars.items(): assert k == "key" assert v == "value" def test_parser_star_without_value(self): - tokens = ['(', '*', 'key', '*', ')'] + tokens = ["(", "*", "key", "*", ")"] tokenizer = self.TestTokenizer(tokens) parser = VerilogParser() parser.tokenizer = tokenizer - + stars = parser.parse_star_property() - for k,v in stars.items(): + for k, v in stars.items(): assert k == "key" assert v is None def test_parser_star_list(self): - '''example taken from a file that is not in our support files. + """example taken from a file that is not in our support files. the construct in question is referenced in xilinx documentation (* KEEP, DONT_TOUCH, BEL = "C6LUT" *) additionally: @@ -1283,15 +1638,43 @@ def test_parser_star_list(self): and I presume that: (* KEEP, DONT_TOUCH *) would all be valid - ''' - tokens = ["(", "*", "KEEP", ",", "DONT_TOUCH", ",", "BEL", "=", '"C6LUT"', "*", ")",\ - "(", "*", "BEL", "=", '"H6LUT"', ",", "RLOC", "=", '"X0Y0"', "*", ")",\ - "(", "*", "KEEP", ",", "DONT_TOUCH", "*", ")"] - + """ + tokens = [ + "(", + "*", + "KEEP", + ",", + "DONT_TOUCH", + ",", + "BEL", + "=", + '"C6LUT"', + "*", + ")", + "(", + "*", + "BEL", + "=", + '"H6LUT"', + ",", + "RLOC", + "=", + '"X0Y0"', + "*", + ")", + "(", + "*", + "KEEP", + ",", + "DONT_TOUCH", + "*", + ")", + ] + tokenizer = self.TestTokenizer(tokens) parser = VerilogParser() parser.tokenizer = tokenizer - + stars0 = parser.parse_star_property() stars1 = parser.parse_star_property() stars2 = parser.parse_star_property() @@ -1312,7 +1695,7 @@ def test_parser_star_list(self): assert stars2["KEEP"] == None assert "DONT_TOUCH" in stars2 assert stars2["DONT_TOUCH"] == None - + ############################################ ##test hierarchy ############################################ @@ -1344,7 +1727,7 @@ def test_hierarchy_fixing(self): ################################################# ## Other tests ################################################# - + def test_partially_connected_ports(self): # make sure partially connected ports connect pins on lower end of the port # create a little netlist to use @@ -1385,14 +1768,23 @@ def test_partially_connected_ports(self): netlist = sdn.parse("test_netlist.v") for inst in netlist.get_instances(): for port in inst.get_ports(): - pins = list(p for p in port.get_pins(selection=Selection.OUTSIDE, filter=lambda x: x.instance==inst)) + pins = list( + p + for p in port.get_pins( + selection=Selection.OUTSIDE, filter=lambda x: x.instance == inst + ) + ) pins.reverse() if not all(p.wire for p in pins) and any(p.wire for p in pins): wires = list(p.wire for p in pins if p.wire) for i in range(len(wires)): - assert pins[i].wire, "The wire is " + str(pins[i].wire + " but should be connected") - for i in range(len(pins)-len(wires)): - assert pins[len(wires)+i].wire is None, "The wire is " + str(pins[i].wire + " but should NOT be connected") + assert pins[i].wire, "The wire is " + str( + pins[i].wire + " but should be connected" + ) + for i in range(len(pins) - len(wires)): + assert pins[len(wires) + i].wire is None, "The wire is " + str( + pins[i].wire + " but should NOT be connected" + ) os.remove("test_netlist.v") @@ -1415,7 +1807,7 @@ def test_get_all_ports_from_wires(self): groups = [[wire1, wire2, wire3], [wire1, wire2], [wire1], [wire3]] expected_results = [[port1, port2], [port1, port2], [port1], []] - + parser = VerilogParser() for i in range(len(groups)): @@ -1425,10 +1817,8 @@ def test_get_all_ports_from_wires(self): assert r in expected_results[i] for r in expected_results[i]: assert r in actual_results - def test_get_wires_from_cable_helper(self): - parser = VerilogParser() cable1 = sdn.Cable() @@ -1439,17 +1829,29 @@ def test_get_wires_from_cable_helper(self): cable2.create_wires(8) cable2.lower_index = 0 - #add the cable.lower_index to all tests + # add the cable.lower_index to all tests - tests = [(7,0), (0, None), (0,0), (1,None), (2,4)] + tests = [(7, 0), (0, None), (0, 0), (1, None), (2, 4)] e11 = [] e21 = [] - for i in reversed(range(0,8)): + for i in reversed(range(0, 8)): e11.append(cable1.wires[i]) e21.append(cable2.wires[i]) - expected1 = [e11, [cable1.wires[0]], [cable1.wires[0]], [cable1.wires[1]], cable1.wires[2:5]] - expected2 = [e21, [cable2.wires[0]], [cable2.wires[0]], [cable2.wires[1]], cable2.wires[2:5]] + expected1 = [ + e11, + [cable1.wires[0]], + [cable1.wires[0]], + [cable1.wires[1]], + cable1.wires[2:5], + ] + expected2 = [ + e21, + [cable2.wires[0]], + [cable2.wires[0]], + [cable2.wires[1]], + cable2.wires[2:5], + ] expected1[4].reverse() expected2[4].reverse() @@ -1471,7 +1873,9 @@ def test_get_wires_from_cable_helper(self): for j in range(len(expected1[i])): w11 = wires1[j] w12 = expected1[i][j] - assert w11 == w12, "the wires are not the same or not in the same order." + assert ( + w11 == w12 + ), "the wires are not the same or not in the same order." w21 = wires2[j] w22 = expected2[i][j] assert w21 == w22, "the wires are not the same or not in the same order" @@ -1503,5 +1907,5 @@ def test_constant_parsing(self): self.assertEqual(cable.name, "\\", "Check const wire name") -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/spydrnet/parsers/verilog/tests/test_verilog_tokens.py b/tests/spydrnet/parsers/verilog/tests/test_verilog_tokens.py index 29826c66..35bd7d82 100644 --- a/tests/spydrnet/parsers/verilog/tests/test_verilog_tokens.py +++ b/tests/spydrnet/parsers/verilog/tests/test_verilog_tokens.py @@ -5,15 +5,19 @@ class TestVerilogTokens(unittest.TestCase): - - def test_valid_identifier(self): identifiers = ["valid", "_valid", "\\^[0]should_be_valid ", "_1293i123"] for i in identifiers: assert vt.is_valid_identifier(i) def test_invalid_identifier(self): - identifiers = ["not valid", "6invalid" "^[0]no_escape...", "\\space in escaped ", "", "!"] + identifiers = [ + "not valid", + "6invalid" "^[0]no_escape...", + "\\space in escaped ", + "", + "!", + ] for i in identifiers: assert not vt.is_valid_identifier(i) @@ -23,13 +27,18 @@ def test_valid_number(self): assert vt.is_numeric(n) def test_invalid_number(self): - #we could change this so that a decimal point is still a valid number if needed. + # we could change this so that a decimal point is still a valid number if needed. numbers = ["123123.12903", "\\*#@(&$#@*$", "123 3901", ""] for n in numbers: assert not vt.is_numeric(n) def test_convert_string_to_direction(self): strings = ["input", "output", "inout", "unknown"] - values = [sdn.Port.Direction.IN, sdn.Port.Direction.OUT, sdn.Port.Direction.INOUT, sdn.Port.Direction.UNDEFINED] + values = [ + sdn.Port.Direction.IN, + sdn.Port.Direction.OUT, + sdn.Port.Direction.INOUT, + sdn.Port.Direction.UNDEFINED, + ] for i in range(len(strings)): - assert vt.string_to_port_direction(strings[i]) == values[i] \ No newline at end of file + assert vt.string_to_port_direction(strings[i]) == values[i] diff --git a/tests/spydrnet/plugins/namespace_manager/tests/test_edif_namespace.py b/tests/spydrnet/plugins/namespace_manager/tests/test_edif_namespace.py index e3f69e5b..a60a7672 100644 --- a/tests/spydrnet/plugins/namespace_manager/tests/test_edif_namespace.py +++ b/tests/spydrnet/plugins/namespace_manager/tests/test_edif_namespace.py @@ -4,6 +4,7 @@ class TestEdifNamespace(unittest.TestCase): original_default = None + @classmethod def setUpClass(cls) -> None: cls.original_default = sdn.namespace_manager.default @@ -31,165 +32,165 @@ def test_basic_setup(self): netlist = self.gen_netlist() lib1 = netlist.create_library() lib2 = netlist.create_library() - lib1['EDIF.identifier'] = "my_lib1" - lib2['EDIF.identifier'] = "my_lib2" + lib1["EDIF.identifier"] = "my_lib1" + lib2["EDIF.identifier"] = "my_lib2" def1 = lib1.create_definition() - def1['EDIF.identifier'] = "d1" + def1["EDIF.identifier"] = "d1" def2 = lib2.create_definition() - def2['EDIF.identifier'] = "d1" + def2["EDIF.identifier"] = "d1" def3 = lib1.create_definition() - def3['EDIF.identifier'] = "my_lib1" + def3["EDIF.identifier"] = "my_lib1" c1 = def1.create_cable() p1 = def1.create_port() i1 = def1.create_child() c2 = def1.create_cable() p2 = def1.create_port() i2 = def1.create_child() - c1['EDIF.identifier'] = "&1" - i1['EDIF.identifier'] = "&1" - p1['EDIF.identifier'] = "&1" - c2['EDIF.identifier'] = "&2" - i2['EDIF.identifier'] = "&2" - p2['EDIF.identifier'] = "&2" + c1["EDIF.identifier"] = "&1" + i1["EDIF.identifier"] = "&1" + p1["EDIF.identifier"] = "&1" + c2["EDIF.identifier"] = "&2" + i2["EDIF.identifier"] = "&2" + p2["EDIF.identifier"] = "&2" def test_dont_track_orphaned(self): netlist = self.gen_netlist() lib1 = sdn.Library() lib2 = sdn.Library() - lib1['EDIF.identifier'] = "my_lib1" - lib2['EDIF.identifier'] = "my_lib1" + lib1["EDIF.identifier"] = "my_lib1" + lib2["EDIF.identifier"] = "my_lib1" @unittest.expectedFailure def test_duplicate_library_name(self): netlist = self.gen_netlist() lib1 = netlist.create_library() lib2 = netlist.create_library() - lib1['EDIF.identifier'] = "my_lib" - lib2['EDIF.identifier'] = "my_lib" + lib1["EDIF.identifier"] = "my_lib" + lib2["EDIF.identifier"] = "my_lib" @unittest.expectedFailure def test_duplicate_definition_name(self): lib1 = self.gen_library() def1 = lib1.create_definition() def2 = lib1.create_definition() - def1['EDIF.identifier'] = "my_lib" - def2['EDIF.identifier'] = "my_lib" + def1["EDIF.identifier"] = "my_lib" + def2["EDIF.identifier"] = "my_lib" def test_duplicate_definition_elements(self): def1 = self.gen_definition() port = def1.create_port() instance = def1.create_child() cable = def1.create_cable() - port['EDIF.identifier'] = "my_lib" - instance['EDIF.identifier'] = "my_lib" - cable['EDIF.identifier'] = "my_lib" + port["EDIF.identifier"] = "my_lib" + instance["EDIF.identifier"] = "my_lib" + cable["EDIF.identifier"] = "my_lib" @unittest.expectedFailure def test_duplicate_definition_ports(self): def1 = self.gen_definition() port = def1.create_port() port2 = def1.create_port() - port['EDIF.identifier'] = "my_lib" - port2['EDIF.identifier'] = "my_lib" + port["EDIF.identifier"] = "my_lib" + port2["EDIF.identifier"] = "my_lib" @unittest.expectedFailure def test_duplicate_definition_cables(self): def1 = self.gen_definition() cable = def1.create_cable() cable2 = def1.create_cable() - cable['EDIF.identifier'] = "my_lib" - cable2['EDIF.identifier'] = "my_lib" + cable["EDIF.identifier"] = "my_lib" + cable2["EDIF.identifier"] = "my_lib" @unittest.expectedFailure def test_duplicate_definition_children(self): def1 = self.gen_definition() instance = def1.create_child() instance2 = def1.create_child() - instance['EDIF.identifier'] = "my_lib" - instance2['EDIF.identifier'] = "my_lib" + instance["EDIF.identifier"] = "my_lib" + instance2["EDIF.identifier"] = "my_lib" def test_rename(self): netlist = self.gen_netlist() lib1 = netlist.create_library() - lib1['EDIF.identifier'] = "my_lib1" - lib1['EDIF.identifier'] = "my_lib2" - lib1['EDIF.identifier'] = "my_lib1" + lib1["EDIF.identifier"] = "my_lib1" + lib1["EDIF.identifier"] = "my_lib2" + lib1["EDIF.identifier"] = "my_lib1" lib2 = netlist.create_library() - lib2['EDIF.identifier'] = "my_lib2" + lib2["EDIF.identifier"] = "my_lib2" def1 = lib1.create_definition() - def1['EDIF.identifier'] = "my_lib1" - def1['EDIF.identifier'] = "my_lib2" - def1['EDIF.identifier'] = "my_lib1" + def1["EDIF.identifier"] = "my_lib1" + def1["EDIF.identifier"] = "my_lib2" + def1["EDIF.identifier"] = "my_lib1" def2 = lib1.create_definition() - def2['EDIF.identifier'] = "my_lib2" + def2["EDIF.identifier"] = "my_lib2" c = def1.create_cable() - c['EDIF.identifier'] = "&1" - c['EDIF.identifier'] = "&2" - c['EDIF.identifier'] = "&1" + c["EDIF.identifier"] = "&1" + c["EDIF.identifier"] = "&2" + c["EDIF.identifier"] = "&1" p = def1.create_port() - p['EDIF.identifier'] = "&1" - p['EDIF.identifier'] = "&2" - p['EDIF.identifier'] = "&1" + p["EDIF.identifier"] = "&1" + p["EDIF.identifier"] = "&2" + p["EDIF.identifier"] = "&1" i = def1.create_child() - i['EDIF.identifier'] = "&1" - i['EDIF.identifier'] = "&2" - i['EDIF.identifier'] = "&1" + i["EDIF.identifier"] = "&1" + i["EDIF.identifier"] = "&2" + i["EDIF.identifier"] = "&1" def test_remove(self): netlist = self.gen_netlist() lib1 = netlist.create_library() - lib1['EDIF.identifier'] = "my_lib1" + lib1["EDIF.identifier"] = "my_lib1" netlist.remove_library(lib1) lib2 = netlist.create_library() - lib2['EDIF.identifier'] = "my_lib1" + lib2["EDIF.identifier"] = "my_lib1" def1 = lib2.create_definition() - def1['EDIF.identifier'] = "my_lib1" + def1["EDIF.identifier"] = "my_lib1" lib2.remove_definition(def1) def2 = lib2.create_definition() - def2['EDIF.identifier'] = "my_lib1" + def2["EDIF.identifier"] = "my_lib1" c1 = def2.create_cable() c2 = def2.create_cable() p1 = def2.create_port() p2 = def2.create_port() i1 = def2.create_child() i2 = def2.create_child() - c1['EDIF.identifier'] = "&1" + c1["EDIF.identifier"] = "&1" def2.remove_cable(c1) - c2['EDIF.identifier'] = "&1" - p1['EDIF.identifier'] = "&1" + c2["EDIF.identifier"] = "&1" + p1["EDIF.identifier"] = "&1" def2.remove_port(p1) - p2['EDIF.identifier'] = "&1" - i1['EDIF.identifier'] = "&1" + p2["EDIF.identifier"] = "&1" + i1["EDIF.identifier"] = "&1" def2.remove_child(i1) - i2['EDIF.identifier'] = "&1" + i2["EDIF.identifier"] = "&1" def test_orphaned_add(self): netlist = self.gen_netlist() lib1 = sdn.Library() - lib1["EDIF.identifier"] = '&1' + lib1["EDIF.identifier"] = "&1" netlist.add_library(lib1) @unittest.expectedFailure def test_orphaned_add_collision(self): netlist = self.gen_netlist() lib1 = sdn.Library() - lib1["EDIF.identifier"] = '&1' + lib1["EDIF.identifier"] = "&1" netlist.add_library(lib1) lib2 = sdn.Library() - lib2["EDIF.identifier"] = '&1' + lib2["EDIF.identifier"] = "&1" netlist.add_library(lib2) def test_remove_twice_library(self): netlist = self.gen_netlist() lib1 = netlist.create_library() - lib1['EDIF.identifier'] = "my_lib1" + lib1["EDIF.identifier"] = "my_lib1" netlist.remove_library(lib1) self.assertRaises(Exception, netlist.remove_library, lib1) def test_remove_twice_definition(self): lib = self.gen_library() d1 = lib.create_definition() - d1['EDIF.identifier'] = "&1" + d1["EDIF.identifier"] = "&1" lib.remove_definition(d1) self.assertRaises(Exception, lib.remove_definition, d1) @@ -227,30 +228,30 @@ def test_remove_tracked(self): def test_pop_name(self): netlist = self.gen_netlist() lib1 = netlist.create_library() - lib1['EDIF.identifier'] = "my_lib1" - lib1.pop('EDIF.identifier') + lib1["EDIF.identifier"] = "my_lib1" + lib1.pop("EDIF.identifier") lib2 = netlist.create_library() - lib2['EDIF.identifier'] = "my_lib1" + lib2["EDIF.identifier"] = "my_lib1" def1 = lib2.create_definition() - def1['EDIF.identifier'] = "my_lib1" - def1.pop('EDIF.identifier') + def1["EDIF.identifier"] = "my_lib1" + def1.pop("EDIF.identifier") def2 = lib2.create_definition() - def2['EDIF.identifier'] = "my_lib1" + def2["EDIF.identifier"] = "my_lib1" c1 = def2.create_cable() c2 = def2.create_cable() p1 = def2.create_port() p2 = def2.create_port() i1 = def2.create_child() i2 = def2.create_child() - c1['EDIF.identifier'] = "&1" - c1.pop('EDIF.identifier') - c2['EDIF.identifier'] = "&1" - p1['EDIF.identifier'] = "&1" - p1.pop('EDIF.identifier') - p2['EDIF.identifier'] = "&1" - i1['EDIF.identifier'] = "&1" - i1.pop('EDIF.identifier') - i2['EDIF.identifier'] = "&1" + c1["EDIF.identifier"] = "&1" + c1.pop("EDIF.identifier") + c2["EDIF.identifier"] = "&1" + p1["EDIF.identifier"] = "&1" + p1.pop("EDIF.identifier") + p2["EDIF.identifier"] = "&1" + i1["EDIF.identifier"] = "&1" + i1.pop("EDIF.identifier") + i2["EDIF.identifier"] = "&1" # TODO: rename an object # TODO: orphan an object and see what happens diff --git a/tests/spydrnet/plugins/tests/test_namespace_manager.py b/tests/spydrnet/plugins/tests/test_namespace_manager.py index d7b0ed8c..e7a6a976 100644 --- a/tests/spydrnet/plugins/tests/test_namespace_manager.py +++ b/tests/spydrnet/plugins/tests/test_namespace_manager.py @@ -3,7 +3,6 @@ class TestNamespaceManager(unittest.TestCase): - def test_naming_after_assignments(self): library = sdn.Library() definition = library.create_definition() diff --git a/tests/spydrnet/testing/__init__.py b/tests/spydrnet/testing/__init__.py index 9498b6f6..b98bd9c7 100644 --- a/tests/spydrnet/testing/__init__.py +++ b/tests/spydrnet/testing/__init__.py @@ -1,2 +1,2 @@ from spydrnet.testing.utils import * -from spydrnet.testing.test import run \ No newline at end of file +from spydrnet.testing.test import run diff --git a/tests/spydrnet/testing/test.py b/tests/spydrnet/testing/test.py index 71ed66c3..3c7612a8 100644 --- a/tests/spydrnet/testing/test.py +++ b/tests/spydrnet/testing/test.py @@ -1,21 +1,21 @@ def run(verbosity=1, doctest=False): """Run SpyDrNet tests. - + Parameters ---------- verbosity: integer, optional Level of detail in test reports. Higher numbers provide more detail. - + doctest: bool, optional True to run doctests in code modules """ import pytest - pytest_args = ['-l'] + pytest_args = ["-l"] if verbosity and int(verbosity) > 1: - pytest_args += ["-" + "v"*(int(verbosity)-1)] + pytest_args += ["-" + "v" * (int(verbosity) - 1)] if doctest: pytest_args += ["--doctest-modules"] @@ -27,8 +27,8 @@ def run(verbosity=1, doctest=False): except SystemExit as exc: code = exc.code - return (code == 0) + return code == 0 if __name__ == "__main__": - run() \ No newline at end of file + run() diff --git a/tests/spydrnet/tests/test_clone.py b/tests/spydrnet/tests/test_clone.py index 98db6b0b..82c21dbf 100644 --- a/tests/spydrnet/tests/test_clone.py +++ b/tests/spydrnet/tests/test_clone.py @@ -6,14 +6,13 @@ class TestClone(unittest.TestCase): - def _get_two_netlists(self): - #create a test netlist + # create a test netlist nl = self._create_netlist() - #create my own backup of the test netlist (just create another that is identical) + # create my own backup of the test netlist (just create another that is identical) nl2 = self._create_netlist() - - #both netlists are created and checkout as the same. + + # both netlists are created and checkout as the same. return nl, nl2 def _compare_netlists(self, n1, n2): @@ -54,7 +53,6 @@ def _create_netlist(self): ins3.reference = def4 return netlist - def create_and_clone_cable(self, wirecount, array, downto, index, key, value): definition = Definition() p1 = definition.create_cable() @@ -90,7 +88,7 @@ def test_cable_not_array(self): index = 0 key = "Name" value = "myPortName" - self.create_and_clone_cable(pincount, array, downto, index, key, value) + self.create_and_clone_cable(pincount, array, downto, index, key, value) def test_cable_single_bit_array(self): pincount = 1 @@ -99,7 +97,7 @@ def test_cable_single_bit_array(self): index = 0 key = "garbage_key" value = "garbage_value" - self.create_and_clone_cable(pincount, array, downto, index, key, value) + self.create_and_clone_cable(pincount, array, downto, index, key, value) def test_definition(self): lib = Library() @@ -131,7 +129,7 @@ def test_innerpin(self): pin2 = pin.clone() assert pin2.wire == None assert pin2.port == None - + def test_instance(self): def1 = Definition() def2 = Definition() @@ -146,7 +144,6 @@ def test_instance(self): for v in inst2.pins.values(): assert v not in child.pins.values() - def test_library_instance_references(self): lib1 = Library() lib2 = Library() @@ -175,7 +172,6 @@ def test_library_instance_references(self): assert ins2 not in def2c.references assert len(def3.references) == 2 - def test_library_definition_references(self): lib1 = Library() lib2 = Library() @@ -193,7 +189,7 @@ def check(self, r1, e): return assert e not in r1 - def not_among_all_references(self,r1, nl1): + def not_among_all_references(self, r1, nl1): self.check(r1, nl1) self.check(r1, nl1.top_instance) for l in nl1.libraries: @@ -217,7 +213,7 @@ def not_among_all_references(self,r1, nl1): for pi in p.pins: self.check(r1, pi) - def add_all_references(self,r1, nl1): + def add_all_references(self, r1, nl1): r1.add(nl1) r1.add(nl1.top_instance) for l in nl1.libraries: @@ -245,7 +241,7 @@ def check_overlap_references(self, nl1, nl2): r1 = set() self.add_all_references(r1, nl1) self.not_among_all_references(r1, nl2) - + def test_netlist_several_lib(self): netlist = Netlist() lib1 = netlist.create_library() @@ -278,7 +274,7 @@ def test_netlist_several_lib(self): netlist2 = clone(netlist) self._compare_netlists(netlist, netlist2) self.check_overlap_references(netlist, netlist2) - + def test_netlist_change_top_instance(self): nl1 = Netlist() lib1 = nl1.create_library() @@ -290,7 +286,6 @@ def test_netlist_change_top_instance(self): self._compare_netlists(nl1, nl2) self.check_overlap_references(nl1, nl2) - def test_library_change_top_instace(self): nl1 = Netlist() nl2 = Netlist() @@ -303,14 +298,13 @@ def test_library_change_top_instace(self): nl2.add_library(lib2) self._compare_netlists(nl1, nl2) self.check_overlap_references(nl1, nl2) - - + def test_netlist(self): nl1, nl2 = self._get_two_netlists() nl3 = clone(nl1) self._compare_netlists(nl1, nl3) self._compare_netlists(nl1, nl2) - #now check that no references overlap. + # now check that no references overlap. self.check_overlap_references(nl1, nl3) def test_netlist_empty_top_instance(self): @@ -341,7 +335,9 @@ def test_outerpin(self): assert op2.instance == None assert op2.inner_pin == None - def create_and_clone_port(self, pincount, direction, array, downto, index, key, value): + def create_and_clone_port( + self, pincount, direction, array, downto, index, key, value + ): definition = Definition() p1 = definition.create_port() p1[key] = value @@ -370,8 +366,10 @@ def test_port_array(self): index = 5 key = "EDIF.identifier" value = "myPort" - self.create_and_clone_port(pincount, direction, array, downto, index, key, value) - + self.create_and_clone_port( + pincount, direction, array, downto, index, key, value + ) + def test_port_not_array(self): pincount = 1 direction = Port.Direction.OUT @@ -380,7 +378,9 @@ def test_port_not_array(self): index = 0 key = "Name" value = "myPortName" - self.create_and_clone_port(pincount, direction, array, downto, index, key, value) + self.create_and_clone_port( + pincount, direction, array, downto, index, key, value + ) def test_port_single_bit_array(self): pincount = 1 @@ -390,14 +390,16 @@ def test_port_single_bit_array(self): index = 0 key = "garbage_key" value = "garbage_value" - self.create_and_clone_port(pincount, direction, array, downto, index, key, value) + self.create_and_clone_port( + pincount, direction, array, downto, index, key, value + ) def test_port_with_connectivity(self): - pass #TODO + pass # TODO def test_wire(self): cable = Cable() wire = cable.create_wire() wire2 = clone(wire) assert len(wire2.pins) == 0 - assert wire2.cable == None \ No newline at end of file + assert wire2.cable == None diff --git a/tests/spydrnet/tests/test_example_netlist_functionality.py b/tests/spydrnet/tests/test_example_netlist_functionality.py index ae8ef479..41c6220b 100644 --- a/tests/spydrnet/tests/test_example_netlist_functionality.py +++ b/tests/spydrnet/tests/test_example_netlist_functionality.py @@ -5,14 +5,15 @@ class TestExampleNetlistFunctionality(unittest.TestCase): def test_example_netlist_names(self): - filenames = list(x for x in Path.glob(Path(sdn.example_netlists_path, 'EDIF_netlists'), "*")) + filenames = list( + x for x in Path.glob(Path(sdn.example_netlists_path, "EDIF_netlists"), "*") + ) - self.assertEqual(len(filenames), len(sdn.example_netlist_names)) filenames.sort() for filename, example_name in zip(filenames, sdn.example_netlist_names): basename = Path(filename).name - example_name_golden = basename[:basename.index('.')] + example_name_golden = basename[: basename.index(".")] self.assertEqual(example_name, example_name_golden) def test_load_example_netlist_by_name(self): diff --git a/tests/spydrnet/tests/test_extend_classes.py b/tests/spydrnet/tests/test_extend_classes.py index 384cc012..2b94bbd8 100644 --- a/tests/spydrnet/tests/test_extend_classes.py +++ b/tests/spydrnet/tests/test_extend_classes.py @@ -1,11 +1,13 @@ import unittest -'''try importing it and extending the classes. Then make sure they're actually extended''' +"""try importing it and extending the classes. Then make sure they're actually extended""" + class TestExtendingClasses(unittest.TestCase): def test_import_and_extend(self): from spydrnet.ir import FirstClassElement from spydrnet.ir import Element + # spydrnet_extension should have been imported and used to extend classes class1 = FirstClassElement() self.assertTrue("first_class_extended" in dir(class1)) diff --git a/tests/spydrnet/tests/test_flatten.py b/tests/spydrnet/tests/test_flatten.py index e01edded..72764729 100644 --- a/tests/spydrnet/tests/test_flatten.py +++ b/tests/spydrnet/tests/test_flatten.py @@ -1,40 +1,40 @@ - import unittest import spydrnet as sdn from spydrnet.ir import * from spydrnet.flatten import flatten from spydrnet.uniquify import uniquify + class TestUniquify(unittest.TestCase): def create_netlist(self): nl = Netlist() lib = nl.create_library() d1 = lib.create_definition() - d1.name = ("d1") + d1.name = "d1" d2 = lib.create_definition() - d2.name = ("d2") + d2.name = "d2" d3 = lib.create_definition() - d3.name = ("d3") + d3.name = "d3" i11 = d1.create_child() - i11.name = ("i11") + i11.name = "i11" i12 = d1.create_child() - i12.name = ("i12") + i12.name = "i12" i13 = d1.create_child() - i13.name = ("i13") + i13.name = "i13" i24 = d2.create_child() - i24.name = ("i24") + i24.name = "i24" i25 = d2.create_child() - i25.name = ("i25") + i25.name = "i25" i26 = d2.create_child() - i26.name = ("i26") + i26.name = "i26" i27 = d2.create_child() d4 = lib.create_definition() - d4.name = ("d4") - i27.name = ("i27") + d4.name = "d4" + i27.name = "i27" i38 = d3.create_child() - i38.name = ("i38") + i38.name = "i38" i39 = d3.create_child() - i39.name = ("i39") + i39.name = "i39" i11.reference = d3 i12.reference = d3 i13.reference = d3 @@ -46,10 +46,10 @@ def create_netlist(self): i39.reference = d4 nl.top_instance = Instance() nl.top_instance.reference = d2 - nl.top_instance.name = ("top_instance") + nl.top_instance.name = "top_instance" return nl - def create_mem_bus(self,top, proc, mem): + def create_mem_bus(self, top, proc, mem): mem_width = 10 mem_write_out = proc.create_port() mem_write_out.name = "mem_write_out" @@ -88,7 +88,6 @@ def create_mem_bus(self,top, proc, mem): return mem_write_out, mem_read_in - def create_proc(self, proc, mem_write, mem_read, core, cachel2): mem_width = 10 core_i1 = proc.create_child() @@ -105,13 +104,12 @@ def create_proc(self, proc, mem_write, mem_read, core, cachel2): cachel2_i = proc.create_child() cachel2_i.reference = cachel2 cachel2_i.name = "cachel2_i" - - mem_a_in = cachel2.create_port() + + mem_a_in = cachel2.create_port() mem_a_out = cachel2.create_port() - mem_b_in = cachel2.create_port() + mem_b_in = cachel2.create_port() mem_b_out = cachel2.create_port() - - + mem_a_in.create_pins(mem_width) mem_a_out.create_pins(mem_width) mem_b_in.create_pins(mem_width) @@ -121,8 +119,7 @@ def create_proc(self, proc, mem_write, mem_read, core, cachel2): mem_b_out.name = "mem_a_out" mem_b_out.name = "mem_b_out" mem_b_in.name = "mem_b_in" - - + ca1 = proc.create_cable() ca2 = proc.create_cable() cb1 = proc.create_cable() @@ -139,14 +136,14 @@ def create_proc(self, proc, mem_write, mem_read, core, cachel2): cb2.name = "cb2" for i in range(mem_width): - ca1.wires[i].connect_pin(core_i1.pins[mem_p.pins[i]]) - ca1.wires[i].connect_pin(cachel2_i.pins[mem_a_in.pins[i]]) - ca2.wires[i].connect_pin(mem_read.pins[i]) - ca2.wires[i].connect_pin(cachel2_i.pins[mem_a_out.pins[i]]) - cb1.wires[i].connect_pin(core_i2.pins[mem_p.pins[i]]) - cb1.wires[i].connect_pin(cachel2_i.pins[mem_b_in.pins[i]]) - cb2.wires[i].connect_pin(mem_write.pins[i]) - cb2.wires[i].connect_pin(cachel2_i.pins[mem_b_out.pins[i]]) + ca1.wires[i].connect_pin(core_i1.pins[mem_p.pins[i]]) + ca1.wires[i].connect_pin(cachel2_i.pins[mem_a_in.pins[i]]) + ca2.wires[i].connect_pin(mem_read.pins[i]) + ca2.wires[i].connect_pin(cachel2_i.pins[mem_a_out.pins[i]]) + cb1.wires[i].connect_pin(core_i2.pins[mem_p.pins[i]]) + cb1.wires[i].connect_pin(cachel2_i.pins[mem_b_in.pins[i]]) + cb2.wires[i].connect_pin(mem_write.pins[i]) + cb2.wires[i].connect_pin(cachel2_i.pins[mem_b_out.pins[i]]) return mem_p @@ -154,7 +151,7 @@ def create_core(self, core, mem_p, alu, reg_file): mem_width = 10 alu_i = core.create_child() reg_file_i = core.create_child() - + alu_i.reference = alu alu_i.name = "alu_i" reg_file_i.reference = reg_file @@ -198,20 +195,17 @@ def create_netlist_with_wires(self): nl.top_instance = Instance() nl.top_instance.reference = top - - mem_write, mem_read= self.create_mem_bus(top, proc, mem) + mem_write, mem_read = self.create_mem_bus(top, proc, mem) core_mem = self.create_proc(proc, mem_write, mem_read, core, cachel2) self.create_core(core, core_mem, alu, reg_file) - nl.top_instance.name = ("top_instance") - - #self.simple_recursive_netlist_visualizer(nl) - - return nl + nl.top_instance.name = "top_instance" + # self.simple_recursive_netlist_visualizer(nl) + return nl # def simple_recursive_netlist_visualizer(self, netlist): # #TODO put this code somewhere where people can use it to visualize simple netlists @@ -225,14 +219,15 @@ def create_netlist_with_wires(self): # def recurse(instance, depth): # s = depth * "\t" # print(s, instance.name, "(", instance.reference.name, ")") - # for c in instance.reference.children: + # for c in instance.reference.children: # recurse(c, depth + 1) - + # recurse(top_instance, 0) - def simple_cable_connection_visualizer(self,netlist): + def simple_cable_connection_visualizer(self, netlist): top_instance = netlist.top_instance - #display all the cables in the top instance with all of their connections next to it + + # display all the cables in the top instance with all of their connections next to it def recur(instance): print(instance.name) for c in instance.reference.cables: @@ -240,7 +235,7 @@ def recur(instance): if len(c.wires) > 0: w = c.wires[0] for p in w.pins: - if isinstance(p,OuterPin): + if isinstance(p, OuterPin): print("\t\t(instance): ", p.instance.name) else: print("\t\t(port): ", p.port.name) @@ -249,8 +244,7 @@ def recur(instance): recur(top_instance) - - def is_flat(self,nl): + def is_flat(self, nl): ti = nl.top_instance td = ti.reference for i in td.children: @@ -258,21 +252,20 @@ def is_flat(self,nl): return False return True - - def test_flatten_instances(self): nl = self.create_netlist() uniquify(nl) flatten(nl) assert self.is_flat(nl) - def test_flatten_cables(self): nl = self.create_netlist_with_wires() self.simple_cable_connection_visualizer(nl) - + uniquify(nl) flatten(nl) self.simple_cable_connection_visualizer(nl) - - assert self.is_flat(nl) #might be nice to add some tests for the connections here. \ No newline at end of file + + assert self.is_flat( + nl + ) # might be nice to add some tests for the connections here. diff --git a/tests/spydrnet/tests/test_uniquify.py b/tests/spydrnet/tests/test_uniquify.py index 3b4c44fe..013bff1a 100644 --- a/tests/spydrnet/tests/test_uniquify.py +++ b/tests/spydrnet/tests/test_uniquify.py @@ -1,15 +1,15 @@ - import unittest from spydrnet import Netlist, Instance from spydrnet.uniquify import uniquify + class TestUniquify(unittest.TestCase): def create_netlist(self): nl = Netlist() lib = nl.create_library() d1 = lib.create_definition() d2 = lib.create_definition() - d3 = lib.create_definition(name='instance_name') + d3 = lib.create_definition(name="instance_name") i11 = d1.create_child() i12 = d1.create_child() i13 = d1.create_child() @@ -34,7 +34,7 @@ def create_netlist(self): return nl def is_unique(self, netlist): - #get all the definitions that are instanced below the top instance + # get all the definitions that are instanced below the top instance top_inst = netlist.top_instance top_def = top_inst.reference inst = [] @@ -47,13 +47,13 @@ def is_unique(self, netlist): inst.append(c) index += 1 - #now we have a list of all the instances in the netlist make sure all references are unique to the netlist + # now we have a list of all the instances in the netlist make sure all references are unique to the netlist refs = set() for i in inst: if i.reference.is_leaf(): continue if i.reference in refs: - return False #the instance references a previously referenced definition, instances are not unique + return False # the instance references a previously referenced definition, instances are not unique refs.add(i.reference) return True @@ -72,7 +72,9 @@ def test_already_unique(self): nl.top_instance = top assert self.is_unique(nl), "netlist should be unique upon creation in this test" uniquify(nl) - assert self.is_unique(nl), "netlist should remain unique in this test. somehow uniquify made the netlist un-unique" + assert self.is_unique( + nl + ), "netlist should remain unique in this test. somehow uniquify made the netlist un-unique" # def simple_recursive_netlist_visualizer(self, netlist): # #TODO put this code somewhere where people can use it to visualize simple netlists @@ -86,14 +88,13 @@ def test_already_unique(self): # def recurse(instance, depth): # s = depth * "\t" # print(s, instance.name, "(", instance.reference.name, ")") - # for c in instance.reference.children: + # for c in instance.reference.children: # recurse(c, depth + 1) - - # recurse(top_instance, 0) + # recurse(top_instance, 0) def test_uniquify_simple_with_names(self): - '''simple test with 2 definitions.''' + """simple test with 2 definitions.""" nl = Netlist() lib = nl.create_library() d1 = lib.create_definition() @@ -115,7 +116,9 @@ def test_uniquify_simple_with_names(self): top.name = "top instance" top.reference = d1 nl.top_instance = top - assert not self.is_unique(nl), "initial netlist should not be unique in this test" + assert not self.is_unique( + nl + ), "initial netlist should not be unique in this test" uniquify(nl) assert self.is_unique(nl), "netlist should have been uniquified." @@ -123,4 +126,4 @@ def test_uniquify(self): nl = self.create_netlist() assert not self.is_unique(nl), "our test netlist should not be unique" uniquify(nl) - assert self.is_unique(nl), "our netlist should have been uniquified" \ No newline at end of file + assert self.is_unique(nl), "our netlist should have been uniquified" diff --git a/tests/spydrnet/tests/test_util.py b/tests/spydrnet/tests/test_util.py index 0d6e42ea..7edbe11b 100644 --- a/tests/spydrnet/tests/test_util.py +++ b/tests/spydrnet/tests/test_util.py @@ -19,4 +19,3 @@ def test_multiple_objects(self): netlist2 = sdn.Netlist() library2 = netlist2.create_library() get_libraries([netlist1, netlist2]) - diff --git a/tests/spydrnet/tests/test_verilog_to_edif.py b/tests/spydrnet/tests/test_verilog_to_edif.py index bab5c049..10ae7b44 100644 --- a/tests/spydrnet/tests/test_verilog_to_edif.py +++ b/tests/spydrnet/tests/test_verilog_to_edif.py @@ -1,8 +1,5 @@ import unittest - - class TestVerilogToEdif(unittest.TestCase): - - pass \ No newline at end of file + pass diff --git a/tests/spydrnet/util/tests/test_get_cables.py b/tests/spydrnet/util/tests/test_get_cables.py index 6c1c0a0a..5102d537 100644 --- a/tests/spydrnet/util/tests/test_get_cables.py +++ b/tests/spydrnet/util/tests/test_get_cables.py @@ -8,26 +8,26 @@ def setUpClass(cls) -> None: cls.netlist = sdn.Netlist() leaf_library = cls.netlist.create_library() - leaf_library.name = 'primitives' + leaf_library.name = "primitives" library = cls.netlist.create_library() - library.name = 'work' + library.name = "work" leaf_def = leaf_library.create_definition() - leaf_def.name = 'leaf' + leaf_def.name = "leaf" leaf_port = leaf_def.create_port() - leaf_port.name = 'I' + leaf_port.name = "I" leaf_port.create_pins(1) bottom_def = library.create_definition() - bottom_def.name = 'bottom' + bottom_def.name = "bottom" bottom_port = bottom_def.create_port() - bottom_port.name = 'I' + bottom_port.name = "I" bottom_port.create_pins(1) leaf_inst = bottom_def.create_child() leaf_inst.reference = leaf_def bottom_cable = bottom_def.create_cable() - bottom_cable.name = 'bottom_cable' + bottom_cable.name = "bottom_cable" bottom_wire = bottom_cable.create_wire() bottom_wire.connect_pin(bottom_port.pins[0]) bottom_wire.connect_pin(leaf_inst.pins[leaf_port.pins[0]]) @@ -36,12 +36,12 @@ def setUpClass(cls) -> None: bottom_floating_wire = bottom_cable.create_wire() middle_def = library.create_definition() - middle_def.name = 'middle' + middle_def.name = "middle" middle_port = middle_def.create_port() middle_port.name = "I" middle_port.create_pin() bottom_inst = middle_def.create_child() - bottom_inst.name = 'bottom' + bottom_inst.name = "bottom" bottom_inst.reference = bottom_def middle_cable = middle_def.create_cable() middle_cable.name = "middle_cable" @@ -53,12 +53,12 @@ def setUpClass(cls) -> None: middle_floating_wire = middle_cable.create_wire() top_def = library.create_definition() - top_def.name = 'top' + top_def.name = "top" top_port = top_def.create_port() top_port.name = "I" top_port.create_pin() middle_inst = top_def.create_child() - middle_inst.name = 'middle' + middle_inst.name = "middle" middle_inst.reference = middle_def top_cable = top_def.create_cable() top_cable.name = "top_cable" @@ -70,7 +70,7 @@ def setUpClass(cls) -> None: top_floating_wire = top_cable.create_wire() top_instance = sdn.Instance() - top_instance.name = 'top' + top_instance.name = "top" top_instance.reference = top_def cls.netlist.top_instance = top_instance @@ -78,9 +78,15 @@ def test_parameter_checking(self): definition = sdn.Definition() cable = definition.create_cable() cable.name = "MY_CABLE" - self.assertRaises(TypeError, sdn.get_cables, definition, "MY_CABLE", patterns="MY_CABLE") - self.assertRaises(TypeError, sdn.get_cables, definition, "MY_CABLE", unsupported_keyword=None) - self.assertRaises(TypeError, sdn.get_cables, definition, "MY_CABLE", selection=None) + self.assertRaises( + TypeError, sdn.get_cables, definition, "MY_CABLE", patterns="MY_CABLE" + ) + self.assertRaises( + TypeError, sdn.get_cables, definition, "MY_CABLE", unsupported_keyword=None + ) + self.assertRaises( + TypeError, sdn.get_cables, definition, "MY_CABLE", selection=None + ) self.assertRaises(TypeError, sdn.get_cables, None, "MY_CABLE") self.assertRaises(TypeError, sdn.get_cables, [None, definition], "MY_CABLE") @@ -138,17 +144,28 @@ def test_outer_pin(self): self.assertEqual(len(search), 3) def test_wire_inside(self): - search = list(sdn.get_cables(self.netlist.top_instance.reference.cables[0].wires[0])) + search = list( + sdn.get_cables(self.netlist.top_instance.reference.cables[0].wires[0]) + ) self.assertEqual(len(search), 1) self.assertEqual(search[0].name, "top_cable") def test_wire_outside(self): - search = list(sdn.get_cables(self.netlist.top_instance.reference.cables[0].wires[0], selection="OUTSIDE")) + search = list( + sdn.get_cables( + self.netlist.top_instance.reference.cables[0].wires[0], + selection="OUTSIDE", + ) + ) self.assertEqual(len(search), 1) self.assertEqual(search[0].name, "middle_cable") def test_wires_all(self): - search = list(sdn.get_cables(self.netlist.top_instance.reference.cables[0].wires[0], selection="ALL")) + search = list( + sdn.get_cables( + self.netlist.top_instance.reference.cables[0].wires[0], selection="ALL" + ) + ) self.assertEqual(len(search), 3) def test_absolute_name_from_relative_reference(self): diff --git a/tests/spydrnet/util/tests/test_get_definitions.py b/tests/spydrnet/util/tests/test_get_definitions.py index eebf7553..3732af91 100644 --- a/tests/spydrnet/util/tests/test_get_definitions.py +++ b/tests/spydrnet/util/tests/test_get_definitions.py @@ -8,26 +8,26 @@ def setUpClass(cls) -> None: cls.netlist = sdn.Netlist() leaf_library = cls.netlist.create_library() - leaf_library.name = 'primitives' + leaf_library.name = "primitives" library = cls.netlist.create_library() - library.name = 'work' + library.name = "work" leaf_def = leaf_library.create_definition() - leaf_def.name = 'leaf' + leaf_def.name = "leaf" leaf_port = leaf_def.create_port() - leaf_port.name = 'I' + leaf_port.name = "I" leaf_port.create_pins(1) bottom_def = library.create_definition() - bottom_def.name = 'bottom' + bottom_def.name = "bottom" bottom_port = bottom_def.create_port() - bottom_port.name = 'I' + bottom_port.name = "I" bottom_port.create_pins(1) leaf_inst = bottom_def.create_child() leaf_inst.reference = leaf_def bottom_cable = bottom_def.create_cable() - bottom_cable.name = 'bottom_cable' + bottom_cable.name = "bottom_cable" bottom_wire = bottom_cable.create_wire() bottom_wire.connect_pin(bottom_port.pins[0]) bottom_wire.connect_pin(leaf_inst.pins[leaf_port.pins[0]]) @@ -36,12 +36,12 @@ def setUpClass(cls) -> None: bottom_floating_wire = bottom_cable.create_wire() middle_def = library.create_definition() - middle_def.name = 'middle' + middle_def.name = "middle" middle_port = middle_def.create_port() middle_port.name = "I" middle_port.create_pin() bottom_inst = middle_def.create_child() - bottom_inst.name = 'bottom' + bottom_inst.name = "bottom" bottom_inst.reference = bottom_def middle_cable = middle_def.create_cable() middle_cable.name = "middle_cable" @@ -53,12 +53,12 @@ def setUpClass(cls) -> None: middle_floating_wire = middle_cable.create_wire() top_def = library.create_definition() - top_def.name = 'top' + top_def.name = "top" top_port = top_def.create_port() top_port.name = "I" top_port.create_pin() middle_inst = top_def.create_child() - middle_inst.name = 'middle' + middle_inst.name = "middle" middle_inst.reference = middle_def top_cable = top_def.create_cable() top_cable.name = "top_cable" @@ -69,7 +69,7 @@ def setUpClass(cls) -> None: top_floating_wire = top_cable.create_wire() top_instance = sdn.Instance() - top_instance.name = 'top' + top_instance.name = "top" top_instance.reference = top_def cls.netlist.top_instance = top_instance @@ -77,9 +77,15 @@ def test_parameter_checking(self): library = sdn.Library() definition = library.create_definition() definition.name = "MY_DEF" - self.assertRaises(TypeError, sdn.get_definitions, library, "MY_DEF", patterns="MY_DEF") - self.assertRaises(TypeError, sdn.get_definitions, library, "MY_DEF", unsupported_keyword=None) - self.assertRaises(TypeError, sdn.get_definitions, library, "MY_DEF", selection="BOTH") + self.assertRaises( + TypeError, sdn.get_definitions, library, "MY_DEF", patterns="MY_DEF" + ) + self.assertRaises( + TypeError, sdn.get_definitions, library, "MY_DEF", unsupported_keyword=None + ) + self.assertRaises( + TypeError, sdn.get_definitions, library, "MY_DEF", selection="BOTH" + ) self.assertRaises(TypeError, sdn.get_definitions, None, "MY_DEF") self.assertRaises(TypeError, sdn.get_definitions, [None, library], "MY_DEF") @@ -91,79 +97,164 @@ def test_collection(self): self.assertEqual(len(ports), 1) def test_get_definition_of_instances_outside(self): - definition_query = list(sdn.get_definitions(self.netlist.libraries[0].definitions[0].references, - selection="OUTSIDE")) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.bottom_inst.reference) + definition_query = list( + sdn.get_definitions( + self.netlist.libraries[0].definitions[0].references, selection="OUTSIDE" + ) + ) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.bottom_inst.reference + ) def test_get_definition_of_instances_inside(self): - definition_query = list(sdn.get_definitions(self.netlist.libraries[0].definitions[0].references, - selection="INSIDE")) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.leaf_inst.reference) + definition_query = list( + sdn.get_definitions( + self.netlist.libraries[0].definitions[0].references, selection="INSIDE" + ) + ) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.leaf_inst.reference + ) def test_get_definition_of_instances_recursive_down(self): - definition_query = set(sdn.get_definitions(self.netlist.top_instance, recursive=True)) + definition_query = set( + sdn.get_definitions(self.netlist.top_instance, recursive=True) + ) self.assertTrue(len(definition_query) == 4) def test_get_definition_of_instances_recursive_up(self): - definition_query = list(sdn.get_definitions(self.leaf_inst, selection="OUTSIDE", recursive=True)) - self.assertTrue(len(definition_query) == 3 and self.leaf_inst.reference not in definition_query) + definition_query = list( + sdn.get_definitions(self.leaf_inst, selection="OUTSIDE", recursive=True) + ) + self.assertTrue( + len(definition_query) == 3 + and self.leaf_inst.reference not in definition_query + ) def test_get_definition_of_library(self): definition_query = list(sdn.get_definitions(self.netlist.libraries[1])) - self.assertTrue(len(definition_query) == 3 and self.leaf_inst.reference not in definition_query) + self.assertTrue( + len(definition_query) == 3 + and self.leaf_inst.reference not in definition_query + ) def test_get_definition_of_library_outside(self): - definition_query = list(sdn.get_definitions(self.netlist.libraries[0], selection="OUTSIDE")) - self.assertTrue(len(definition_query) == 1 and self.leaf_inst.reference not in definition_query) + definition_query = list( + sdn.get_definitions(self.netlist.libraries[0], selection="OUTSIDE") + ) + self.assertTrue( + len(definition_query) == 1 + and self.leaf_inst.reference not in definition_query + ) def test_get_definition_of_library_outside_recursive(self): - definition_query = list(sdn.get_definitions(self.netlist.libraries[0], selection="OUTSIDE", recursive=True)) - self.assertTrue(len(definition_query) == 3 and self.leaf_inst.reference not in definition_query) + definition_query = list( + sdn.get_definitions( + self.netlist.libraries[0], selection="OUTSIDE", recursive=True + ) + ) + self.assertTrue( + len(definition_query) == 3 + and self.leaf_inst.reference not in definition_query + ) def test_get_definition_of_library_recursive(self): - definition_query = list(sdn.get_definitions(self.netlist.libraries[1], recursive=True)) - self.assertTrue(len(definition_query) == 4 and self.leaf_inst.reference in definition_query) + definition_query = list( + sdn.get_definitions(self.netlist.libraries[1], recursive=True) + ) + self.assertTrue( + len(definition_query) == 4 and self.leaf_inst.reference in definition_query + ) def test_get_definition_of_library_recursive_absolute_pattern(self): - definition_query = list(sdn.get_definitions(self.netlist.libraries[1], "leaf", recursive=True)) - self.assertTrue(len(definition_query) == 1 and self.leaf_inst.reference is definition_query[0]) + definition_query = list( + sdn.get_definitions(self.netlist.libraries[1], "leaf", recursive=True) + ) + self.assertTrue( + len(definition_query) == 1 + and self.leaf_inst.reference is definition_query[0] + ) def test_get_definition_of_definition_inside(self): - definition_query = list(sdn.get_definitions(self.netlist.libraries[1].definitions[0], - selection="INSIDE")) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.netlist.libraries[0].definitions[0]) + definition_query = list( + sdn.get_definitions( + self.netlist.libraries[1].definitions[0], selection="INSIDE" + ) + ) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.netlist.libraries[0].definitions[0] + ) def test_get_definition_of_definition_outside(self): - definition_query = list(sdn.get_definitions(self.netlist.libraries[0].definitions[0], - selection="OUTSIDE")) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.netlist.libraries[1].definitions[0]) + definition_query = list( + sdn.get_definitions( + self.netlist.libraries[0].definitions[0], selection="OUTSIDE" + ) + ) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.netlist.libraries[1].definitions[0] + ) def test_get_definition_of_definition_inside_recursive(self): - definition_query = list(sdn.get_definitions(self.netlist.top_instance.reference, - selection="INSIDE", recursive=True)) - self.assertTrue(len(definition_query) == 3 and self.netlist.top_instance.reference not in definition_query) + definition_query = list( + sdn.get_definitions( + self.netlist.top_instance.reference, selection="INSIDE", recursive=True + ) + ) + self.assertTrue( + len(definition_query) == 3 + and self.netlist.top_instance.reference not in definition_query + ) def test_get_definition_from_outer_pins(self): definition_query = list(sdn.get_definitions(self.leaf_inst.pins)) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.leaf_inst.reference) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.leaf_inst.reference + ) def test_get_definition_from_inner_pins(self): - definition_query = list(sdn.get_definitions(self.leaf_inst.reference.ports[0].pins[0])) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.leaf_inst.reference) + definition_query = list( + sdn.get_definitions(self.leaf_inst.reference.ports[0].pins[0]) + ) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.leaf_inst.reference + ) def test_get_definition_from_wire(self): - definition_query = list(sdn.get_definitions(self.netlist.top_instance.reference.cables[0].wires[0])) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.netlist.top_instance.reference) + definition_query = list( + sdn.get_definitions(self.netlist.top_instance.reference.cables[0].wires[0]) + ) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.netlist.top_instance.reference + ) def test_get_definition_from_href(self): href = next(sdn.get_hinstances(self.netlist.top_instance)) definition_query = list(sdn.get_definitions(href)) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.netlist.top_instance.reference) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.netlist.top_instance.reference + ) def test_unique_query_return(self): - definition_query = list(sdn.get_definitions([self.netlist.libraries[0], self.leaf_inst], "leaf")) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.leaf_inst.reference) + definition_query = list( + sdn.get_definitions([self.netlist.libraries[0], self.leaf_inst], "leaf") + ) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.leaf_inst.reference + ) def test_absolute_pattern_from_relative_query(self): definition_query = list(sdn.get_definitions(self.leaf_inst, "leaf")) - self.assertTrue(len(definition_query) == 1 and definition_query[0] == self.leaf_inst.reference) + self.assertTrue( + len(definition_query) == 1 + and definition_query[0] == self.leaf_inst.reference + ) diff --git a/tests/spydrnet/util/tests/test_get_hcables.py b/tests/spydrnet/util/tests/test_get_hcables.py index 901036ec..186fbaa2 100644 --- a/tests/spydrnet/util/tests/test_get_hcables.py +++ b/tests/spydrnet/util/tests/test_get_hcables.py @@ -7,29 +7,36 @@ class TestGetHCables(unittest.TestCase): @classmethod def setUpClass(cls) -> None: - cls.netlist = sdn.load_example_netlist_by_name('b13') + cls.netlist = sdn.load_example_netlist_by_name("b13") def test_wild_card_search_on_netlist(self): hrefs = list(sdn.get_hcables(self.netlist)) - self.assertTrue(len(hrefs) == 76 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + self.assertTrue( + len(hrefs) == 76 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) def test_absolute_search(self): - href = next(self.netlist.get_hcables(''), None) + href = next(self.netlist.get_hcables(""), None) self.assertIsNotNone(href) self.assertIsInstance(href.item, sdn.Cable) def test_regex_search(self): - hrefs = list(sdn.get_hcables( - self.netlist, '.*FSM_onehot.*', is_re=True)) - self.assertTrue(len(hrefs) == 8 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + hrefs = list(sdn.get_hcables(self.netlist, ".*FSM_onehot.*", is_re=True)) + self.assertTrue( + len(hrefs) == 8 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) def test_parameters(self): - self.assertRaises(TypeError, sdn.get_hcables, self.netlist, - r'.*FSM_onehot.*', patterns=r".*FSM_onehot.*") - self.assertRaises(TypeError, sdn.get_hcables, - self.netlist, parameter_does_not_exit=True) + self.assertRaises( + TypeError, + sdn.get_hcables, + self.netlist, + r".*FSM_onehot.*", + patterns=r".*FSM_onehot.*", + ) + self.assertRaises( + TypeError, sdn.get_hcables, self.netlist, parameter_does_not_exit=True + ) self.assertRaises(TypeError, sdn.get_hcables, object()) def test_get_hcables_of_pin(self): @@ -52,6 +59,7 @@ def test_get_hcables_of_wire(self): def test_get_hwire_of_invalid_reference(self): from spydrnet.util.hierarchical_reference import HRef + invalid_href = HRef.from_parent_and_item(None, None) hrefs = list(sdn.get_hcables(invalid_href)) self.assertTrue(len(hrefs) == 0) @@ -64,6 +72,7 @@ def test_get_hcables_from_hrefs_of_cable_and_wire(self): hrefs = list(sdn.get_hinstances(wire)) href_top = hrefs[0] from spydrnet.util.hierarchical_reference import HRef + cable_href = HRef.from_parent_and_item(href_top, cable) self.assertIsInstance(cable_href.item, sdn.Cable) wire_href = HRef.from_parent_and_item(cable_href, wire) @@ -81,6 +90,7 @@ def test_get_hcables_from_hrefs_of_port_and_pin(self): href = hrefs[0] self.assertIsInstance(href.item, sdn.Cable) from spydrnet.util.hierarchical_reference import HRef + port_href = HRef.from_parent_and_item(href.parent, port) href_result = next(sdn.get_hcables(port_href), None) self.assertTrue(href_result is href) @@ -91,19 +101,21 @@ def test_get_hcables_from_hrefs_of_port_and_pin(self): def test_from_href_of_instance(self): href = next(sdn.get_hinstances(self.netlist.top_instance)) hrefs = list(sdn.get_hcables(href)) - self.assertTrue(len(hrefs) == 76 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + self.assertTrue( + len(hrefs) == 76 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) def test_from_instance(self): hrefs = list(sdn.get_hcables(self.netlist.top_instance)) - self.assertTrue(len(hrefs) == 76 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + self.assertTrue( + len(hrefs) == 76 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) def test_from_library(self): - hrefs = list(sdn.get_hcables( - self.netlist.libraries[0], selection=sdn.OUTSIDE)) - self.assertTrue(len(hrefs) == 76 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + hrefs = list(sdn.get_hcables(self.netlist.libraries[0], selection=sdn.OUTSIDE)) + self.assertTrue( + len(hrefs) == 76 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) def test_from_wire_and_cable(self): library = self.netlist.libraries[1] @@ -111,11 +123,13 @@ def test_from_wire_and_cable(self): cable = definition.cables[0] wire = cable.wires[0] hrefs = list(sdn.get_hcables(wire)) - self.assertTrue(len(hrefs) == 1 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + self.assertTrue( + len(hrefs) == 1 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) hrefs = list(sdn.get_hcables(cable)) - self.assertTrue(len(hrefs) == 1 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + self.assertTrue( + len(hrefs) == 1 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) def test_from_outerpin(self): library = self.netlist.libraries[1] @@ -123,12 +137,14 @@ def test_from_outerpin(self): instance = definition.children[0] outerpin = next(iter(instance.pins)) hrefs = list(sdn.get_hcables(outerpin, selection="OUTSIDE")) - self.assertTrue(len(hrefs) == 1 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + self.assertTrue( + len(hrefs) == 1 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) def test_bad_selection_type(self): - self.assertRaises(TypeError, self.netlist.get_hcables, - selection="NOT_AN_OPTION") + self.assertRaises( + TypeError, self.netlist.get_hcables, selection="NOT_AN_OPTION" + ) self.assertRaises(TypeError, self.netlist.get_hcables, selection=None) def test_of_bad_instance(self): @@ -155,34 +171,36 @@ def test_through_hierarchy(self): top_inst_href = next(sdn.get_hinstances(netlist.top_instance)) hrefs = list(sdn.get_hcables(top_inst_href, recursive=True)) - self.assertTrue(len(hrefs) == 1 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + self.assertTrue( + len(hrefs) == 1 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) hrefs = list(sdn.get_hcables(middle_inst)) - self.assertTrue(len(hrefs) == 1 and all( - isinstance(x.item, sdn.Cable) for x in hrefs)) + self.assertTrue( + len(hrefs) == 1 and all(isinstance(x.item, sdn.Cable) for x in hrefs) + ) def test_through_hierarchy_again(self): netlist = sdn.Netlist() library = netlist.create_library() - library.name = 'work' + library.name = "work" leaf_def = library.create_definition() - leaf_def.name = 'leaf' + leaf_def.name = "leaf" leaf_port = leaf_def.create_port() - leaf_port.name = 'I' + leaf_port.name = "I" leaf_port.create_pins(1) bottom_def = library.create_definition() - bottom_def.name = 'bottom' + bottom_def.name = "bottom" bottom_port = bottom_def.create_port() - bottom_port.name = 'I' + bottom_port.name = "I" bottom_port.create_pins(1) leaf_inst = bottom_def.create_child() leaf_inst.reference = leaf_def bottom_cable = bottom_def.create_cable() - bottom_cable.name = 'bottom_cable' + bottom_cable.name = "bottom_cable" bottom_wire = bottom_cable.create_wire() bottom_wire.connect_pin(bottom_port.pins[0]) bottom_wire.connect_pin(leaf_inst.pins[leaf_port.pins[0]]) @@ -190,12 +208,12 @@ def test_through_hierarchy_again(self): bottom_floating_wire = bottom_cable.create_wire() middle_def = library.create_definition() - middle_def.name = 'middle' + middle_def.name = "middle" middle_port = middle_def.create_port() middle_port.name = "I" middle_port.create_pin() bottom_inst = middle_def.create_child() - bottom_inst.name = 'bottom' + bottom_inst.name = "bottom" bottom_inst.reference = bottom_def middle_cable = middle_def.create_cable() middle_cable.name = "middle_cable" @@ -206,12 +224,12 @@ def test_through_hierarchy_again(self): middle_floating_wire = middle_cable.create_wire() top_def = library.create_definition() - top_def.name = 'top' + top_def.name = "top" top_port = top_def.create_port() top_port.name = "I" top_port.create_pin() middle_inst = top_def.create_child() - middle_inst.name = 'middle' + middle_inst.name = "middle" middle_inst.reference = middle_def top_cable = top_def.create_cable() top_cable.name = "top_cable" @@ -222,7 +240,7 @@ def test_through_hierarchy_again(self): top_floating_wire = top_cable.create_wire() top_instance = sdn.Instance() - top_instance.name = 'top' + top_instance.name = "top" top_instance.reference = top_def netlist.top_instance = top_instance @@ -232,7 +250,7 @@ def test_through_hierarchy_again(self): # look at wire_name href = next(sdn.get_hcables(middle_floating_wire)) - self.assertTrue('middle/middle_cable[1]', href.name) + self.assertTrue("middle/middle_cable[1]", href.name) hrefs = set(sdn.get_hcables(netlist.top_instance, recursive=True)) self.assertTrue(href in hrefs) @@ -241,12 +259,19 @@ def test_through_hierarchy_again(self): href_middle_wire = next(sdn.get_hcables(middle_cable.wires[0])) href_bottom_wire = next(sdn.get_hcables(bottom_cable.wires[0])) self.assertTrue( - href_top_wire in hrefs and href_middle_wire not in hrefs and href_bottom_wire in hrefs) + href_top_wire in hrefs + and href_middle_wire not in hrefs + and href_bottom_wire in hrefs + ) hrefs = set(sdn.get_hcables(middle_cable, selection="ALL")) href_middle_floating_wire = next(sdn.get_hcables(middle_floating_wire)) - self.assertTrue(href_top_wire in hrefs and href_middle_wire in hrefs and href_bottom_wire in hrefs and - href_middle_floating_wire in hrefs) + self.assertTrue( + href_top_wire in hrefs + and href_middle_wire in hrefs + and href_bottom_wire in hrefs + and href_middle_floating_wire in hrefs + ) all_wires = set(netlist.get_hcables()) self.assertTrue(len(all_wires) == 1) diff --git a/tests/spydrnet/util/tests/test_get_hinstances.py b/tests/spydrnet/util/tests/test_get_hinstances.py index 0a374d55..744388d7 100644 --- a/tests/spydrnet/util/tests/test_get_hinstances.py +++ b/tests/spydrnet/util/tests/test_get_hinstances.py @@ -4,21 +4,30 @@ class TestGetHInstances(unittest.TestCase): netlist = None + @classmethod def setUpClass(cls) -> None: - cls.netlist = sdn.load_example_netlist_by_name('b13') + cls.netlist = sdn.load_example_netlist_by_name("b13") def test_absolute_search(self): - href = next(self.netlist.get_hinstances('tx_end_reg'), None) + href = next(self.netlist.get_hinstances("tx_end_reg"), None) self.assertIsNotNone(href) def test_regex_search(self): - hrefs = list(sdn.get_hinstances(self.netlist, '.*FSM_onehot.*', is_re=True)) + hrefs = list(sdn.get_hinstances(self.netlist, ".*FSM_onehot.*", is_re=True)) self.assertTrue(len(hrefs) == 24) def test_parameters(self): - self.assertRaises(TypeError, sdn.get_hinstances, self.netlist, r'.*FSM_onehot.*', patterns=r".*FSM_onehot.*") - self.assertRaises(TypeError, sdn.get_hinstances, self.netlist, parameter_does_not_exit=True) + self.assertRaises( + TypeError, + sdn.get_hinstances, + self.netlist, + r".*FSM_onehot.*", + patterns=r".*FSM_onehot.*", + ) + self.assertRaises( + TypeError, sdn.get_hinstances, self.netlist, parameter_does_not_exit=True + ) self.assertRaises(TypeError, sdn.get_hinstances, object()) def test_get_hinstances_of_pin(self): @@ -39,6 +48,7 @@ def test_get_hinstances_of_wire(self): def test_get_hinstance_of_invalid_reference(self): from spydrnet.util.hierarchical_reference import HRef + invalid_href = HRef.from_parent_and_item(None, None) hrefs = list(sdn.get_hinstances(invalid_href)) self.assertTrue(len(hrefs) == 0) @@ -51,6 +61,7 @@ def test_get_hinstances_from_hrefs_of_cable_and_wire(self): hrefs = list(sdn.get_hinstances(wire)) href_top = hrefs[0] from spydrnet.util.hierarchical_reference import HRef + cable_href = HRef.from_parent_and_item(href_top, cable) href_result = next(sdn.get_hinstances(cable_href), None) self.assertTrue(href_result is href_top) @@ -66,6 +77,7 @@ def test_get_hinstances_from_hrefs_of_port_and_pin(self): hrefs = list(sdn.get_hinstances(pin)) href = hrefs[0] from spydrnet.util.hierarchical_reference import HRef + port_href = HRef.from_parent_and_item(href, port) href_result = next(sdn.get_hinstances(port_href), None) self.assertTrue(href_result is href) @@ -127,6 +139,6 @@ def test_through_hierarchy(self): @unittest.skip("Test takes too long at this time.") def test_recursive_memory_use(self): - netlist = sdn.load_example_netlist_by_name('leon3mp_hierarchical') + netlist = sdn.load_example_netlist_by_name("leon3mp_hierarchical") hrefs = list(sdn.get_hinstances(netlist)) self.assertTrue(len(hrefs) > 0) diff --git a/tests/spydrnet/util/tests/test_get_hpins.py b/tests/spydrnet/util/tests/test_get_hpins.py index 20e013bb..3cd2d1e1 100644 --- a/tests/spydrnet/util/tests/test_get_hpins.py +++ b/tests/spydrnet/util/tests/test_get_hpins.py @@ -4,34 +4,49 @@ class TestGetHPins(unittest.TestCase): netlist = None + @classmethod def setUpClass(cls) -> None: - cls.netlist = sdn.load_example_netlist_by_name('b13') + cls.netlist = sdn.load_example_netlist_by_name("b13") def test_wild_card_search_on_netlist(self): hrefs = list(sdn.get_hpins(self.netlist)) - self.assertTrue(len(hrefs) == 22 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + self.assertTrue( + len(hrefs) == 22 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) def test_wild_card_search_on_netlist_recursive(self): hrefs = list(sdn.get_hpins(self.netlist, recursive=True)) - self.assertTrue(len(hrefs) == 510 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + self.assertTrue( + len(hrefs) == 510 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) def test_absolute_search_excluded(self): - href = next(self.netlist.get_hpins('this_is_not_contained'), None) + href = next(self.netlist.get_hpins("this_is_not_contained"), None) self.assertIsNone(href) def test_absolute_search(self): - href = next(self.netlist.get_hpins('clock'), None) + href = next(self.netlist.get_hpins("clock"), None) self.assertIsNotNone(href) self.assertIsInstance(href.item, sdn.InnerPin) def test_regex_search(self): - hrefs = list(sdn.get_hpins(self.netlist, '.*dAtA.*', is_re=True, is_case=False)) - self.assertTrue(len(hrefs) == 9 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + hrefs = list(sdn.get_hpins(self.netlist, ".*dAtA.*", is_re=True, is_case=False)) + self.assertTrue( + len(hrefs) == 9 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) def test_parameters(self): - self.assertRaises(TypeError, sdn.get_hpins, self.netlist, r'.*FSM_onehot.*', patterns=r".*FSM_onehot.*") - self.assertRaises(TypeError, sdn.get_hpins, self.netlist, parameter_does_not_exit=True) + self.assertRaises( + TypeError, + sdn.get_hpins, + self.netlist, + r".*FSM_onehot.*", + patterns=r".*FSM_onehot.*", + ) + self.assertRaises( + TypeError, sdn.get_hpins, self.netlist, parameter_does_not_exit=True + ) self.assertRaises(TypeError, sdn.get_hpins, object()) def test_get_hpins_of_pin(self): @@ -54,6 +69,7 @@ def test_get_hpins_of_wire(self): def test_get_hwire_of_invalid_reference(self): from spydrnet.util.hierarchical_reference import HRef + invalid_href = HRef.from_parent_and_item(None, None) hrefs = list(sdn.get_hpins(invalid_href)) self.assertTrue(len(hrefs) == 0) @@ -86,6 +102,7 @@ def test_get_hpins_from_hrefs_of_port_and_pin(self): hrefs = list(sdn.get_hinstances(pin)) href = hrefs[0] from spydrnet.util.hierarchical_reference import HRef + port_href = HRef.from_parent_and_item(href, port) pin_href = HRef.from_parent_and_item(port_href, pin) href_result = next(sdn.get_hpins(port_href), None) @@ -96,15 +113,21 @@ def test_get_hpins_from_hrefs_of_port_and_pin(self): def test_from_href_of_instance(self): href = next(sdn.get_hinstances(self.netlist.top_instance)) hrefs = list(sdn.get_hpins(href)) - self.assertTrue(len(hrefs) == 22 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + self.assertTrue( + len(hrefs) == 22 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) def test_from_instance(self): hrefs = list(sdn.get_hpins(self.netlist.top_instance)) - self.assertTrue(len(hrefs) == 22 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + self.assertTrue( + len(hrefs) == 22 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) def test_from_library(self): hrefs = list(sdn.get_hpins(self.netlist.libraries[0])) - self.assertTrue(len(hrefs) == 488 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + self.assertTrue( + len(hrefs) == 488 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) def test_from_wire_and_cable(self): library = self.netlist.libraries[1] @@ -112,9 +135,13 @@ def test_from_wire_and_cable(self): cable = definition.cables[0] wire = cable.wires[0] hrefs = list(sdn.get_hpins(wire)) - self.assertTrue(len(hrefs) == 2 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + self.assertTrue( + len(hrefs) == 2 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) hrefs = list(sdn.get_hpins(cable)) - self.assertTrue(len(hrefs) == 2 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + self.assertTrue( + len(hrefs) == 2 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) def test_from_outerpin(self): library = self.netlist.libraries[1] @@ -122,7 +149,9 @@ def test_from_outerpin(self): instance = definition.children[0] outerpin = next(iter(instance.pins)) hrefs = list(sdn.get_hpins(outerpin)) - self.assertTrue(len(hrefs) == 1 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs)) + self.assertTrue( + len(hrefs) == 1 and all(isinstance(x.item, sdn.InnerPin) for x in hrefs) + ) def test_bad_selection_type(self): self.assertRaises(TypeError, self.netlist.get_hpins, selection="NOT_AN_OPTION") @@ -136,24 +165,24 @@ def test_through_hierarchy_again(self): netlist = sdn.Netlist() library = netlist.create_library() - library.name = 'work' + library.name = "work" leaf_def = library.create_definition() - leaf_def.name = 'leaf' + leaf_def.name = "leaf" leaf_port = leaf_def.create_port() - leaf_port.name = 'I' + leaf_port.name = "I" leaf_port.create_pins(1) bottom_def = library.create_definition() - bottom_def.name = 'bottom' + bottom_def.name = "bottom" bottom_port = bottom_def.create_port() - bottom_port.name = 'I' + bottom_port.name = "I" bottom_port.create_pins(1) leaf_inst = bottom_def.create_child() - leaf_inst.name = 'leaf' + leaf_inst.name = "leaf" leaf_inst.reference = leaf_def bottom_cable = bottom_def.create_cable() - bottom_cable.name = 'bottom_cable' + bottom_cable.name = "bottom_cable" bottom_wire = bottom_cable.create_wire() bottom_wire.connect_pin(bottom_port.pins[0]) bottom_wire.connect_pin(leaf_inst.pins[leaf_port.pins[0]]) @@ -161,12 +190,12 @@ def test_through_hierarchy_again(self): bottom_floating_wire = bottom_cable.create_wire() middle_def = library.create_definition() - middle_def.name = 'middle' + middle_def.name = "middle" middle_port = middle_def.create_port() middle_port.name = "I" middle_port.create_pin() bottom_inst = middle_def.create_child() - bottom_inst.name = 'bottom' + bottom_inst.name = "bottom" bottom_inst.reference = bottom_def middle_cable = middle_def.create_cable() middle_cable.name = "middle_cable" @@ -177,12 +206,12 @@ def test_through_hierarchy_again(self): middle_floating_wire = middle_cable.create_wire() top_def = library.create_definition() - top_def.name = 'top' + top_def.name = "top" top_port = top_def.create_port() top_port.name = "I" top_port.create_pin() middle_inst = top_def.create_child() - middle_inst.name = 'middle' + middle_inst.name = "middle" middle_inst.reference = middle_def top_cable = top_def.create_cable() top_cable.name = "top_cable" @@ -193,13 +222,13 @@ def test_through_hierarchy_again(self): top_floating_wire = top_cable.create_wire() top_instance = sdn.Instance() - top_instance.name = 'top' + top_instance.name = "top" top_instance.reference = top_def netlist.top_instance = top_instance - #look at wire_name - href = next(netlist.get_hpins('I')) - self.assertTrue('clock', href.name) + # look at wire_name + href = next(netlist.get_hpins("I")) + self.assertTrue("clock", href.name) hrefs = set(sdn.get_hpins(netlist.top_instance, recursive=True)) self.assertTrue(href in hrefs) @@ -207,10 +236,18 @@ def test_through_hierarchy_again(self): href_top_pin = next(sdn.get_hpins(top_port.pins[0])) href_middle_pin = next(sdn.get_hpins(middle_port.pins[0])) href_bottom_pin = next(sdn.get_hpins(bottom_port.pins[0])) - self.assertTrue(href_top_pin not in hrefs and href_middle_pin in hrefs and href_bottom_pin in hrefs) + self.assertTrue( + href_top_pin not in hrefs + and href_middle_pin in hrefs + and href_bottom_pin in hrefs + ) hrefs = set(sdn.get_hpins(top_def, recursive=True)) - self.assertTrue(href_top_pin in hrefs and href_middle_pin in hrefs and href_bottom_pin in hrefs) + self.assertTrue( + href_top_pin in hrefs + and href_middle_pin in hrefs + and href_bottom_pin in hrefs + ) all_pins = set(netlist.get_hpins()) self.assertTrue(len(all_pins) == 1) diff --git a/tests/spydrnet/util/tests/test_get_hports.py b/tests/spydrnet/util/tests/test_get_hports.py index a43cacfa..38fe0f28 100644 --- a/tests/spydrnet/util/tests/test_get_hports.py +++ b/tests/spydrnet/util/tests/test_get_hports.py @@ -4,34 +4,51 @@ class TestGetHPorts(unittest.TestCase): netlist = None + @classmethod def setUpClass(cls) -> None: - cls.netlist = sdn.load_example_netlist_by_name('b13') + cls.netlist = sdn.load_example_netlist_by_name("b13") def test_wild_card_search_on_netlist(self): hrefs = list(sdn.get_hports(self.netlist)) - self.assertTrue(len(hrefs) == 12 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + self.assertTrue( + len(hrefs) == 12 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) def test_wild_card_search_on_netlist_recursive(self): hrefs = list(sdn.get_hports(self.netlist, recursive=True)) - self.assertTrue(len(hrefs) == 500 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + self.assertTrue( + len(hrefs) == 500 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) def test_absolute_search_excluded(self): - href = next(self.netlist.get_hports('this_is_not_contained'), None) + href = next(self.netlist.get_hports("this_is_not_contained"), None) self.assertIsNone(href) def test_absolute_search(self): - href = next(self.netlist.get_hports('clock'), None) + href = next(self.netlist.get_hports("clock"), None) self.assertIsNotNone(href) self.assertIsInstance(href.item, sdn.Port) def test_regex_search(self): - hrefs = list(sdn.get_hports(self.netlist, '.*dAtA.*', is_re=True, is_case=False)) - self.assertTrue(len(hrefs) == 2 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + hrefs = list( + sdn.get_hports(self.netlist, ".*dAtA.*", is_re=True, is_case=False) + ) + self.assertTrue( + len(hrefs) == 2 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) def test_parameters(self): - self.assertRaises(TypeError, sdn.get_hports, self.netlist, r'.*FSM_onehot.*', patterns=r".*FSM_onehot.*") - self.assertRaises(TypeError, sdn.get_hports, self.netlist, parameter_does_not_exit=True) + self.assertRaises( + TypeError, + sdn.get_hports, + self.netlist, + r".*FSM_onehot.*", + patterns=r".*FSM_onehot.*", + ) + self.assertRaises( + TypeError, sdn.get_hports, self.netlist, parameter_does_not_exit=True + ) self.assertRaises(TypeError, sdn.get_hports, object()) def test_get_hports_of_pin(self): @@ -54,6 +71,7 @@ def test_get_hports_of_wire(self): def test_get_hwire_of_invalid_reference(self): from spydrnet.util.hierarchical_reference import HRef + invalid_href = HRef.from_parent_and_item(None, None) hrefs = list(sdn.get_hports(invalid_href)) self.assertTrue(len(hrefs) == 0) @@ -86,6 +104,7 @@ def test_get_hports_from_hrefs_of_port_and_pin(self): hrefs = list(sdn.get_hinstances(pin)) href = hrefs[0] from spydrnet.util.hierarchical_reference import HRef + port_href = HRef.from_parent_and_item(href, port) pin_href = HRef.from_parent_and_item(port_href, pin) href_result = next(sdn.get_hports(port_href), None) @@ -96,15 +115,21 @@ def test_get_hports_from_hrefs_of_port_and_pin(self): def test_from_href_of_instance(self): href = next(sdn.get_hinstances(self.netlist.top_instance)) hrefs = list(sdn.get_hports(href)) - self.assertTrue(len(hrefs) == 12 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + self.assertTrue( + len(hrefs) == 12 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) def test_from_instance(self): hrefs = list(sdn.get_hports(self.netlist.top_instance)) - self.assertTrue(len(hrefs) == 12 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + self.assertTrue( + len(hrefs) == 12 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) def test_from_library(self): hrefs = list(sdn.get_hports(self.netlist.libraries[0])) - self.assertTrue(len(hrefs) == 488 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + self.assertTrue( + len(hrefs) == 488 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) def test_from_wire_and_cable(self): library = self.netlist.libraries[1] @@ -112,9 +137,13 @@ def test_from_wire_and_cable(self): cable = definition.cables[0] wire = cable.wires[0] hrefs = list(sdn.get_hports(wire)) - self.assertTrue(len(hrefs) == 2 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + self.assertTrue( + len(hrefs) == 2 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) hrefs = list(sdn.get_hports(cable)) - self.assertTrue(len(hrefs) == 2 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + self.assertTrue( + len(hrefs) == 2 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) def test_from_outerpin(self): library = self.netlist.libraries[1] @@ -122,7 +151,9 @@ def test_from_outerpin(self): instance = definition.children[0] outerpin = next(iter(instance.pins)) hrefs = list(sdn.get_hports(outerpin)) - self.assertTrue(len(hrefs) == 1 and all(isinstance(x.item, sdn.Port) for x in hrefs)) + self.assertTrue( + len(hrefs) == 1 and all(isinstance(x.item, sdn.Port) for x in hrefs) + ) def test_bad_selection_type(self): self.assertRaises(TypeError, self.netlist.get_hports, selection="NOT_AN_OPTION") @@ -136,24 +167,24 @@ def test_through_hierarchy_again(self): netlist = sdn.Netlist() library = netlist.create_library() - library.name = 'work' + library.name = "work" leaf_def = library.create_definition() - leaf_def.name = 'leaf' + leaf_def.name = "leaf" leaf_port = leaf_def.create_port() - leaf_port.name = 'I' + leaf_port.name = "I" leaf_port.create_pins(1) bottom_def = library.create_definition() - bottom_def.name = 'bottom' + bottom_def.name = "bottom" bottom_port = bottom_def.create_port() - bottom_port.name = 'I' + bottom_port.name = "I" bottom_port.create_pins(1) leaf_inst = bottom_def.create_child() - leaf_inst.name = 'leaf' + leaf_inst.name = "leaf" leaf_inst.reference = leaf_def bottom_cable = bottom_def.create_cable() - bottom_cable.name = 'bottom_cable' + bottom_cable.name = "bottom_cable" bottom_wire = bottom_cable.create_wire() bottom_wire.connect_pin(bottom_port.pins[0]) bottom_wire.connect_pin(leaf_inst.pins[leaf_port.pins[0]]) @@ -161,12 +192,12 @@ def test_through_hierarchy_again(self): bottom_floating_wire = bottom_cable.create_wire() middle_def = library.create_definition() - middle_def.name = 'middle' + middle_def.name = "middle" middle_port = middle_def.create_port() middle_port.name = "I" middle_port.create_pin() bottom_inst = middle_def.create_child() - bottom_inst.name = 'bottom' + bottom_inst.name = "bottom" bottom_inst.reference = bottom_def middle_cable = middle_def.create_cable() middle_cable.name = "middle_cable" @@ -177,12 +208,12 @@ def test_through_hierarchy_again(self): middle_floating_wire = middle_cable.create_wire() top_def = library.create_definition() - top_def.name = 'top' + top_def.name = "top" top_port = top_def.create_port() top_port.name = "I" top_port.create_pin() middle_inst = top_def.create_child() - middle_inst.name = 'middle' + middle_inst.name = "middle" middle_inst.reference = middle_def top_cable = top_def.create_cable() top_cable.name = "top_cable" @@ -193,13 +224,13 @@ def test_through_hierarchy_again(self): top_floating_wire = top_cable.create_wire() top_instance = sdn.Instance() - top_instance.name = 'top' + top_instance.name = "top" top_instance.reference = top_def netlist.top_instance = top_instance - #look at wire_name - href = next(netlist.get_hports('I')) - self.assertTrue('clock', href.name) + # look at wire_name + href = next(netlist.get_hports("I")) + self.assertTrue("clock", href.name) hrefs = set(sdn.get_hports(netlist.top_instance, recursive=True)) self.assertTrue(href in hrefs) @@ -207,10 +238,18 @@ def test_through_hierarchy_again(self): href_top_pin = next(sdn.get_hports(top_port.pins[0])) href_middle_pin = next(sdn.get_hports(middle_port.pins[0])) href_bottom_pin = next(sdn.get_hports(bottom_port.pins[0])) - self.assertTrue(href_top_pin not in hrefs and href_middle_pin in hrefs and href_bottom_pin in hrefs) + self.assertTrue( + href_top_pin not in hrefs + and href_middle_pin in hrefs + and href_bottom_pin in hrefs + ) hrefs = set(sdn.get_hports(top_def, recursive=True)) - self.assertTrue(href_top_pin in hrefs and href_middle_pin in hrefs and href_bottom_pin in hrefs) + self.assertTrue( + href_top_pin in hrefs + and href_middle_pin in hrefs + and href_bottom_pin in hrefs + ) all_pins = set(netlist.get_hports()) self.assertTrue(len(all_pins) == 1) diff --git a/tests/spydrnet/util/tests/test_get_hwires.py b/tests/spydrnet/util/tests/test_get_hwires.py index 51d24ec8..5146f22c 100644 --- a/tests/spydrnet/util/tests/test_get_hwires.py +++ b/tests/spydrnet/util/tests/test_get_hwires.py @@ -7,26 +7,31 @@ class TestGetHWires(unittest.TestCase): @classmethod def setUpClass(cls) -> None: - cls.netlist = sdn.load_example_netlist_by_name('b13') + cls.netlist = sdn.load_example_netlist_by_name("b13") def test_wild_card_search_on_netlist(self): hrefs = list(sdn.get_hwires(self.netlist)) - assert (len(hrefs) > 0) + assert len(hrefs) > 0 def test_absolute_search(self): - href = next(self.netlist.get_hwires(''), None) + href = next(self.netlist.get_hwires(""), None) self.assertIsNotNone(href) def test_regex_search(self): - hrefs = list(sdn.get_hwires( - self.netlist, '.*FSM_onehot.*', is_re=True)) - assert (len(hrefs) == 23) + hrefs = list(sdn.get_hwires(self.netlist, ".*FSM_onehot.*", is_re=True)) + assert len(hrefs) == 23 def test_parameters(self): - self.assertRaises(TypeError, sdn.get_hwires, self.netlist, - r'.*FSM_onehot.*', patterns=r".*FSM_onehot.*") - self.assertRaises(TypeError, sdn.get_hwires, - self.netlist, parameter_does_not_exit=True) + self.assertRaises( + TypeError, + sdn.get_hwires, + self.netlist, + r".*FSM_onehot.*", + patterns=r".*FSM_onehot.*", + ) + self.assertRaises( + TypeError, sdn.get_hwires, self.netlist, parameter_does_not_exit=True + ) self.assertRaises(TypeError, sdn.get_hwires, object()) def test_get_hwires_of_pin(self): @@ -35,7 +40,7 @@ def test_get_hwires_of_pin(self): port = definition.ports[0] pin = port.pins[0] hrefs = list(sdn.get_hwires(pin)) - assert (len(hrefs) == 1) + assert len(hrefs) == 1 def test_get_hwires_of_wire(self): library = self.netlist.libraries[1] @@ -43,13 +48,14 @@ def test_get_hwires_of_wire(self): cable = definition.cables[0] wire = cable.wires[0] hrefs = list(sdn.get_hwires(wire)) - assert (len(hrefs) == 1) + assert len(hrefs) == 1 def test_get_hwire_of_invalid_reference(self): from spydrnet.util.hierarchical_reference import HRef + invalid_href = HRef.from_parent_and_item(None, None) hrefs = list(sdn.get_hwires(invalid_href)) - assert (len(hrefs) == 0) + assert len(hrefs) == 0 def test_get_hwires_from_hrefs_of_cable_and_wire(self): library = self.netlist.libraries[1] @@ -59,12 +65,13 @@ def test_get_hwires_from_hrefs_of_cable_and_wire(self): hrefs = list(sdn.get_hinstances(wire)) href_top = hrefs[0] from spydrnet.util.hierarchical_reference import HRef + cable_href = HRef.from_parent_and_item(href_top, cable) wire_href = HRef.from_parent_and_item(cable_href, wire) href_result = next(sdn.get_hwires(cable_href), None) - assert (href_result is wire_href) + assert href_result is wire_href href_result = next(sdn.get_hwires(wire_href), None) - assert (href_result is wire_href) + assert href_result is wire_href def test_get_hwires_from_hrefs_of_port_and_pin(self): library = self.netlist.libraries[1] @@ -74,26 +81,26 @@ def test_get_hwires_from_hrefs_of_port_and_pin(self): hrefs = list(sdn.get_hwires(pin)) href = hrefs[0] from spydrnet.util.hierarchical_reference import HRef + port_href = HRef.from_parent_and_item(href.parent.parent, port) href_result = next(sdn.get_hwires(port_href), None) - assert (href_result is href) + assert href_result is href pin_href = HRef.from_parent_and_item(port_href, pin) href_result = next(sdn.get_hwires(pin_href), None) - assert (href_result is href) + assert href_result is href def test_from_href_of_instance(self): href = next(sdn.get_hinstances(self.netlist.top_instance)) hrefs = list(sdn.get_hwires(href)) - assert (len(hrefs) == 122) + assert len(hrefs) == 122 def test_from_instance(self): hrefs = list(sdn.get_hwires(self.netlist.top_instance)) - assert (len(hrefs) == 122) + assert len(hrefs) == 122 def test_from_library(self): - hrefs = list(sdn.get_hwires( - self.netlist.libraries[0], selection=sdn.OUTSIDE)) - assert (len(hrefs) == 114) + hrefs = list(sdn.get_hwires(self.netlist.libraries[0], selection=sdn.OUTSIDE)) + assert len(hrefs) == 114 def test_from_wire_and_cable(self): library = self.netlist.libraries[1] @@ -101,9 +108,9 @@ def test_from_wire_and_cable(self): cable = definition.cables[0] wire = cable.wires[0] hrefs = list(sdn.get_hwires(wire)) - assert (len(hrefs) == 1) + assert len(hrefs) == 1 hrefs = list(sdn.get_hwires(cable)) - assert (len(hrefs) == 1) + assert len(hrefs) == 1 def test_from_outerpin(self): library = self.netlist.libraries[1] @@ -111,16 +118,15 @@ def test_from_outerpin(self): instance = definition.children[0] outerpin = next(iter(instance.pins)) hrefs = list(sdn.get_hwires(outerpin, selection="OUTSIDE")) - assert (len(hrefs) == 1) + assert len(hrefs) == 1 def test_bad_selection_type(self): - self.assertRaises(TypeError, self.netlist.get_hwires, - selection="NOT_AN_OPTION") + self.assertRaises(TypeError, self.netlist.get_hwires, selection="NOT_AN_OPTION") self.assertRaises(TypeError, self.netlist.get_hwires, selection=None) def test_of_bad_instance(self): hrefs = list(sdn.get_hwires(sdn.Instance())) - assert (len(hrefs) == 0) + assert len(hrefs) == 0 def test_through_hierarchy(self): netlist = sdn.Netlist() @@ -142,32 +148,32 @@ def test_through_hierarchy(self): top_inst_href = next(sdn.get_hinstances(netlist.top_instance)) hrefs = list(sdn.get_hwires(top_inst_href, recursive=True)) - assert (len(hrefs) == 1) + assert len(hrefs) == 1 hrefs = list(sdn.get_hwires(middle_inst)) - assert (len(hrefs) == 1) + assert len(hrefs) == 1 def test_through_hierarchy_again(self): netlist = sdn.Netlist() library = netlist.create_library() - library.name = 'work' + library.name = "work" leaf_def = library.create_definition() - leaf_def.name = 'leaf' + leaf_def.name = "leaf" leaf_port = leaf_def.create_port() - leaf_port.name = 'I' + leaf_port.name = "I" leaf_port.create_pins(1) bottom_def = library.create_definition() - bottom_def.name = 'bottom' + bottom_def.name = "bottom" bottom_port = bottom_def.create_port() - bottom_port.name = 'I' + bottom_port.name = "I" bottom_port.create_pins(1) leaf_inst = bottom_def.create_child() leaf_inst.reference = leaf_def bottom_cable = bottom_def.create_cable() - bottom_cable.name = 'bottom_cable' + bottom_cable.name = "bottom_cable" bottom_wire = bottom_cable.create_wire() bottom_wire.connect_pin(bottom_port.pins[0]) bottom_wire.connect_pin(leaf_inst.pins[leaf_port.pins[0]]) @@ -175,12 +181,12 @@ def test_through_hierarchy_again(self): bottom_floating_wire = bottom_cable.create_wire() middle_def = library.create_definition() - middle_def.name = 'middle' + middle_def.name = "middle" middle_port = middle_def.create_port() middle_port.name = "I" middle_port.create_pin() bottom_inst = middle_def.create_child() - bottom_inst.name = 'bottom' + bottom_inst.name = "bottom" bottom_inst.reference = bottom_def middle_cable = middle_def.create_cable() middle_cable.name = "middle_cable" @@ -191,12 +197,12 @@ def test_through_hierarchy_again(self): middle_floating_wire = middle_cable.create_wire() top_def = library.create_definition() - top_def.name = 'top' + top_def.name = "top" top_port = top_def.create_port() top_port.name = "I" top_port.create_pin() middle_inst = top_def.create_child() - middle_inst.name = 'middle' + middle_inst.name = "middle" middle_inst.reference = middle_def top_cable = top_def.create_cable() top_cable.name = "top_cable" @@ -207,34 +213,41 @@ def test_through_hierarchy_again(self): top_floating_wire = top_cable.create_wire() top_instance = sdn.Instance() - top_instance.name = 'top' + top_instance.name = "top" top_instance.reference = top_def netlist.top_instance = top_instance href = next(sdn.get_hwires(top_floating_wire)) hrefs = set(sdn.get_hwires(netlist.top_instance)) - assert (href in hrefs) + assert href in hrefs # look at wire_name href = next(sdn.get_hwires(middle_floating_wire)) - assert ('middle/middle_cable[1]' == href.name) + assert "middle/middle_cable[1]" == href.name hrefs = set(sdn.get_hwires(netlist.top_instance, recursive=True)) - assert (href in hrefs) + assert href in hrefs hrefs = set(sdn.get_hwires(middle_cable, selection="OUTSIDE")) href_top_wire = next(sdn.get_hwires(top_cable.wires[0])) href_middle_wire = next(sdn.get_hwires(middle_cable.wires[0])) href_bottom_wire = next(sdn.get_hwires(bottom_cable.wires[0])) assert ( - href_top_wire in hrefs and href_middle_wire not in hrefs and href_bottom_wire in hrefs) + href_top_wire in hrefs + and href_middle_wire not in hrefs + and href_bottom_wire in hrefs + ) hrefs = set(sdn.get_hwires(middle_cable, selection="ALL")) href_middle_floating_wire = next(sdn.get_hwires(middle_floating_wire)) - assert (href_top_wire in hrefs and href_middle_wire in hrefs and href_bottom_wire in hrefs and - href_middle_floating_wire in hrefs) + assert ( + href_top_wire in hrefs + and href_middle_wire in hrefs + and href_bottom_wire in hrefs + and href_middle_floating_wire in hrefs + ) all_wires = set(netlist.get_hwires()) - assert (len(all_wires) == 2) + assert len(all_wires) == 2 all_wires = set(netlist.get_hwires(recursive=True)) - assert (len(all_wires) == 6) + assert len(all_wires) == 6 diff --git a/tests/spydrnet/util/tests/test_get_instances.py b/tests/spydrnet/util/tests/test_get_instances.py index 0e54403a..e0008804 100644 --- a/tests/spydrnet/util/tests/test_get_instances.py +++ b/tests/spydrnet/util/tests/test_get_instances.py @@ -43,9 +43,19 @@ def test_parameter_checking(self): definition = sdn.Definition() instance = definition.create_child() instance.name = "MY_INST" - self.assertRaises(TypeError, sdn.get_instances, definition, "MY_INST", patterns="MY_INST") - self.assertRaises(TypeError, sdn.get_instances, definition, "MY_INST", unsupported_keyword=None) - self.assertRaises(TypeError, sdn.get_instances, definition, "MY_INST", selection=sdn.BOTH) + self.assertRaises( + TypeError, sdn.get_instances, definition, "MY_INST", patterns="MY_INST" + ) + self.assertRaises( + TypeError, + sdn.get_instances, + definition, + "MY_INST", + unsupported_keyword=None, + ) + self.assertRaises( + TypeError, sdn.get_instances, definition, "MY_INST", selection=sdn.BOTH + ) self.assertRaises(TypeError, sdn.get_instances, None, "MY_INST") self.assertRaises(TypeError, sdn.get_instances, [None, definition], "MY_INST") @@ -74,11 +84,15 @@ def test_get_instances_from_definition_recursive(self): self.assertEqual(self.instance, instance1[0]) def test_from_definition_outside_recursive(self): - instance1 = list(sdn.get_instances(self.definition, selection="OUTSIDE", recursive=True)) + instance1 = list( + sdn.get_instances(self.definition, selection="OUTSIDE", recursive=True) + ) self.assertEqual(self.top_instance, instance1[0]) def test_from_leaf_definition_outside_recursive(self): - instance1 = list(sdn.get_instances(self.leaf_definition, selection="OUTSIDE", recursive=True)) + instance1 = list( + sdn.get_instances(self.leaf_definition, selection="OUTSIDE", recursive=True) + ) self.assertEqual(len(instance1), 2) self.assertTrue(self.top_instance in instance1 and self.instance in instance1) @@ -87,7 +101,9 @@ def test_from_instance_recursive(self): self.assertEqual(self.instance, instance1) def test_from_instance_outside_resursive(self): - instance1 = list(sdn.get_instances(self.instance, selection="OUTSIDE", recursive=True)) + instance1 = list( + sdn.get_instances(self.instance, selection="OUTSIDE", recursive=True) + ) self.assertEqual(self.top_instance, instance1[0]) def test_from_wire(self): diff --git a/tests/spydrnet/util/tests/test_get_libraries.py b/tests/spydrnet/util/tests/test_get_libraries.py index 3d2ccfa6..0c05c4ab 100644 --- a/tests/spydrnet/util/tests/test_get_libraries.py +++ b/tests/spydrnet/util/tests/test_get_libraries.py @@ -8,26 +8,26 @@ def setUpClass(cls) -> None: cls.netlist = sdn.Netlist() leaf_library = cls.netlist.create_library() - leaf_library.name = 'primitives' + leaf_library.name = "primitives" library = cls.netlist.create_library() - library.name = 'work' + library.name = "work" leaf_def = leaf_library.create_definition() - leaf_def.name = 'leaf' + leaf_def.name = "leaf" leaf_port = leaf_def.create_port() - leaf_port.name = 'I' + leaf_port.name = "I" leaf_port.create_pins(1) bottom_def = library.create_definition() - bottom_def.name = 'bottom' + bottom_def.name = "bottom" bottom_port = bottom_def.create_port() - bottom_port.name = 'I' + bottom_port.name = "I" bottom_port.create_pins(1) leaf_inst = bottom_def.create_child() leaf_inst.reference = leaf_def bottom_cable = bottom_def.create_cable() - bottom_cable.name = 'bottom_cable' + bottom_cable.name = "bottom_cable" bottom_wire = bottom_cable.create_wire() bottom_wire.connect_pin(bottom_port.pins[0]) bottom_wire.connect_pin(leaf_inst.pins[leaf_port.pins[0]]) @@ -36,12 +36,12 @@ def setUpClass(cls) -> None: bottom_floating_wire = bottom_cable.create_wire() middle_def = library.create_definition() - middle_def.name = 'middle' + middle_def.name = "middle" middle_port = middle_def.create_port() middle_port.name = "I" middle_port.create_pin() bottom_inst = middle_def.create_child() - bottom_inst.name = 'bottom' + bottom_inst.name = "bottom" bottom_inst.reference = bottom_def middle_cable = middle_def.create_cable() middle_cable.name = "middle_cable" @@ -52,12 +52,12 @@ def setUpClass(cls) -> None: middle_floating_wire = middle_cable.create_wire() top_def = library.create_definition() - top_def.name = 'top' + top_def.name = "top" top_port = top_def.create_port() top_port.name = "I" top_port.create_pin() middle_inst = top_def.create_child() - middle_inst.name = 'middle' + middle_inst.name = "middle" middle_inst.reference = middle_def top_cable = top_def.create_cable() top_cable.name = "top_cable" @@ -68,7 +68,7 @@ def setUpClass(cls) -> None: top_floating_wire = top_cable.create_wire() top_instance = sdn.Instance() - top_instance.name = 'top' + top_instance.name = "top" top_instance.reference = top_def cls.netlist.top_instance = top_instance @@ -76,9 +76,15 @@ def test_parameter_checking(self): netlist = sdn.Netlist() library = netlist.create_library() library.name = "MY_LIB" - self.assertRaises(TypeError, sdn.get_libraries, netlist, "MY_LIB", patterns="MY_LIB") - self.assertRaises(TypeError, sdn.get_libraries, netlist, "MY_LIB", unsupported_keyword=None) - self.assertRaises(TypeError, sdn.get_libraries, netlist, "MY_LIB", selection="BOTH") + self.assertRaises( + TypeError, sdn.get_libraries, netlist, "MY_LIB", patterns="MY_LIB" + ) + self.assertRaises( + TypeError, sdn.get_libraries, netlist, "MY_LIB", unsupported_keyword=None + ) + self.assertRaises( + TypeError, sdn.get_libraries, netlist, "MY_LIB", selection="BOTH" + ) self.assertRaises(TypeError, sdn.get_libraries, None, "MY_LIB") self.assertRaises(TypeError, sdn.get_libraries, [None, netlist], "MY_LIB") @@ -90,72 +96,145 @@ def test_collection(self): self.assertEqual(len(ports), 1) def test_get_library_of_instances_outside(self): - library_query = list(sdn.get_libraries(self.netlist.libraries[0].definitions[0].references, - selection="OUTSIDE")) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[1]) + library_query = list( + sdn.get_libraries( + self.netlist.libraries[0].definitions[0].references, selection="OUTSIDE" + ) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[1] + ) def test_get_library_of_instances_inside(self): - library_query = list(sdn.get_libraries(self.netlist.libraries[0].definitions[0].references, - selection="INSIDE")) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[0]) + library_query = list( + sdn.get_libraries( + self.netlist.libraries[0].definitions[0].references, selection="INSIDE" + ) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[0] + ) def test_get_library_of_instances_recursive_down(self): - library_query = list(sdn.get_libraries(self.netlist.top_instance, recursive=True)) - self.assertTrue(len(library_query) == 2 and all(x in library_query for x in self.netlist.libraries)) + library_query = list( + sdn.get_libraries(self.netlist.top_instance, recursive=True) + ) + self.assertTrue( + len(library_query) == 2 + and all(x in library_query for x in self.netlist.libraries) + ) def test_get_library_of_instances_recursive_up(self): - library_query = list(sdn.get_libraries(self.leaf_inst, selection="OUTSIDE", recursive=True)) - self.assertTrue(len(library_query) == 1 and library_query[0] is self.netlist.libraries[1]) + library_query = list( + sdn.get_libraries(self.leaf_inst, selection="OUTSIDE", recursive=True) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] is self.netlist.libraries[1] + ) def test_get_library_of_library_recursive_down(self): - library_query = list(sdn.get_libraries(self.netlist.libraries[1], selection="INSIDE", recursive=True)) - self.assertTrue(len(library_query) == 2 and all(x in library_query for x in self.netlist.libraries)) + library_query = list( + sdn.get_libraries( + self.netlist.libraries[1], selection="INSIDE", recursive=True + ) + ) + self.assertTrue( + len(library_query) == 2 + and all(x in library_query for x in self.netlist.libraries) + ) def test_get_library_of_library_recursive_up(self): - library_query = list(sdn.get_libraries(self.netlist.libraries[0], selection="OUTSIDE", recursive=True)) - self.assertTrue(len(library_query) == 1 and library_query[0] is self.netlist.libraries[1]) + library_query = list( + sdn.get_libraries( + self.netlist.libraries[0], selection="OUTSIDE", recursive=True + ) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] is self.netlist.libraries[1] + ) def test_get_library_of_inside_inside(self): - library_query = list(sdn.get_libraries(self.netlist.libraries[0].definitions[0], - selection="INSIDE")) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[0]) + library_query = list( + sdn.get_libraries( + self.netlist.libraries[0].definitions[0], selection="INSIDE" + ) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[0] + ) def test_get_library_of_inside_outside(self): - library_query = list(sdn.get_libraries(self.netlist.libraries[0].definitions[0], - selection="OUTSIDE")) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[1]) + library_query = list( + sdn.get_libraries( + self.netlist.libraries[0].definitions[0], selection="OUTSIDE" + ) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[1] + ) def test_get_library_of_inside_outside_recursive(self): - library_query = list(sdn.get_libraries(self.netlist.libraries[0].definitions[0], - selection="OUTSIDE", recursive=True)) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[1]) + library_query = list( + sdn.get_libraries( + self.netlist.libraries[0].definitions[0], + selection="OUTSIDE", + recursive=True, + ) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[1] + ) def test_get_library_of_inside_inside_recursive(self): - library_query = list(sdn.get_libraries(self.netlist.top_instance.reference, - selection="INSIDE", recursive=True)) - self.assertTrue(len(library_query) == 2 and all(x in library_query for x in self.netlist.libraries)) + library_query = list( + sdn.get_libraries( + self.netlist.top_instance.reference, selection="INSIDE", recursive=True + ) + ) + self.assertTrue( + len(library_query) == 2 + and all(x in library_query for x in self.netlist.libraries) + ) def test_get_library_from_outer_pins(self): library_query = list(sdn.get_libraries(self.leaf_inst.pins)) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[0]) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[0] + ) def test_get_library_from_inner_pins(self): - library_query = list(sdn.get_libraries(self.leaf_inst.reference.ports[0].pins[0])) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[0]) + library_query = list( + sdn.get_libraries(self.leaf_inst.reference.ports[0].pins[0]) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[0] + ) def test_get_library_from_wire(self): - library_query = list(sdn.get_libraries(self.netlist.top_instance.reference.cables[0].wires[0])) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[1]) + library_query = list( + sdn.get_libraries(self.netlist.top_instance.reference.cables[0].wires[0]) + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[1] + ) def test_get_library_from_href(self): href = next(sdn.get_hinstances(self.netlist.top_instance)) library_query = list(sdn.get_libraries(href)) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[1]) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[1] + ) def test_unique_query_return(self): - library_query = list(sdn.get_libraries([self.netlist, self.netlist.top_instance], "work")) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[1]) + library_query = list( + sdn.get_libraries([self.netlist, self.netlist.top_instance], "work") + ) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[1] + ) def test_absolute_pattern_from_relative_query(self): library_query = list(sdn.get_libraries(self.netlist.top_instance, "work")) - self.assertTrue(len(library_query) == 1 and library_query[0] == self.netlist.libraries[1]) + self.assertTrue( + len(library_query) == 1 and library_query[0] == self.netlist.libraries[1] + ) diff --git a/tests/spydrnet/util/tests/test_get_netlists.py b/tests/spydrnet/util/tests/test_get_netlists.py index 89dca6be..bca92af5 100644 --- a/tests/spydrnet/util/tests/test_get_netlists.py +++ b/tests/spydrnet/util/tests/test_get_netlists.py @@ -7,8 +7,12 @@ def test_parameter_checking(self): netlist = sdn.Netlist() library = netlist.create_library() library.name = "MY_LIB" - self.assertRaises(TypeError, sdn.get_netlists, netlist, "MY_LIB", patterns="MY_LIB") - self.assertRaises(TypeError, sdn.get_netlists, netlist, "MY_LIB", unsupported_keyword=None) + self.assertRaises( + TypeError, sdn.get_netlists, netlist, "MY_LIB", patterns="MY_LIB" + ) + self.assertRaises( + TypeError, sdn.get_netlists, netlist, "MY_LIB", unsupported_keyword=None + ) self.assertRaises(TypeError, sdn.get_netlists, None, "MY_LIB") self.assertRaises(TypeError, sdn.get_netlists, [None, netlist], "MY_LIB") diff --git a/tests/spydrnet/util/tests/test_get_ports.py b/tests/spydrnet/util/tests/test_get_ports.py index 95edbdb5..6f3ac93d 100644 --- a/tests/spydrnet/util/tests/test_get_ports.py +++ b/tests/spydrnet/util/tests/test_get_ports.py @@ -7,8 +7,12 @@ def test_parameter_checking(self): definition = sdn.Definition() port = definition.create_port() port.name = "MY_PORT" - self.assertRaises(TypeError, sdn.get_ports, definition, "MY_PORT", patterns="MY_PORT") - self.assertRaises(TypeError, sdn.get_ports, definition, "MY_PORT", unsupported_keyword=None) + self.assertRaises( + TypeError, sdn.get_ports, definition, "MY_PORT", patterns="MY_PORT" + ) + self.assertRaises( + TypeError, sdn.get_ports, definition, "MY_PORT", unsupported_keyword=None + ) self.assertRaises(TypeError, sdn.get_ports, None, "MY_PORT") self.assertRaises(TypeError, sdn.get_ports, [None, definition], "MY_PORT") diff --git a/tests/spydrnet/util/tests/test_get_wires.py b/tests/spydrnet/util/tests/test_get_wires.py index cd3a02cf..1661aea1 100644 --- a/tests/spydrnet/util/tests/test_get_wires.py +++ b/tests/spydrnet/util/tests/test_get_wires.py @@ -8,26 +8,26 @@ def setUpClass(cls) -> None: cls.netlist = sdn.Netlist() leaf_library = cls.netlist.create_library() - leaf_library.name = 'primitives' + leaf_library.name = "primitives" library = cls.netlist.create_library() - library.name = 'work' + library.name = "work" leaf_def = leaf_library.create_definition() - leaf_def.name = 'leaf' + leaf_def.name = "leaf" leaf_port = leaf_def.create_port() - leaf_port.name = 'I' + leaf_port.name = "I" leaf_port.create_pins(1) bottom_def = library.create_definition() - bottom_def.name = 'bottom' + bottom_def.name = "bottom" bottom_port = bottom_def.create_port() - bottom_port.name = 'I' + bottom_port.name = "I" bottom_port.create_pins(1) leaf_inst = bottom_def.create_child() leaf_inst.reference = leaf_def bottom_cable = bottom_def.create_cable() - bottom_cable.name = 'bottom_cable' + bottom_cable.name = "bottom_cable" bottom_wire = bottom_cable.create_wire() bottom_wire.connect_pin(bottom_port.pins[0]) bottom_wire.connect_pin(leaf_inst.pins[leaf_port.pins[0]]) @@ -36,12 +36,12 @@ def setUpClass(cls) -> None: bottom_floating_wire = bottom_cable.create_wire() middle_def = library.create_definition() - middle_def.name = 'middle' + middle_def.name = "middle" middle_port = middle_def.create_port() middle_port.name = "I" middle_port.create_pin() bottom_inst = middle_def.create_child() - bottom_inst.name = 'bottom' + bottom_inst.name = "bottom" bottom_inst.reference = bottom_def middle_cable = middle_def.create_cable() middle_cable.name = "middle_cable" @@ -53,12 +53,12 @@ def setUpClass(cls) -> None: middle_floating_wire = middle_cable.create_wire() top_def = library.create_definition() - top_def.name = 'top' + top_def.name = "top" top_port = top_def.create_port() top_port.name = "I" top_port.create_pin() middle_inst = top_def.create_child() - middle_inst.name = 'middle' + middle_inst.name = "middle" middle_inst.reference = middle_def top_cable = top_def.create_cable() top_cable.name = "top_cable" @@ -70,7 +70,7 @@ def setUpClass(cls) -> None: top_floating_wire = top_cable.create_wire() top_instance = sdn.Instance() - top_instance.name = 'top' + top_instance.name = "top" top_instance.reference = top_def cls.netlist.top_instance = top_instance @@ -85,7 +85,9 @@ def test_parameter_checking(self): self.assertRaises(TypeError, sdn.get_wires, [None, library]) def test_collection(self): - wires = list(sdn.get_wires([self.netlist.libraries[1], self.netlist.libraries[1]])) + wires = list( + sdn.get_wires([self.netlist.libraries[1], self.netlist.libraries[1]]) + ) self.assertEqual(len(wires), 6) def test_inside(self): @@ -97,7 +99,9 @@ def test_both(self): self.assertEqual(len(wires), 2) def test_outside(self): - wires = list(sdn.get_wires(self.middle_inst, selection="OUTSIDE", recursive=True)) + wires = list( + sdn.get_wires(self.middle_inst, selection="OUTSIDE", recursive=True) + ) self.assertEqual(len(wires), 1) def test_wire_inside(self): @@ -106,26 +110,42 @@ def test_wire_inside(self): self.assertIs(wires[0], self.middle_inst.reference.cables[0].wires[0]) def test_wire_outside(self): - wires = list(sdn.get_wires(self.middle_inst.reference.cables[0].wires[0], selection="OUTSIDE")) + wires = list( + sdn.get_wires( + self.middle_inst.reference.cables[0].wires[0], selection="OUTSIDE" + ) + ) self.assertEqual(len(wires), 2) self.assertTrue(self.middle_inst.reference.cables[0].wires[0] not in wires) def test_port_outside(self): - wires = list(sdn.get_wires(self.middle_inst.reference.ports[0], selection="OUTSIDE")) + wires = list( + sdn.get_wires(self.middle_inst.reference.ports[0], selection="OUTSIDE") + ) self.assertEqual(len(wires), 1) - self.assertTrue(wires[0].cable.name == 'top_cable') + self.assertTrue(wires[0].cable.name == "top_cable") def test_cable_outside(self): - wires = list(sdn.get_wires(self.middle_inst.reference.cables[0], selection="OUTSIDE")) + wires = list( + sdn.get_wires(self.middle_inst.reference.cables[0], selection="OUTSIDE") + ) self.assertEqual(len(wires), 2) - self.assertTrue(all(x not in wires for x in self.middle_inst.reference.cables[0].wires)) + self.assertTrue( + all(x not in wires for x in self.middle_inst.reference.cables[0].wires) + ) def test_cable_all(self): - wires = list(sdn.get_wires(self.netlist.top_instance.reference.cables[0].wires[0], selection="ALL")) + wires = list( + sdn.get_wires( + self.netlist.top_instance.reference.cables[0].wires[0], selection="ALL" + ) + ) self.assertEqual(len(wires), 3) def test_pin_all(self): - wires = list(sdn.get_wires(self.middle_inst.reference.ports[0].pins[0], selection="ALL")) + wires = list( + sdn.get_wires(self.middle_inst.reference.ports[0].pins[0], selection="ALL") + ) self.assertEqual(len(wires), 3) def test_pin_inside(self): diff --git a/tests/spydrnet/util/tests/test_hierarchical_reference.py b/tests/spydrnet/util/tests/test_hierarchical_reference.py index 75009eca..0d8970a0 100644 --- a/tests/spydrnet/util/tests/test_hierarchical_reference.py +++ b/tests/spydrnet/util/tests/test_hierarchical_reference.py @@ -48,11 +48,13 @@ def test_flyweight(self): href2 = HRef.from_parent_and_item(None, instance) self.assertTrue(href1 is href2) import weakref + w_href1 = weakref.ref(href1) w_href2 = weakref.ref(href2) href1 = None href2 = None import gc + gc.collect() self.assertIsNone(w_href1()) self.assertIsNone(w_href2()) @@ -99,7 +101,7 @@ def test_href_valid(self): self.assertFalse(href.is_valid) port = sdn.Port() - pin = sdn.InnerPin() + pin = sdn.InnerPin() href = HRef.from_sequence([instance, port, pin]) self.assertFalse(href.is_valid) @@ -183,7 +185,7 @@ def test_href_inst_name(self): instance = sdn.Instance() instance.name = "MY_INST" href = HRef.from_parent_and_item(None, instance) - self.assertEqual('', href.name) + self.assertEqual("", href.name) def test_href_wire_name(self): top = sdn.Instance() diff --git a/tests/spydrnet/util/tests/test_patterns.py b/tests/spydrnet/util/tests/test_patterns.py index 63db2681..106ad16c 100644 --- a/tests/spydrnet/util/tests/test_patterns.py +++ b/tests/spydrnet/util/tests/test_patterns.py @@ -18,4 +18,3 @@ def test_value_matches_pattern(self): def test_value_matches_pattern_bad_regex_expr(self): self.assertFalse(_value_matches_pattern(None, "*", is_case=False, is_re=True)) -