Skip to content

Commit

Permalink
Images listing file to help content checking; util to update it; test…
Browse files Browse the repository at this point in the history
… to check it.
  • Loading branch information
pp-mo committed May 3, 2019
1 parent f9910af commit e8f0ab0
Show file tree
Hide file tree
Showing 4 changed files with 580 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
*.py[co]

# Packages
*.egg?
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt
pip-cache

# Unit test / coverage reports
.coverage
.tox
.pytest_cache

#Translations
*.mo

# Pydev/Eclipse files
.project
.pydevproject
.settings

# PyCharm files
/.idea
*.cover

# Created by editiors
*~
\#*
\.\#*
*.swp
28 changes: 28 additions & 0 deletions recreate_v4_files_listing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python

import os
import os.path
from glob import glob

REPO_MAIN_DIRPATH = os.path.dirname(os.path.abspath(__file__))
V4_DIR = os.sep.join([REPO_MAIN_DIRPATH, 'images', 'v4'])
V4_LISTFILE_NAME = 'v4_files_listing.txt'
V4_LISTFILE_PATH = os.sep.join([REPO_MAIN_DIRPATH, V4_LISTFILE_NAME])

def get_v4_imagefile_names(search_dirpath=V4_DIR, filespec='*.png'):
"""Return a list of the current image files in the v4 subdirectory."""
files_spec = os.path.join(search_dirpath, filespec)
file_paths = glob(files_spec)
return [os.path.basename(file_path) for file_path in file_paths]


def create_v4_images_listfile(search_dirpath=V4_DIR, filespec='*.png',
output_filepath=V4_LISTFILE_PATH):
file_names = get_v4_imagefile_names(search_dirpath, filespec)
with open(output_filepath, 'w') as f_out:
for file_name in file_names:
f_out.write('{}\n'.format(file_name))


if __name__ == '__main__':
create_v4_images_listfile()
30 changes: 30 additions & 0 deletions run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,35 @@ def test(self):
self.assertEqual([], exceptions)


class TestListing(unittest.TestCase):
def test(self):
# Check that the image listing file contents are up to date.
import recreate_v4_files_listing as v4list
file_names = set(v4list.get_v4_imagefile_names())
listing_filepath = v4list.V4_LISTFILE_NAME
self.assertTrue(os.path.exists(listing_filepath))
with open(listing_filepath) as listing_file:
listed_names = [line.strip()
for line in listing_file.readlines()]

files = set(file_names)
listed = set(listed_names)
if listed != files:
msg = ('Filenames in the listing file {} do not match the image '
'file contents of the {} directory:')
msg = msg.format(v4list.V4_LISTFILE_NAME, v4list.V4_DIR)
newfiles = files - listed
if newfiles:
msg += '\n Names in directory, but not in the listing file:'
msg += ''.join(['\n ' + name for name in newfiles])
missing = listed - files
if missing:
msg += '\n Names in the listing, but not in the directory:'
msg += ''.join(['\n ' + name for name in missing])
msg += ('\n\n*** Please run "{}.py" to correct. ***'.format(
os.path.basename(v4list.__name__)))
self.assertEqual(listed, files, msg)


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit e8f0ab0

Please sign in to comment.