Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
mzuenni authored and RagnarGrootKoerkamp committed May 18, 2024
1 parent b19ef77 commit 2709bc9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
19 changes: 6 additions & 13 deletions bin/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent, coun

# Used by `fuzz`
self.in_is_generated = False
self.has_count = count_index is not None
self.count_index = count_index if self.has_count else 0
self.count_index = count_index

# used to decide if this was supposed to be a duplicate or not
self.intended_copy = self.count_index > 0
Expand Down Expand Up @@ -510,7 +509,7 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent, coun
# replace count
command_string = yaml['generate']
if '{count}' in command_string:
if self.has_count:
if 'count' in yaml:
command_string = command_string.replace(
'{count}', f'{self.count_index+1}'
)
Expand Down Expand Up @@ -883,6 +882,8 @@ def add_testdata_to_cache():
# Step 1: run `generate:` if present.
if t.generator:
result = t.generator.run(bar, cwd, infile.stem, t.seed, t.config.retries)
if result.err is not None:
bar.debug('generator:', result.err)
if not result.status:
return

Expand Down Expand Up @@ -1434,22 +1435,14 @@ def parse(key, name_gen, yaml, parent):
for count_index in range(count):
if count_index > 0:
name = name_gen()
if count > 1:
if 'count' in yaml:
name += f'-{count_index+1:0{len(str(count))}}'

# If a list of testcases was passed and this one is not in it, skip it.
if not self.process_testcase(parent.path / name):
continue

t = TestcaseRule(
self.problem,
self,
key,
name,
yaml,
parent,
count_index if count > 1 else None,
)
t = TestcaseRule(self.problem, self, key, name, yaml, parent, count_index)
if t.path in self.known_cases:
message(
f'was already parsed. Skipping.',
Expand Down
2 changes: 1 addition & 1 deletion test/problems/identity/generators/generators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ data:
generate: stdout.py 700 {count}
count: 1
- generate:
generate: stdout.py 701
generate: stdout.py 701 {name}
count: 3
- seed:
generate: random_gen.py {seed:9}
Expand Down
2 changes: 2 additions & 0 deletions test/problems/identity/generators/stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
import sys

print(sys.argv[1])
if 2 < len(sys.argv):
print(sys.argv[2], file=sys.stderr)

0 comments on commit 2709bc9

Please sign in to comment.