Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
amykyta3 committed Oct 26, 2023
1 parent ca1a768 commit 1fe9705
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/test_cfg_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def test_extract_base_types(self):
"date": schema.Date(),
"time": schema.Time(),
"int_array": [schema.Integer()],
"user_mapping": {"*": schema.Integer()}
"user_mapping": {"*": schema.Integer()},
"anything": schema.AnyType(),
"choice": schema.Choice(["a", "b", "c"]),
}

sch = schema.normalize(sch)
Expand All @@ -32,7 +34,9 @@ def test_extract_base_types(self):
"user_mapping": {
"foo": 1,
"bar": 2,
}
},
"anything": [1, 2, "hi"],
"choice": "a",
}

data = sch.extract(raw_data, __file__, "testcase")
Expand Down Expand Up @@ -75,6 +79,12 @@ def test_bad_type(self):
with self.assertRaises(schema.SchemaException):
sch.extract(raw_data, __file__, "testcase")

with self.subTest("choice"):
sch = schema.Choice("b")
raw_data = "hi"
with self.assertRaises(schema.SchemaException):
sch.extract(raw_data, __file__, "testcase")

def test_paths(self):
this_dir = os.path.dirname(__file__)

Expand Down Expand Up @@ -105,6 +115,15 @@ def test_paths(self):
os.path.abspath(os.path.join(this_dir, "run.sh"))
)

with self.subTest("abspath"):
sch = schema.Path(shall_exist=False)
raw_data = "/foo/bar"
data = sch.extract(raw_data, __file__, "testcase")
self.assertEqual(
data,
raw_data
)

def test_path_errors(self):
with self.subTest("exists"):
sch = schema.Path()
Expand Down
42 changes: 42 additions & 0 deletions test/test_core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,48 @@ def test_dump(self):
])
self.assertEqual(captured.out, expected)

def test_dump_fields(self):
self.run_commandline([
'dump',
os.path.join(self.testdata_dir, "structural.rdl"),
"-F"
])
captured = self.capsys.readouterr()
expected = "\n".join([
"0x0000-0x0003: regblock.r0",
"\t[7:0] a",
"\t[8:8] b",
"\t[31:31] c",
"0x0010-0x006f: regblock.r1[2][3][4]",
"\t[7:0] a",
"\t[8:8] b",
"\t[31:31] c",
"0x1000-0x1003: regblock.r2",
"\t[7:0] a",
"\t[8:8] b",
"\t[31:31] c",
"0x2000-0x200f: regblock.sub2[2].r1[4]",
"\t[7:4] x",
"0x2010-0x2013: regblock.sub2[2].sub[2].r1",
"\t[7:4] x",
"0x2014-0x201b: regblock.sub2[2].sub[2].r2[2]",
"\t[7:4] x",
"0x201c-0x201f: regblock.sub2[2].sub[2].r3",
"\t[7:4] x",
"0x2030-0x203f: regblock.sub2[2].r2[4]",
"\t[7:4] x",
"0x2080-0x2083: regblock.r3",
"\t[7:4] x",
"0x3000-0x3003: regblock.rw_reg",
"\t[19:12] f1",
"\t[30:20] f2",
"0x3004-0x3007: regblock.rw_reg_lsb0",
"\t[12:19] f1",
"\t[20:30] f2",
"",
])
self.assertEqual(captured.out, expected)

def test_dump_unroll(self):
self.run_commandline([
'dump',
Expand Down

0 comments on commit 1fe9705

Please sign in to comment.