Skip to content

Commit

Permalink
Enable coverage through UnitTesting (#843)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rwols authored Dec 29, 2019
1 parent 3c0c15f commit da0745d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
7 changes: 2 additions & 5 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
[run]
source = .
omit =
*test_*
omit = /*/tests/*

[report]
omit =
*test_*
ignore_errors = True
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
19 changes: 16 additions & 3 deletions tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion tests/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit da0745d

Please sign in to comment.