From da0745dd2b88b9362d69674ffff3b589f0521b4f Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Sun, 29 Dec 2019 14:30:11 +0100 Subject: [PATCH] Enable coverage through UnitTesting (#843) * fixup .coveragerc for UnitTesting * Run coverage along with tests * Run the codecov tool in the ci * Start active views in self.wm in case testfile.txt was already open * Remove print statement * Play around with period and timeout times a bit more * Shut down all sessions cleanly and close all views before starting test --- .coveragerc | 7 ++----- .github/workflows/main.yml | 7 +++++-- README.md | 1 + codecov.yml | 1 + tests/setup.py | 19 ++++++++++++++++--- tests/test_windows.py | 1 - 6 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 codecov.yml diff --git a/.coveragerc b/.coveragerc index f9540c5fe..2192f204c 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,8 +1,5 @@ [run] -source = . -omit = - *test_* +omit = /*/tests/* [report] -omit = - *test_* +ignore_errors = True diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ccc651e1c..850fa8e73 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,10 +21,13 @@ jobs: sh ci.sh bootstrap sh ci.sh install_package_control subl & - sleep 5 - sh ci.sh run_tests + sleep 6 + sh ci.sh run_tests --coverage name: Run UnitTesting tests - run: pip3 install mypy==0.750 flake8==3.7.9 yapf==0.29.0 --user - run: mypy -p plugin - run: flake8 plugin tests - run: yapf --diff plugin/core/main.py + - run: | + pip3 install coverage==4.5.4 codecov==2.0.15 + codecov diff --git a/README.md b/README.md index 0ba854c22..f66ad84b7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![GitHub release](https://img.shields.io/github/release/sublimelsp/LSP.svg)](https://github.com/sublimelsp/LSP/releases) [![Build Status](https://travis-ci.org/sublimelsp/LSP.svg?branch=master)](https://travis-ci.org/sublimelsp/LSP) +![](https://github.com/sublimelsp/LSP/workflows/.github/workflows/main.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/tomv564/LSP/badge.svg?branch=master)](https://coveralls.io/github/tomv564/LSP?branch=master) [![SublimeHQ Discord](https://img.shields.io/discord/280102180189634562?label=SublimeHQ%20Discord&logo=discord&style=flat-square)](#chat) diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..69cb76019 --- /dev/null +++ b/codecov.yml @@ -0,0 +1 @@ +comment: false diff --git a/tests/setup.py b/tests/setup.py index a82982548..6f582e0f7 100644 --- a/tests/setup.py +++ b/tests/setup.py @@ -17,8 +17,8 @@ project_path = dirname(__file__) test_file_path = project_path + "/testfile.txt" workspace_folders = [WorkspaceFolder.from_path(project_path)] -TIMEOUT_TIME = 10000 if CI else 1000 -PERIOD_TIME = 200 if CI else 17 +TIMEOUT_TIME = 16000 if CI else 2000 +PERIOD_TIME = 400 if CI else 1 SUPPORTED_SCOPE = "text.plain" SUPPORTED_SYNTAX = "Packages/Text/Plain text.tmLanguage" text_language = LanguageConfig("text", [SUPPORTED_SCOPE], [SUPPORTED_SYNTAX]) @@ -118,13 +118,26 @@ def setUp(self) -> 'Generator': self.assertTrue(window) filename = expand("$packages/LSP/tests/{}.txt".format(test_name), window) self.config.init_options["serverResponse"] = server_capabilities - windows._windows.clear() # destroy all window managers + window.run_command("close_all") + # Cleanly shut down all window managers by ending all their sessions + for wm in windows._windows.values(): + wm.end_sessions() + + def condition() -> bool: + nonlocal wm + return len(wm._sessions) == 0 + + yield {"condition": condition, "timeout": TIMEOUT_TIME, "period": PERIOD_TIME} + # The Sublime windows are actually still valid, so WindowManagers don't remove themselves from this global + # dictionary. We do it by hand. + windows._windows.clear() client_configs.all.clear() add_config(self.config) self.wm = windows.lookup(window) # create just this single one for the test self.view = window.open_file(filename) self.assertTrue(self.wm._configs.syntax_supported(self.view)) self.init_view_settings() + self.wm.start_active_views() # in case testfile.txt was already opened yield from self.await_boilerplate_begin() def get_test_name(self) -> str: diff --git a/tests/test_windows.py b/tests/test_windows.py index 609d4b325..9209d2b4a 100644 --- a/tests/test_windows.py +++ b/tests/test_windows.py @@ -61,7 +61,6 @@ def test_can_get_window_state(self): def test_removes_window_state(self): test_window = MockWindow([[MockView(__file__)]]) - print(__file__) windows = WindowRegistry(TestGlobalConfigs(), TestDocumentHandlerFactory(), mock_start_session, test_sublime, MockHandlerDispatcher())