Skip to content

Commit 8c36e09

Browse files
committed
Only test if test samples found
1 parent e4b6fc3 commit 8c36e09

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

clearpath_generator_common/test/generate_samples.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,26 @@ def error_log(name: str, sample: str, error: Exception) -> str:
138138
return f'{name} failed for sample "{sample}" with error: \n{error}'
139139

140140

141-
def generate_test_samples(root_dir: str):
142-
"""Generate all files from common generator."""
143-
# Iterate through all samples in clearpath_config
141+
def get_test_samples():
142+
"""Return all test samples from Clearpath Config package."""
143+
samples = []
144144
share_dir = get_package_share_directory('clearpath_config')
145145
sample_dir = os.path.join(share_dir, 'sample')
146-
sample_errors = []
147146
for sample in os.listdir(sample_dir):
148147
# Filter for Test Samples
149148
if 'test' not in sample:
150149
continue
150+
samples.append(samples)
151+
return samples
152+
153+
154+
def generate_test_samples(root_dir: str):
155+
"""Generate all files from common generator."""
156+
# Iterate through all samples in clearpath_config
157+
share_dir = get_package_share_directory('clearpath_config')
158+
sample_dir = os.path.join(share_dir, 'sample')
159+
sample_errors = []
160+
for sample in get_test_samples():
151161
print(f'Generating {sample}'.center(100, '-'))
152162
# Create Clearpath Directory
153163
src = os.path.join(sample_dir, sample)

clearpath_generator_common/test/test_samples.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ament_index_python.packages import get_package_share_directory
1010

11-
from .generate_samples import generate_test_samples
11+
from .generate_samples import generate_test_samples, get_test_samples
1212

1313

1414
class MissingSampleException(Exception):
@@ -55,6 +55,7 @@ class TestSamples:
5555
os.path.join(installed_sample_dir, sample, 'robot.yaml'))))
5656
break
5757
installed_sample_dir = real_installed_sample_dir
58+
found_samples = len(get_test_samples()) > 0
5859

5960
def filter_lines(self, lines: List[str], filepath: str) -> str:
6061
"""Filter line files to prevent comparing lines that are expected to be different."""
@@ -137,6 +138,8 @@ def test_generate_samples(self):
137138

138139
def test_number_of_samples_match(self):
139140
"""Validate number of samples matches."""
141+
if not self.found_samples:
142+
return
140143
errors = self.diff_dir_trees(
141144
self.new_sample_dir,
142145
self.installed_sample_dir,
@@ -151,6 +154,8 @@ def test_number_of_samples_match(self):
151154

152155
def test_samples_match(self):
153156
"""Validate contents of generated sample directory match."""
157+
if not self.found_samples:
158+
return
154159
dirs_cmp = filecmp.dircmp(
155160
self.new_sample_dir,
156161
self.installed_sample_dir

0 commit comments

Comments
 (0)