From 5365985ead900a6b427d313f2eef26cfca85189e Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 12 Apr 2020 17:42:12 +0200 Subject: [PATCH] Test pull request Pull request used to test the action. --- Makefile | 3 +- tests/test_entrypoint.py | 159 --------------------------------------- 2 files changed, 2 insertions(+), 160 deletions(-) diff --git a/Makefile b/Makefile index bfc378e..204d48f 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,8 @@ lint/flake8: virtualenv lint/black: virtualenv $(BLACK) --check $(SOURCES) -lint: lint/isort lint/flake8 lint/black +lint: # lint/isort lint/flake8 lint/black + echo pass format/isort: virtualenv $(ISORT) $(SOURCES) diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index 7142628..8887466 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -70,165 +70,6 @@ def test_main_base_path(self): mock.call("TOKEN", False, None, "SRC") ] - def test_main_parallel_finished(self): - argv = ["src/entrypoint.py", "--github-token", "TOKEN", "--parallel-finished"] - with patch_sys_argv(argv), mock.patch( - "entrypoint.post_webhook" - ) as m_post_webhook: - entrypoint.main() - assert m_post_webhook.call_args_list == [mock.call("TOKEN")] - - def test_try_main(self): - with mock.patch( - "entrypoint.main", side_effect=Exception - ) as m_main, pytest.raises(SystemExit, match=f"{entrypoint.ExitCode.FAILURE}"): - entrypoint.try_main() - assert m_main.call_args_list == [mock.call()] - - def test_run_coveralls_github_token(self): - """Simple case when Coveralls.wear() returns some results.""" - token = "TOKEN" - url = "https://coveralls.io/jobs/1234" - json_response = { - "message": "Job ##12.34", - "url": url, - } - with patch_requests_post( - json_response=json_response - ) as m_post, patch_log() as m_log: - entrypoint.run_coveralls(repo_token=token) - assert m_post.call_args_list == [ - mock.call( - "https://coveralls.io/api/v1/jobs", - files={"json_file": mock.ANY}, - verify=True, - ) - ] - json_file = json.loads(m_post.call_args_list[0][1]["files"]["json_file"]) - assert json_file["repo_token"] == token - assert m_log.method_calls == [ - mock.call.info("Trying submitting coverage with service_name: github..."), - mock.call.info("cd ."), - mock.call.info(mock.ANY), - mock.call.debug(json_response), - mock.call.info(url), - ] - - def test_run_coveralls_parallel(self): - """Makes sure the `parallel` parameter is being handled correctly.""" - token = "TOKEN" - url = "https://coveralls.io/jobs/1234" - json_response = { - "message": "Job ##12.34", - "url": url, - } - parallel = True - with patch_requests_post( - json_response=json_response - ) as m_post, patch_log() as m_log: - entrypoint.run_coveralls(repo_token=token, parallel=parallel) - assert m_post.call_count == 1 - json_file = json.loads(m_post.call_args_list[0][1]["files"]["json_file"]) - assert json_file["parallel"] == parallel - assert m_log.method_calls == [ - mock.call.info("Trying submitting coverage with service_name: github..."), - mock.call.info("cd ."), - mock.call.info(mock.ANY), - mock.call.debug(json_response), - mock.call.info(url), - ] - parallel = False - with patch_requests_post( - json_response=json_response - ) as m_post, patch_log() as m_log: - entrypoint.run_coveralls(repo_token=token, parallel=parallel) - assert m_post.call_count == 1 - json_file = json.loads(m_post.call_args_list[0][1]["files"]["json_file"]) - assert "parallel" not in json_file - assert m_log.method_calls == [ - mock.call.info("Trying submitting coverage with service_name: github..."), - mock.call.info("cd ."), - mock.call.info(mock.ANY), - mock.call.debug(json_response), - mock.call.info(url), - ] - - def test_run_coveralls_flag_name(self): - """Makes sure the `flag_name` parameter is being handled correctly.""" - token = "TOKEN" - url = "https://coveralls.io/jobs/1234" - json_response = { - "message": "Job ##12.34", - "url": url, - } - flag_name = "Unit" - with patch_requests_post( - json_response=json_response - ) as m_post, patch_log() as m_log: - entrypoint.run_coveralls(repo_token=token, flag_name=flag_name) - assert m_post.call_count == 1 - json_file = json.loads(m_post.call_args_list[0][1]["files"]["json_file"]) - assert json_file["flag_name"] == flag_name - assert m_log.method_calls == [ - mock.call.info("Trying submitting coverage with service_name: github..."), - mock.call.info("cd ."), - mock.call.info(mock.ANY), - mock.call.debug(json_response), - mock.call.info(url), - ] - - @pytest.mark.parametrize("flag_name", (None, "")) - def test_run_coveralls_no_flag_name(self, flag_name): - """Note `flag_name` set `None` or empty string should behave the same.""" - token = "TOKEN" - url = "https://coveralls.io/jobs/1234" - json_response = { - "message": "Job ##12.34", - "url": url, - } - with patch_requests_post( - json_response=json_response - ) as m_post, patch_log() as m_log: - entrypoint.run_coveralls(repo_token=token, flag_name=flag_name) - assert m_post.call_count == 1 - json_file = json.loads(m_post.call_args_list[0][1]["files"]["json_file"]) - assert "flag_name" not in json_file - assert m_log.method_calls == [ - mock.call.info("Trying submitting coverage with service_name: github..."), - mock.call.info("cd ."), - mock.call.info(mock.ANY), - mock.call.debug(json_response), - mock.call.info(url), - ] - - def test_run_coveralls_wear_error_once(self): - """On Coveralls.wear() error we should try another `service_name`.""" - url = "https://coveralls.io/jobs/1234" - side_effect = ( - CoverallsException("Error"), - {"message": "Job ##12.34", "url": url}, - ) - with patch_coveralls_wear() as m_wear, patch_log() as m_log: - m_wear.side_effect = side_effect - entrypoint.run_coveralls(repo_token="TOKEN") - assert m_wear.call_args_list == [mock.call(), mock.call()] - assert m_log.method_calls == [ - mock.call.info("Trying submitting coverage with service_name: github..."), - mock.call.info("cd ."), - mock.call.warning( - "Failed submitting coverage with service_name: github", - exc_info=side_effect[0], - ), - mock.call.info(mock.ANY), - mock.call.info( - "Trying submitting coverage with service_name: github-actions..." - ), - mock.call.info("cd ."), - mock.call.info(mock.ANY), - mock.call.debug(side_effect[1]), - mock.call.info(url), - ] - def test_run_coveralls_wear_error_twice(self): """Exits with error code if Coveralls.wear() fails twice.""" side_effect = (