Skip to content

Commit

Permalink
Add patch duplication test
Browse files Browse the repository at this point in the history
  • Loading branch information
Eloston committed Mar 7, 2020
1 parent 106ec89 commit 4679001
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 3 deletions.
22 changes: 22 additions & 0 deletions devutils/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[run]
branch = True
parallel = True
omit = tests/*

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
Empty file added devutils/__init__.py
Empty file.
20 changes: 19 additions & 1 deletion devutils/check_patch_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def check_unused_patches(patches_dir, series_path=Path('series')):
Unused patches are logged to stdout.
patches_dir is a pathlib.Path to the directory of patches
series_path is a pathlib.Path to the series file relative to the patch_dir
series_path is a pathlib.Path to the series file relative to the patches_dir
Returns True if there are unused patches; False otherwise.
"""
Expand All @@ -94,6 +94,23 @@ def check_unused_patches(patches_dir, series_path=Path('series')):
return bool(unused_patches)


def check_series_duplicates(patches_dir, series_path=Path('series')):
"""
Checks if there are duplicate entries in the series file
series_path is a pathlib.Path to the series file relative to the patches_dir
returns True if there are duplicate entries; False otherwise.
"""
entries_seen = set()
for entry in _read_series_file(patches_dir, series_path):
if entry in entries_seen:
get_logger().warning('Patch appears more than once in series: %s', entry)
return True
entries_seen.add(entry)
return False


def main():
"""CLI entrypoint"""

Expand All @@ -111,6 +128,7 @@ def main():

warnings = False
warnings |= check_patch_readability(args.patches)
warnings |= check_series_duplicates(args.patches)
warnings |= check_unused_patches(args.patches)

if warnings:
Expand Down
7 changes: 7 additions & 0 deletions devutils/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pytest]
testpaths = tests
#filterwarnings =
# error
# ignore::DeprecationWarning
#addopts = --cov-report term-missing --hypothesis-show-statistics -p no:warnings
addopts = --cov=. --cov-config=.coveragerc --cov-report term-missing -p no:warnings
7 changes: 7 additions & 0 deletions devutils/run_devutils_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -eux

_root_dir=$(dirname $(dirname $(readlink -f $0)))
cd ${_root_dir}/devutils
python3 -m pytest -c ${_root_dir}/devutils/pytest.ini
Empty file added devutils/tests/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions devutils/tests/test_check_patch_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: UTF-8 -*-

# Copyright (c) 2019 The ungoogled-chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Test check_patch_files.py"""

import tempfile
from pathlib import Path

from ..check_patch_files import check_series_duplicates


def test_check_series_duplicates():
"""Test check_series_duplicates"""
with tempfile.TemporaryDirectory() as tmpdirname:
patches_dir = Path(tmpdirname)
series_path = Path(tmpdirname, 'series')

# Check no duplicates
series_path.write_text('\n'.join([
'a.patch',
'b.patch',
'c.patch',
]))
assert not check_series_duplicates(patches_dir)

# Check duplicates
series_path.write_text('\n'.join([
'a.patch',
'b.patch',
'c.patch',
'a.patch',
]))
assert check_series_duplicates(patches_dir)
4 changes: 3 additions & 1 deletion devutils/validate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

from check_downloads_ini import check_downloads_ini
from check_gn_flags import check_gn_flags
from check_patch_files import check_patch_readability, check_unused_patches
from check_patch_files import (check_patch_readability, check_series_duplicates,
check_unused_patches)


def main():
Expand All @@ -39,6 +40,7 @@ def main():

# Check patches
warnings |= check_patch_readability(patches_dir)
warnings |= check_series_duplicates(patches_dir)
warnings |= check_unused_patches(patches_dir)

# Check GN flags
Expand Down
1 change: 0 additions & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# TODO: Figure out why this file is needed for Pylint to work when devutils doesn't need it

0 comments on commit 4679001

Please sign in to comment.