From d87a6502af92aa8c79da108cdfe79d031736b176 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Fri, 12 Apr 2019 07:48:10 -0500 Subject: [PATCH] Factor out some branches in utils:create_alt_files() --- test/utils.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/test/utils.py b/test/utils.py index 577281c..0b52b37 100644 --- a/test/utils.py +++ b/test/utils.py @@ -64,24 +64,29 @@ def create_alt_files(paths, suffix, test_path.write('\n' + content, mode='a', ensure=True) assert test_path.exists() - create_includefiles(includefile, paths, test_paths) - - if tracked: - for track_path in test_paths: - os.system(f'GIT_DIR={str(paths.repo)} git add "{track_path}"') - os.system(f'GIT_DIR={str(paths.repo)} git commit -m "Add test files"') - - if encrypt: - for encrypt_name in test_names: - paths.encrypt.write(f'{encrypt_name + suffix}\n', mode='a') - if exclude: - paths.encrypt.write(f'!{encrypt_name + suffix}\n', mode='a') + _create_includefiles(includefile, paths, test_paths) + _create_tracked(tracked, test_paths, paths) + _create_encrypt(encrypt, test_names, suffix, paths, exclude) -def create_includefiles(includefile, paths, test_paths): - """Generate files for testing jinja includes""" +def _create_includefiles(includefile, paths, test_paths): if includefile: for dpath in INCLUDE_DIRS: incfile = paths.work.join(dpath + '/' + INCLUDE_FILE) incfile.write(INCLUDE_CONTENT, ensure=True) test_paths += [incfile] + + +def _create_tracked(tracked, test_paths, paths): + if tracked: + for track_path in test_paths: + os.system(f'GIT_DIR={str(paths.repo)} git add "{track_path}"') + os.system(f'GIT_DIR={str(paths.repo)} git commit -m "Add test files"') + + +def _create_encrypt(encrypt, test_names, suffix, paths, exclude): + if encrypt: + for encrypt_name in test_names: + paths.encrypt.write(f'{encrypt_name + suffix}\n', mode='a') + if exclude: + paths.encrypt.write(f'!{encrypt_name + suffix}\n', mode='a')