Skip to content

Commit

Permalink
Add options to skip tests (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
regebro committed Apr 30, 2023
1 parent 7388022 commit e363f67
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changelog
4.3 (unreleased)
----------------

- Nothing changed yet.
- Added a --skip-tests parameter to allow skipping of certain tests.
You shouldn't skip tests, of course, but now you can. This is actually
only implemented so that I can add a test using check-manifest and
skip it when run from the zest.releaser hook.


4.2 (2023-02-25)
Expand Down
44 changes: 41 additions & 3 deletions pyroma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,39 @@ def min_argument(arg):
return f


def get_all_tests():
return [x.__class__.__name__ for x in ratings.ALL_TESTS]


def parse_tests(arg):
if not arg:
return

arg = [arg]
for sep in " ,;":
skips = []
for t in arg:
skips.extend(t.split(sep))
arg = skips

tests = get_all_tests()
for skip in arg:
if skip not in tests:
return

return skip


def skip_tests(arg):
test_to_skip = parse_tests(arg)
if test_to_skip:
return test_to_skip

tests = ", ".join(get_all_tests())
message = f"Invalid tests listed. Available tests: {tests}"
raise ArgumentTypeError(message)


def main():
parser = ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -94,6 +127,11 @@ def main():
default=False,
help="Output only the rating",
)
parser.add_argument(
"--skip-tests",
type=skip_tests,
help="Skip the named tests",
)

args = parser.parse_args()

Expand All @@ -106,13 +144,13 @@ def main():
else:
mode = "pypi"

rating = run(mode, args.package, args.quiet)
rating = run(mode, args.package, args.quiet, args.skip_tests)
if rating < args.min:
sys.exit(2)
sys.exit(0)


def run(mode, argument, quiet=False):
def run(mode, argument, quiet=False, skip_tests=None):

if quiet:
logger = logging.getLogger()
Expand All @@ -132,7 +170,7 @@ def run(mode, argument, quiet=False):
data = pypidata.get_data(argument)
logging.info("Found " + data.get("name", "nothing"))

rating = ratings.rate(data)
rating = ratings.rate(data, skip_tests)

logging.info("-" * 30)
for problem in rating[1]:
Expand Down
8 changes: 7 additions & 1 deletion pyroma/ratings.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,15 +508,21 @@ def message(self):
]


def rate(data):
def rate(data, skip_tests=None):
if not data:
# No data was gathered. Fail:
return (0, ["I couldn't find any package data"])

if skip_tests is None:
skip_tests = []

fails = []
good = 0
bad = 0
fatality = False
for test in ALL_TESTS:
if test.__class__.__name__ in skip_tests:
continue
res = test.test(data)
if res is False:
fails.append(test.message())
Expand Down
12 changes: 10 additions & 2 deletions pyroma/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ class RatingsTest(unittest.TestCase):

maxDiff = None

def _get_file_rating(self, dirname):
def _get_file_rating(self, dirname, skip_tests=None):
directory = resource_filename(__name__, os.path.join("testdata", dirname))
data = projectdata.get_data(directory)
return rate(data)
return rate(data, skip_tests)

def test_complete(self):
rating = self._get_file_rating("complete")
Expand Down Expand Up @@ -141,6 +141,14 @@ def test_only_config(self):
),
)

def test_skip_tests(self):
rating = self._get_file_rating("only_config", skip_tests=["PythonRequiresVersion", "MissingBuildSystem"])

self.assertEqual(
rating,
(10, []),
)

def test_pep517(self):
rating = self._get_file_rating("pep517")
self.assertEqual(
Expand Down

0 comments on commit e363f67

Please sign in to comment.