From 77de25494f9697dc080261ede8df2211e7fd293d Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Wed, 22 Nov 2023 21:47:57 +0100 Subject: [PATCH] Add more coverage for tests --- tests.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests.py b/tests.py index b63ecb3..05bdd81 100644 --- a/tests.py +++ b/tests.py @@ -103,3 +103,27 @@ def test_contains_dot_proto_in_middle_of_the_name(self): .build() assert os.path.getsize(tf) > 0 + + def test_to_file_with_missing_protobuf(self): + """A test where the protobuf module is missing.""" + with TemporaryDirectory() as tmpdir: + tf = os.path.join(tmpdir, 'diagram.png') + d = Diagram().from_file('test_data.issue_27.proto.configs_data_pb2') + d._proto_module = None + with pytest.raises(ValueError) as cm: + d.to_file(Path(tf)) + assert str(cm.value) == 'Missing protobuf module!' + + + def test_to_file_with_protobuf_missing_file(self): + """A test where the protobuf module is present but invalid (no file).""" + with TemporaryDirectory() as tmpdir: + tf = os.path.join(tmpdir, 'diagram.png') + d = Diagram().from_file('test_data.issue_27.proto.configs_data_pb2') + d._proto_module = {} + with pytest.raises(ValueError) as cm: + d.to_file(Path(tf)) + assert str(cm.value) == 'Missing protobuf module!' + + +