From ea4dd3b831b924a024a8420717c267c6b566386d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20R=C3=BCegg?= Date: Tue, 12 May 2020 13:28:53 +0200 Subject: [PATCH 1/3] Reformat tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon Rüegg --- tests/test_target.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/test_target.py b/tests/test_target.py index 736cc5567..a40e5461e 100644 --- a/tests/test_target.py +++ b/tests/test_target.py @@ -23,14 +23,13 @@ def test_render_target(): target = cluster._full_target(cluster_obj, components, catalog) facts = cluster_obj['facts'] assert target != "" - all_classes = ([f"defaults.{cn}" for cn in components] + - ['global.common', - f"global.{facts['distribution']}", - f"global.{facts['cloud']}", - f"{cluster_obj['tenant']}.{cluster_obj['id']}", - ]) - assert len(target['classes']) == len( - all_classes), "rendered target includes different amount of classes" + all_classes = [f"defaults.{cn}" for cn in components] + \ + ['global.common', + f"global.{facts['distribution']}", + f"global.{facts['cloud']}", + f"{cluster_obj['tenant']}.{cluster_obj['id']}"] + assert len(target['classes']) == len(all_classes), \ + "rendered target includes different amount of classes" # Test order of included classes for i in range(len(all_classes)): assert target['classes'][i] == all_classes[i] From 6402c4fad77cf7dde4424aecfac1ba459371511d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20R=C3=BCegg?= Date: Tue, 12 May 2020 15:55:21 +0200 Subject: [PATCH 2/3] Rename variables To not override existing ones. Add test. --- commodore/git.py | 8 ++++---- tests/test_git.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 tests/test_git.py diff --git a/commodore/git.py b/commodore/git.py index 9d39da8d8..d24dd504f 100644 --- a/commodore/git.py +++ b/commodore/git.py @@ -161,10 +161,10 @@ def stage_all(repo): # and a_blob as after. before = c.b_blob.data_stream.read().decode('utf-8').split('\n') after = c.a_blob.data_stream.read().decode('utf-8').split('\n') - diff = difflib.unified_diff(before, after, lineterm='', - fromfile=c.b_path, tofile=c.a_path) - diff = [_colorize_diff(line) for line in diff] - difftext.append('\n'.join(diff).strip()) + diff_lines = difflib.unified_diff(before, after, lineterm='', + fromfile=c.b_path, tofile=c.a_path) + diff_lines = [_colorize_diff(line) for line in diff_lines] + difftext.append('\n'.join(diff_lines).strip()) return '\n'.join(difftext), changed diff --git a/tests/test_git.py b/tests/test_git.py new file mode 100644 index 000000000..136c52cf1 --- /dev/null +++ b/tests/test_git.py @@ -0,0 +1,13 @@ +""" +Unit-tests for git +""" + +import commodore.git as git + + +def test_reconstruct_api_response(tmp_path): + repo_path = tmp_path / 'test-repo' + repo_path.mkdir() + repo = git.create_repository(repo_path) + output = git.stage_all(repo) + assert output != "" From dfd4c01fdf9cc763d90bcf0fe8b7a169e83475f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20R=C3=BCegg?= Date: Tue, 12 May 2020 18:36:46 +0200 Subject: [PATCH 3/3] Implement review findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon Rüegg --- tests/test_git.py | 5 +++-- tests/test_target.py | 13 ++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_git.py b/tests/test_git.py index 136c52cf1..abdd9acc2 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -2,10 +2,11 @@ Unit-tests for git """ -import commodore.git as git +from commodore import git +from pathlib import Path -def test_reconstruct_api_response(tmp_path): +def test_reconstruct_api_response(tmp_path: Path): repo_path = tmp_path / 'test-repo' repo_path.mkdir() repo = git.create_repository(repo_path) diff --git a/tests/test_target.py b/tests/test_target.py index a40e5461e..0a84730bb 100644 --- a/tests/test_target.py +++ b/tests/test_target.py @@ -4,7 +4,7 @@ import click import pytest -import commodore.cluster as cluster +from commodore import cluster cluster_obj = { @@ -22,15 +22,14 @@ def test_render_target(): target = cluster._full_target(cluster_obj, components, catalog) facts = cluster_obj['facts'] + all_classes = [f"defaults.{cn}" for cn in components] + [ + 'global.common', + f"global.{facts['distribution']}", + f"global.{facts['cloud']}", + f"{cluster_obj['tenant']}.{cluster_obj['id']}"] assert target != "" - all_classes = [f"defaults.{cn}" for cn in components] + \ - ['global.common', - f"global.{facts['distribution']}", - f"global.{facts['cloud']}", - f"{cluster_obj['tenant']}.{cluster_obj['id']}"] assert len(target['classes']) == len(all_classes), \ "rendered target includes different amount of classes" - # Test order of included classes for i in range(len(all_classes)): assert target['classes'][i] == all_classes[i] assert target['parameters']['target_name'] == 'cluster'