Skip to content

Commit

Permalink
fix: incorrect file indexing during split #148
Browse files Browse the repository at this point in the history
When a list item is split the file index should have 5 digits instead of 4 digits.
  • Loading branch information
Lenin Mehedy committed Oct 18, 2020
1 parent bc912ce commit ad7b2e6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/trestle/core/commands/split_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_subsequent_split_model(tmp_dir, sample_target: ostarget.TargetDefinitio
element = Element(metadata2)
parties_dir = target_def_dir / 'metadata/parties'
for i, party in enumerate(element.get_at(element_paths[0])):
prefix = str(i).zfill(4)
prefix = str(i).zfill(const.FILE_DIGIT_PREFIX_LENGTH)
sub_model_actions = SplitCmd.prepare_sub_model_split_actions(party, parties_dir, prefix, content_type)
second_plan.add_actions(sub_model_actions)

Expand Down
4 changes: 2 additions & 2 deletions trestle/core/commands/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def split_model_at_path_chain(
sub_model_items: Dict[str, OscalBaseModel] = {}
if isinstance(sub_models, list):
for i, sub_model_item in enumerate(sub_models):
# e.g. `groups/0000_groups/`
prefix = str(i).zfill(4)
# e.g. `groups/00000_groups/`
prefix = str(i).zfill(const.FILE_DIGIT_PREFIX_LENGTH)
sub_model_items[prefix] = sub_model_item
elif isinstance(sub_models, dict):
# prefix is the key of the dict
Expand Down
3 changes: 3 additions & 0 deletions trestle/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
# Index separater for naming directories representing collection properties
IDX_SEP = '__'

# Digit prefix for split files
FILE_DIGIT_PREFIX_LENGTH = 5

# Wildcard that can be used in the element path to represent all elements
ELEMENT_WILDCARD = '*'
ARG_VALIDATE = 'validate'
Expand Down

0 comments on commit ad7b2e6

Please sign in to comment.