Skip to content

Commit

Permalink
Merge pull request #265 from laurenmarietta/test-utils-filesystem
Browse files Browse the repository at this point in the history
Test filename_parser with whole filesystem
  • Loading branch information
bourque authored Feb 1, 2019
2 parents ca51c37 + f49fbc5 commit 749e656
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ docs/build/
docs/source/api/
.cache
*.pytest_cache
htmlcov/
35 changes: 33 additions & 2 deletions jwql/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
pytest -s test_utils.py
"""

import os

import pytest

from jwql.utils.utils import get_config, filename_parser
Expand Down Expand Up @@ -150,9 +152,9 @@
]


@pytest.mark.xfail
@pytest.mark.xfail(reason='User must manually supply config file.')
def test_get_config():
"""Assert that the ``get_config`` function successfuly creates a
"""Assert that the ``get_config`` function successfully creates a
dictionary.
"""
settings = get_config()
Expand All @@ -175,6 +177,35 @@ def test_filename_parser(filename, solution):
assert filename_parser(filename) == solution


@pytest.mark.xfail(reason='Known non-compliant files in filesystem')
def test_filename_parser_whole_filesystem():
"""Test the filename_parser on all files currently in the filesystem.
"""
# Get all files
filesystem_dir = get_config()['filesystem']
all_files = []
for dir_name, _, file_list in os.walk(filesystem_dir):
for file in file_list:
if file.endswith('.fits'):
all_files.append(os.path.join(dir_name, file))

# Run the filename_parser on all files
bad_filenames = []
for filepath in all_files:
try:
filename_parser(filepath)
except ValueError:
bad_filenames.append(os.path.basename(filepath))

# Determine if the test failed
fail = bad_filenames != []
failure_msg = '{} files could not be successfully parsed: \n - {}'.\
format(len(bad_filenames), '\n - '.join(bad_filenames))

# Check which ones failed
assert not fail, failure_msg


def test_filename_parser_nonJWST():
"""Attempt to generate a file parameter dictionary from a file
that is not formatted in the JWST naming convention. Ensure the
Expand Down

0 comments on commit 749e656

Please sign in to comment.