Skip to content

Commit

Permalink
ran black formatter on test code
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdbrown4 committed Aug 30, 2023
1 parent 34e4975 commit 678956d
Show file tree
Hide file tree
Showing 61 changed files with 2,476 additions and 1,308 deletions.
31 changes: 20 additions & 11 deletions tests/spydrnet/compare/tests/test_compare_netlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -71,22 +78,24 @@ 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()
comp = Comparer(nl1, nl2)
comp.compare()


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions tests/spydrnet/compare/tests/test_composers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import spydrnet as sdn


class TestComposers(unittest.TestCase):
def test_compose(self):
netlist = sdn.Netlist()
Expand Down
61 changes: 40 additions & 21 deletions tests/spydrnet/composers/eblif/tests/test_eblif_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

42 changes: 20 additions & 22 deletions tests/spydrnet/composers/edif/tests/test_edifify_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class TestEdififyNames(unittest.TestCase):

def test_simple_conversion(self):
ed = EdififyNames()
l = []
Expand All @@ -19,28 +18,27 @@ 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_"

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_"

Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/spydrnet/composers/edif/tests/test_topological_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
assert l_dep in found_libraries
Loading

0 comments on commit 678956d

Please sign in to comment.