Skip to content

Commit c4c4d9c

Browse files
author
DeathAxe
committed
Tests: Add folding unit and integration tests
requires: "Unittesting" package Add a first `DeferrableTestCase` which can interact with ST to simulate normal user interaction. It enables all kinds of real world tests with regards to how MarkdownEditing's commands behave in certain situations. Using a hidden output panel to perform all kinds of text manipulation, which keeps ST free from flickering and causes tests to run smoothly. Note: Can't use pytest any longer as it would try to load new test file and fail due to missing sublime API.
1 parent df93b44 commit c4c4d9c

File tree

7 files changed

+435
-13
lines changed

7 files changed

+435
-13
lines changed

.github/workflows/ci.yml

+28-10
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ on:
1818
workflow_dispatch:
1919

2020
jobs:
21-
build:
22-
name: Python ${{ matrix.python }} on ${{ matrix.os }} ${{ matrix.arch }}
23-
runs-on: ${{ matrix.os }}
21+
lint:
22+
name: Lint code via python ${{ matrix.python }} on ${{ matrix.os }} ${{ matrix.arch }}
23+
runs-on: ubuntu-18.04
2424
strategy:
2525
matrix:
26-
os:
27-
- ubuntu-18.04
2826
python:
2927
- '3.3'
3028
- '3.8'
@@ -38,12 +36,32 @@ jobs:
3836
with:
3937
python-version: ${{ matrix.python }}
4038
architecture: ${{ matrix.arch }}
41-
- name: Install test suites
39+
- name: Install linters
4240
run: pip install -r tests/requirements.txt
43-
- name: Run flake8
44-
run: python -m flake8
45-
- name: Run pytest
46-
run: python -m pytest --import-mode=append tests/
4741
- name: Run black
4842
run: python -m black --check .
4943
if: ${{ matrix.python == '3.8' }}
44+
- name: Run flake8
45+
run: python -m flake8
46+
47+
test:
48+
name: Run tests on (ST${{ matrix.st_version }})
49+
runs-on: ubuntu-latest
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
st_version: [3, 4]
54+
container:
55+
image: sublimetext/unittesting
56+
options: --cap-add=NET_ADMIN
57+
env:
58+
SUBLIME_TEXT_VERSION: ${{ matrix.st_version }}
59+
steps:
60+
- uses: actions/checkout@v1
61+
- run: sh -e /etc/init.d/xvfb start
62+
- run: curl -OL https://raw.githubusercontent.com/SublimeText/UnitTesting/master/sbin/github.sh
63+
- run: |
64+
PATH="$HOME/.local/bin:$PATH"
65+
sh github.sh bootstrap
66+
sh github.sh install_package_control
67+
sh github.sh run_tests

make.cmd

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ goto :usage
4141
call :venv
4242
black --check .
4343
flake8
44-
pytest --import-mode=append tests/
4544
goto :eof
4645

4746
:VENV

tests/__init__.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import sublime
2+
3+
from textwrap import dedent
4+
from unittesting import DeferrableTestCase
5+
6+
7+
class DereferrablePanelTestCase(DeferrableTestCase):
8+
9+
@classmethod
10+
def setUpClass(cls):
11+
"""
12+
Set up global test environment once for all tests owned by this class.
13+
"""
14+
cls.window = sublime.active_window()
15+
cls.view = cls.window.create_output_panel("MarkdownUnitTests", unlisted=True)
16+
settings = cls.view.settings()
17+
settings.set("detect_indentation", False)
18+
settings.set("fold_buttons", False)
19+
settings.set("gutter", False)
20+
settings.set("line_numbers", False)
21+
settings.set("scroll_past_end", False)
22+
settings.set("syntax", "Packages/MarkdownEditing/syntaxes/Markdown.sublime-syntax")
23+
settings.set("word_wrap", False)
24+
cls.view = cls.window.create_output_panel("MarkdownUnitTests", unlisted=True)
25+
26+
@classmethod
27+
def tearDownClass(cls):
28+
"""
29+
Teardown global test environment once all tests finished.
30+
"""
31+
cls.view = cls.window.destroy_output_panel("MarkdownUnitTests")
32+
33+
@classmethod
34+
def setCaretTo(cls, pt):
35+
"""
36+
Move caret to given point
37+
38+
:param pt: Text point to move caret to.
39+
"""
40+
cls.view.sel().clear()
41+
cls.view.sel().add(sublime.Region(pt, pt))
42+
43+
@classmethod
44+
def setBlockText(cls, text):
45+
"""
46+
Replace everything with given block text
47+
48+
:param text: The triple quoted block text to put into scratch view.
49+
"""
50+
cls.setText(dedent(text.strip()))
51+
52+
@classmethod
53+
def setText(cls, text):
54+
"""
55+
Replace everything with given text
56+
57+
:param text: The text to put into scratch view.
58+
"""
59+
cls.view.run_command("select_all")
60+
cls.view.run_command("right_delete")
61+
cls.view.run_command("insert", {"characters": text})
62+
63+
@classmethod
64+
def getRow(cls, row):
65+
"""
66+
Return row's text content.
67+
68+
:param row: The natural 1-based row number. 1=first row
69+
"""
70+
return cls.view.substr(cls.view.line(cls.textPoint(row, 0)))
71+
72+
@classmethod
73+
def textPoint(cls, row, col):
74+
"""
75+
Return textpoint for given row,col coordinats.
76+
77+
:param row: The natural 1-based row number. 1=first row
78+
:param col: The natural 1-based column number. 1=first column
79+
"""
80+
return cls.view.text_point(row - 1, col - 1)

tests/requirements.txt

-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ mccabe == 0.6.1 ; python_version == '3.3'
22
pycodestyle == 2.3.1 ; python_version == '3.3'
33
pyflakes == 1.6.0 ; python_version == '3.3'
44
flake8 == 3.5.0 ; python_version == '3.3'
5-
pytest == 3.2.5 ; python_version == '3.3'
65
mccabe == 0.6.1 ; python_version == '3.8'
76
pycodestyle == 2.7.0 ; python_version == '3.8'
87
pyflakes == 2.3.1 ; python_version == '3.8'
98
flake8 == 3.9.2 ; python_version == '3.8'
10-
pytest == 6.2.4 ; python_version == '3.8'
119
black == 21.5b1 ; python_version == '3.8'

tests/test_folding.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# 1 Heading
2+
3+
A paragraph with [link](https://foo.bar).
4+
5+
* item 1
6+
* item 2
7+
* item 3
8+
9+
## 1.1 Heading
10+
11+
### 1.1.1 Heading
12+
13+
Simple paragraph.
14+
15+
#### 1.1.1.1 Heading
16+
17+
A paragraph with [link](https://foo.bar).
18+
19+
#### 1.1.1.2 Heading
20+
21+
A paragraph with [^1] footnotes.
22+
23+
[^1]: Footnote
24+
25+
### 1.1.2 Heading
26+
27+
Simple paragraph.
28+
29+
title | description
30+
--- | ---
31+
foo | bar
32+
33+
## [1.3](https://foo.bar) Heading
34+
35+
A paragraph with [link](https://foo.bar).
36+
37+
## 1.3 Heading
38+
39+
Simple paragraph.
40+
41+
# 2 Heading
42+
43+
Simple paragraph.
44+
45+
3 heading
46+
=========
47+
48+
3.1 heading
49+
-----------
50+
51+
Simple paragraph.
52+
53+
3.2 heading
54+
-----------
55+
Simple paragraph.
56+
57+
4 heading
58+
=========
59+
Simple paragraph.

0 commit comments

Comments
 (0)