def test_location_specific(self): """Since a file path is given, the Description class should return True.""" code = textwrap.dedent("""\ import os os.path.join("asdf") print('more lines') """) code += "\n" * 100 root = tempfile.mkdtemp() self.delete_item_later(root) description = message_description.Description( ["some text"], message_description.Location(root, 110, 3, ""), base_checker.Code(short_name="Z", long_name="some-code"), ) self.assertTrue(description.is_location_specific()) description = message_description.Description( ["some text"], message_description.Location("foo", 110, 3, ""), base_checker.Code(short_name="Z", long_name="some-code"), ) self.assertFalse(description.is_location_specific())
def test_empty(): """Creating a description with basically nothing in it should still be valid.""" message_description.Description( [], message_description.Location(".", 0, 0, ""), base_checker.Code(short_name="", long_name=""), )
def test_vimgrep_001(self): """Check that Description prints path / row / column information correctly.""" code = textwrap.dedent("""\ import os os.path.join("asdf") print('more lines') """) code += "\n" * 100 root = tempfile.mkdtemp() self.delete_item_later(root) path = os.path.join(root, "some_module.py") with open(path, "w") as handler: handler.write(code) description = message_description.Description( ["some text"], message_description.Location(path, 110, 3, ""), base_checker.Code(short_name="Z", long_name="some-code"), ) self.assertEqual(["Z: 110, 3: some text (some-code)"], description.get_message(verbose=True)) self.assertEqual(3, description.get_padding_row()) self.assertEqual(1, description.get_padding_column()) self.assertEqual( "{path}:110:3: (some-code)".format(path=path), description.get_location_data(), )
def test_empty(self): """An empty location should error - there needs to always be some file path.""" with self.assertRaises(ValueError): message_description.Description( [], message_description.Location("", 0, 0, ""), base_checker.Code(short_name="Z", long_name="some-code"), )
def test_dot(self): """A single dot path (e.g. ".") should return the current directory.""" description = message_description.Description( [], message_description.Location(".", 0, 0, ""), base_checker.Code(short_name="Z", long_name="some-code"), ) self.assertEqual(os.getcwd(), description.get_header())
def test_summary(self): """Make sure description summarizes print as-expected.""" description = message_description.Description( ["Some important message"], message_description.Location(".", 0, 0, ""), base_checker.Code(short_name="Z", long_name="some-code"), ) self.assertEqual(["Z: 0, 0: Some important message (some-code)"], description.get_message())
def test_absolute(self): """A location that is next to or above the current directory should return absolute.""" parent = os.path.dirname(os.getcwd()) description = message_description.Description( [], message_description.Location(parent, 0, 0, ""), base_checker.Code(short_name="Z", long_name="some-code"), ) self.assertEqual(parent, description.get_header())
def test_relative_001(self): """A location that is below the current directory should return relative.""" description = message_description.Description( [], message_description.Location( os.path.join(os.getcwd(), "something", "else"), 0, 0, ""), base_checker.Code(short_name="Z", long_name="some-code"), ) self.assertEqual(os.path.join("something", "else"), description.get_header())
def _get_no_documentation_message(directory): summary = "No documentation found" return message_description.Description( [summary], message_description.Location(directory, 0, 0, ""), base_checker.Code(short_name="E", long_name="no-documentation"), full=[ summary, "Consider adding documentation to your Python package.", "Reference: https://www.sphinx-doc.org/en/master/usage/quickstart.html", ], )
def test_sorting(self): """Make sure the vimgrep output is sorted correctly.""" descriptions = [ message_description.Description( ["some text"], message_description.Location("foo", 110, 3, ""), base_checker.Code(short_name="Z", long_name="some-code"), ), message_description.Description( ["bar"], message_description.Location("foo", 1, 10, ""), base_checker.Code(short_name="Z", long_name="some-code"), ), message_description.Description( ["another"], message_description.Location("foo", 1, 10, ""), base_checker.Code(short_name="Z", long_name="some-code"), ), message_description.Description( ["foo"], message_description.Location("foo", 20, 10, ""), base_checker.Code(short_name="Z", long_name="some-code"), ), ] lines = [] lines.extend(line for description in descriptions for line in description.get_message(verbose=True)) self.assertEqual( [ "Z: 1, 10: another (some-code)", "Z: 1, 10: bar (some-code)", "Z: 20, 10: foo (some-code)", "Z: 110, 3: some text (some-code)", ], message_description.sort_with_vimgrep(lines), )
def test_full(self): """Make sure description summarizes print as-expected.""" summary = "Some important message" description = message_description.Description( [summary], message_description.Location(".", 0, 0, ""), base_checker.Code(short_name="Z", long_name="some-code"), full=[summary, "More information here", "And even more"], ) self.assertEqual( [ "Z: 0, 0: Some important message (some-code)", " More information here", " And even more", ], description.get_message(verbose=True), )
def test_vimgrep_002(self): """Check that Description prints path / row / column information correctly.""" root = tempfile.mkdtemp() self.delete_item_later(root) description = message_description.Description( ["some text"], message_description.Location(root, 110, 3, ""), base_checker.Code(short_name="Z", long_name="some-code"), ) self.assertEqual(["Z: 110, 3: some text (some-code)"], description.get_message(verbose=True)) self.assertEqual(0, description.get_padding_row()) self.assertEqual(1, description.get_padding_column()) self.assertEqual( "{root}:110:3: (some-code)".format(root=root), description.get_location_data(), )
def _get_no_readme_message(directory): return message_description.Description( ["Rez package has no README file"], message_description.Location(directory, 0, 0, ""), base_checker.Code(short_name="E", long_name="no-read-me"), )
def _get_no_changelog_message(directory): return message_description.Description( ["Rez package has no CHANGELOG file"], message_description.Location(directory, 0, 0, ""), base_checker.Code(short_name="E", long_name="no-change-log"), )