def _describe_location(*codes): """ Helper to test describe_location """ contents = {} location = None for idx, code in enumerate(codes): filename = "filename%i" % idx contents[filename] = code start = code.index("S") if "E" in code: end = code.index("E") else: end = start location = ((filename, (start, end)), location) with mock.patch("vunit.parsing.tokenizer.read_file", autospec=True) as mock_read_file: with mock.patch("vunit.parsing.tokenizer.file_exists", autospec=True) as mock_file_exists: def file_exists_side_effect(filename): return filename in contents def read_file_side_effect(filename): return contents[filename] mock_file_exists.side_effect = file_exists_side_effect mock_read_file.side_effect = read_file_side_effect retval = describe_location(location=location) return retval
def test_describe_none_filename_location(self): self.assertEqual(describe_location(((None, (0, 0)), None)), "Unknown Python string")
def test_describe_missing_location(self): self.assertEqual(describe_location((("missing.svh", (0, 0)), None)), "Unknown location in missing.svh")
def test_describe_location_none(self): self.assertEqual(describe_location(None), "Unknown location")