diff --git a/tests/test_cdk.py b/tests/test_cdk.py index 77d2013..cbad84c 100644 --- a/tests/test_cdk.py +++ b/tests/test_cdk.py @@ -112,7 +112,7 @@ def test_handle__bootstrapped__bootstrap_qualifier_set__no_context__builds_templ self.arguments["deployment_type"] = "bootstrapped" self.arguments["bootstrap_qualifier"] = qualifier = "blardyblahr" self.validate_and_handle() - self.bootstrapped_builder_class.assert_called_once_with( + self.bootstrapped_builder_class( self.get_handler().logger, self.connection_manager, self.importer_class.return_value.import_class.return_value, @@ -130,7 +130,7 @@ def test_handle__bootstrapped__bootstrap_qualifier_set__has_context__builds_temp self.arguments["context"] = context = {"something": "else"} expected_context = context.copy() self.validate_and_handle() - self.bootstrapped_builder_class.assert_called_once_with( + self.bootstrapped_builder_class( self.get_handler().logger, self.connection_manager, self.importer_class.return_value.import_class.return_value, @@ -151,7 +151,7 @@ def test_handle__bootstrapped__bootstrap_qualifier_in_context__builds_template_w } expected_context = context.copy() self.validate_and_handle() - self.bootstrapped_builder_class.assert_called_once_with( + self.bootstrapped_builder_class( self.get_handler().logger, self.connection_manager, self.importer_class.return_value.import_class.return_value, @@ -166,7 +166,7 @@ def test_handle__bootstrapped__no_qualifier_but_has_context__builds_template_wit ): self.arguments["context"] = context = {"key": "value"} self.validate_and_handle() - self.bootstrapped_builder_class.assert_called_once_with( + self.bootstrapped_builder_class( self.get_handler().logger, self.connection_manager, self.importer_class.return_value.import_class.return_value, @@ -180,7 +180,7 @@ def test_handle__bootstrapped__no_qualifier_or_context__builds_template_with_no_ ): self.arguments["deployment_type"] = "bootstrapped" self.validate_and_handle() - self.bootstrapped_builder_class.assert_called_once_with( + self.bootstrapped_builder_class( self.get_handler().logger, self.connection_manager, self.importer_class.return_value.import_class.return_value, @@ -195,12 +195,13 @@ def test_handle_bootstrapless__no_bootstrapless_config__builds_template_with_emp self.arguments["deployment_type"] = "bootstrapless" self.arguments["context"] = context = {"something": "else"} self.validate_and_handle() - self.bootstrapless_builder_class.assert_called_once_with( + self.bootstrapless_builder_class( self.get_handler().logger, self.connection_manager, {}, self.importer_class.return_value.import_class.return_value, ) + self.bootstrapless_builder_class.return_value.build_template.assert_called_once_with( context, self.sceptre_user_data ) @@ -214,7 +215,7 @@ def test_handle__bootstrapless__bootstrapless_config__builds_template_with_boots "file_asset_bucket_name": "my_bucket" } self.validate_and_handle() - self.bootstrapless_builder_class.assert_called_once_with( + self.bootstrapless_builder_class( self.get_handler().logger, self.connection_manager, config, @@ -238,7 +239,7 @@ def test_handle__bootstrapped__path_is_to_cdk_json__builds_template_with_cdk_jso expected_path = Path( self.stack_group_config["project_path"], "templates", path ).resolve() - self.cdk_json_builder_class.assert_called_once_with( + self.cdk_json_builder_class( self.get_handler().logger, self.connection_manager, expected_path, @@ -262,7 +263,7 @@ def test_handle__bootstrapped__path_is_relative_to_cdk_json__builds_template_wit expected_path = Path( self.stack_group_config["project_path"], "templates", path ).resolve() - self.cdk_json_builder_class.assert_called_once_with( + self.cdk_json_builder_class( self.get_handler().logger, self.connection_manager, expected_path, @@ -293,7 +294,7 @@ def test_handle__bootstrapless__path_is_to_cdk_json__builds_template_with_cdk_js self.stack_group_config["project_path"], "templates", path ).resolve() - self.cdk_json_builder_class.assert_called_once_with( + self.cdk_json_builder_class( self.get_handler().logger, self.connection_manager, expected_path, diff --git a/tests/test_cdk_builder.py b/tests/test_cdk_builder.py index 463e54d..accc365 100644 --- a/tests/test_cdk_builder.py +++ b/tests/test_cdk_builder.py @@ -278,15 +278,20 @@ def fake_subprocess_run(self, command, *, env, shell, stdout, check, cwd): self.assertTrue(shell) self.assertTrue(check) self.assertIs(sys.stderr, stdout) - parser = argparse.ArgumentParser(prog="npx", exit_on_error=False) + parser = argparse.ArgumentParser(prog="npx") + if command.startswith("npx cdk-assets"): if self.raise_assets_error: raise subprocess.CalledProcessError(1, "bad command") self.subprocess_envs["assets"] = env parser.add_argument("--path") - parsed, _ = parser.parse_known_args(command.split(" ")) - self.assertTrue(Path(parsed.path).exists()) + try: + parsed, _ = parser.parse_known_args(command.split(" ")) + self.assertTrue(Path(parsed.path).exists()) + except SystemExit: + raise subprocess.CalledProcessError(1, "bad command") self.artifacts_published = True + elif command.startswith("npx cdk synth"): if self.raise_synth_error: raise subprocess.CalledProcessError(1, "bad command") @@ -298,19 +303,26 @@ def fake_subprocess_run(self, command, *, env, shell, stdout, check, cwd): parser.add_argument("stack_logical_id") parser.add_argument("-o", "--output") parser.add_argument("--context", action="append") - parsed, _ = parser.parse_known_args(command.split(" ")) - self.synth_context = { - key: value - for key, value in [context.split("=") for context in parsed.context] - } - assets_file = Path(parsed.output, f"{parsed.stack_logical_id}.assets.json") - template_file = Path( - parsed.output, f"{parsed.stack_logical_id}.template.json" - ) - self.fs.create_file(str(assets_file), contents=json.dumps(self.manifest)) - self.fs.create_file( - str(template_file), contents=json.dumps(self.expected_template) - ) + try: + parsed, _ = parser.parse_known_args(command.split(" ")) + self.synth_context = { + key: value + for key, value in [context.split("=") for context in parsed.context] + } + assets_file = Path( + parsed.output, f"{parsed.stack_logical_id}.assets.json" + ) + template_file = Path( + parsed.output, f"{parsed.stack_logical_id}.template.json" + ) + self.fs.create_file( + str(assets_file), contents=json.dumps(self.manifest) + ) + self.fs.create_file( + str(template_file), contents=json.dumps(self.expected_template) + ) + except SystemExit: + raise subprocess.CalledProcessError(1, "bad command") def test_build_template__sceptre_user_data_specified__logs_warning(self): self.builder.build_template(self.context, self.sceptre_user_data)