Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions iris_grib/tests/test_license_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,29 @@ def last_change_by_fname():
or cannot be found by subprocess, an IOError may also be raised.

"""
# Check the ".git" folder exists at the repo dir.
if not os.path.isdir(os.path.join(REPO_DIR, '.git')):
raise ValueError('{} is not a git repository.'.format(REPO_DIR))

# Call "git whatchanged" to get the details of all the files and when
# they were last changed.
output = subprocess.check_output(['git', 'whatchanged',
"--pretty=TIME:%ct"],
cwd=REPO_DIR)
output = output.decode().split('\n')
res = {}
for fname, dt in TestLicenseHeaders.whatchanged_parse(output):
if fname not in res or dt > res[fname]:
res[fname] = dt

# HACKED!
# just return all the paths in the subdir 'tests/unit/load_convert/*.py'
import iris_grib.tests.unit.load_convert as testmod
from pathlib import Path
pths = list(Path(testmod.__file__).parent.glob('test_grid_def*.py'))
# Usual function returns a dict (though only the keys are ever used?)
res = {str(pth): 0 for pth in pths}

# # Check the ".git" folder exists at the repo dir.
# if not os.path.isdir(os.path.join(REPO_DIR, '.git')):
# raise ValueError('{} is not a git repository.'.format(REPO_DIR))
#
# # Call "git whatchanged" to get the details of all the files and when
# # they were last changed.
# output = subprocess.check_output(['git', 'whatchanged',
# "--pretty=TIME:%ct"],
# cwd=REPO_DIR)
# output = output.decode().split('\n')
# res = {}
# for fname, dt in TestLicenseHeaders.whatchanged_parse(output):
# if fname not in res or dt > res[fname]:
# res[fname] = dt

return res

Expand All @@ -98,8 +107,11 @@ def test_license_headers(self):
return self.skipTest('Iris-grib installation did not look like a '
'git repo.')

failed = False
tested_paths = []
fail_paths = [1]
# failed = False
for fname, last_change in sorted(last_change_by_fname.items()):
tested_paths.append(fname)
full_fname = os.path.join(REPO_DIR, fname)
if full_fname.endswith('.py') and os.path.isfile(full_fname) and \
not any(fnmatch(fname, pat) for pat in exclude_patterns):
Expand All @@ -108,10 +120,13 @@ def test_license_headers(self):
if not content.startswith(LICENSE_TEMPLATE):
print('The file {} does not start with the required '
'license header.'.format(fname))
failed = True
# failed = True
fail_paths.append(fname)

if failed:
raise ValueError('There were license header failures. See stdout.')
self.maxDiff = None
self.assertEqual((tested_paths, fail_paths), (tested_paths, []))
# if failed:
# raise ValueError('There were license header failures. See stdout.')


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright iris-grib contributors
#
# MESS THIS UP
#
# This file is part of iris-grib and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

"""

# MEANINGLESS CHANGE
# - temporary tweak to force licence check on this file (otherwise unchanged).

# import iris_grib.tests first so that some things can be initialised
# before importing anything else.
import iris_grib.tests as tests
Expand Down