Skip to content

Commit

Permalink
Fix for JASCIS-345
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanwp committed Aug 3, 2016
1 parent 106b38f commit 348ed36
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cis/data_io/products/AProduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def __get_class(filename, product=None):
class_instance = cls()
patterns = class_instance.get_file_signature()
for pattern in patterns:
# Match the pattern - re.I allows for case insensitive matches
if re.match(pattern, basename, re.I) is not None:
# Match the pattern - re.I allows for case insensitive matches.
# Appending '$' to the pattern ensures we match the whole string
if re.match(pattern+'$', basename, re.I) is not None:
logging.debug("Found product class " + cls.__name__ + " matching regex pattern " + pattern)
errors = class_instance.get_file_type_error(filename)
if errors is None:
Expand Down
21 changes: 19 additions & 2 deletions cis/test/unit/test_overide_product.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from nose.tools import istest, eq_
from nose.tools import istest, eq_, raises
from cis.data_io.products.caliop import Caliop_L2

from cis.exceptions import ClassNotFoundError
from cis.data_io.products.AProduct import __get_class
from cis.parse import parse_args

Expand All @@ -24,3 +24,20 @@ def should_raise_error_with_unknown_product_specified():
except SystemExit as e:
if e.code != 2:
raise e


@istest
@raises(ClassNotFoundError)
def files_which_match_some_of_regexp_but_not_the_end_shouldnt_match():
"""
Because we're using re.match the regular expression has to match the start - but not necassarily the end. This
test ensures that we have taken care of that as often the extension is the most important part.
"""
import cis.plugin as plugin
from cis.data_io.products.AProduct import AProduct
# We have to patch all of the plugin classes because get_file_type_error gets called and this file doesn't exist
# we are only testing the wildcard matching logic.
product_classes = plugin.find_plugin_classes(AProduct, 'cis.data_io.products')
for p in product_classes:
p.get_file_type_error = lambda self, f: None
_ = __get_class(example_caliop_l2_filename+".ext")
3 changes: 2 additions & 1 deletion doc/whats_new_1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ CIS 1.4 features
Bugs fixed
==========

* [JASCIS-34] MODIS L3 data is now correctly treated as gridded data.
* [JASCIS-34] MODIS L3 data is now correctly treated as gridded data.
* [JASCIS-345] Product regular expression matching now matches the whole string rather than just the start.

0 comments on commit 348ed36

Please sign in to comment.