Skip to content

Commit 609c790

Browse files
authored
Merge pull request chubin#314 from chubin/fix-tests
Add test for section splitting
2 parents 5a79c76 + 3d1e4ec commit 609c790

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

.github/workflows/tests-ubuntu.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ jobs:
1717
run: pip install --upgrade -r requirements.txt
1818
- name: fetch upstream cheat sheets
1919
run: python lib/fetch.py fetch-all
20-
- name: run tests
20+
- name: run bash tests
2121
run: bash tests/run-tests.sh
22+
- name: run pytest
23+
run: pytest lib/
2224

2325
docker:
2426
runs-on: ubuntu-20.04

lib/cheat_wrapper.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@
1919
import frontend.html
2020
import frontend.ansi
2121

22+
def _add_section_name(query):
23+
# temporary solution before we don't find a fixed one
24+
if ' ' not in query and '+' not in query:
25+
return query
26+
if '/' in query:
27+
return query
28+
if ' ' in query:
29+
# for standalone queries only that may contain ' '
30+
return "%s/%s" % tuple(query.split(' ', 1))
31+
return "%s/%s" % tuple(query.split('+', 1))
32+
2233
def cheat_wrapper(query, request_options=None, output_format='ansi'):
2334
"""
2435
Function that delivers cheat sheet for `query`.
2536
If `html` is True, the answer is formatted as HTML.
2637
Additional request options specified in `request_options`.
2738
"""
2839

29-
def _add_section_name(query):
30-
# temporary solution before we don't find a fixed one
31-
if ' ' not in query and '+' not in query:
32-
return query
33-
if '/' in query:
34-
return query
35-
if ' ' in query:
36-
# for standalone queries only that may contain ' '
37-
return "%s/%s" % tuple(query.split(' ', 1))
38-
return "%s/%s" % tuple(query.split('+', 1))
3940

4041
def _rewrite_aliases(word):
4142
if word == ':bash.completion':

lib/cheat_wrapper_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from cheat_wrapper import _add_section_name
2+
3+
unchanged = """
4+
python/:list
5+
ls
6+
btrfs~volume
7+
:intro
8+
:cht.sh
9+
python/copy+file
10+
python/rosetta/:list
11+
emacs:go-mode/:list
12+
"""
13+
14+
split = """
15+
python copy file
16+
python/copy file
17+
"""
18+
19+
def test_header_split():
20+
for inp in unchanged.strip().splitlines():
21+
assert inp == _add_section_name(inp)
22+
23+
for test in split.strip().split('\n\n'):
24+
inp, outp = test.split('\n')
25+
assert outp == _add_section_name(inp)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ pycld2
1515
colorama
1616
pyyaml
1717
python-Levenshtein
18+
pytest

0 commit comments

Comments
 (0)