java_gen: support glob based test_data files
enables us to have more than on unit test per class.
Additional tests follow the pattern:
${class_name}__${suffix}.data
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index 9f2bdc9..feb3c72 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -1005,16 +1005,23 @@
self.java_class = java_class
first_data_file_name = "of{version}/{name}.data".format(version=java_class.version.of_version,
name=java_class.c_name[3:])
- data_file_template = "of{version}/{name}.".format(version=java_class.version.of_version,
- name=java_class.c_name[3:]) + "{i}.data"
+ glob_file_name = "of{version}/{name}__*.data".format(version=java_class.version.of_version,
+ name=java_class.c_name[3:])
test_class_name = self.java_class.name + "Test"
self.test_units = []
if test_data.exists(first_data_file_name):
self.test_units.append(JavaUnitTest(java_class, first_data_file_name, test_class_name))
+
i = 1
- while test_data.exists(data_file_template.format(i=i)):
- self.test_units.append(JavaUnitTest(java_class, data_file_template.format(i=i), test_class_name + str(i)))
- i = i + 1
+ for f in test_data.glob(glob_file_name):
+ m = re.match(".*__(.*).data", f)
+ if m:
+ suffix = java_type.name_c_to_caps_camel(m.group(1))
+ else:
+ suffix = str(i)
+ i += 1
+ test_class_name = self.java_class.name + suffix + "Test"
+ self.test_units.append(JavaUnitTest(java_class, f, test_class_name))
@property
def package(self):
diff --git a/test_data/__init__.py b/test_data/__init__.py
index 7a55c11..dc063fa 100644
--- a/test_data/__init__.py
+++ b/test_data/__init__.py
@@ -26,6 +26,7 @@
# EPL for the specific language governing permissions and limitations
# under the EPL.
+import fnmatch
import os
_test_data_dir = os.path.dirname(os.path.realpath(__file__))
@@ -45,6 +46,11 @@
result.append(dirname + '/' + filename)
return sorted(result)
+def glob(pattern):
+ for f in list_files():
+ if fnmatch.fnmatch(f, pattern):
+ yield f
+
def exists(name):
return os.path.exists(os.path.join(_test_data_dir, name))