1
0
mirror of https://github.com/chubin/cheat.sh.git synced 2026-06-20 13:16:44 +02:00

Merge pull request #314 from chubin/fix-tests

Add test for section splitting
This commit is contained in:
Anatoli Babenia
2021-10-22 13:41:21 +03:00
committed by GitHub
4 changed files with 40 additions and 11 deletions
+3 -1
View File
@@ -17,8 +17,10 @@ jobs:
run: pip install --upgrade -r requirements.txt
- name: fetch upstream cheat sheets
run: python lib/fetch.py fetch-all
- name: run tests
- name: run bash tests
run: bash tests/run-tests.sh
- name: run pytest
run: pytest lib/
docker:
runs-on: ubuntu-20.04
+11 -10
View File
@@ -19,6 +19,17 @@ import postprocessing
import frontend.html
import frontend.ansi
def _add_section_name(query):
# temporary solution before we don't find a fixed one
if ' ' not in query and '+' not in query:
return query
if '/' in query:
return query
if ' ' in query:
# for standalone queries only that may contain ' '
return "%s/%s" % tuple(query.split(' ', 1))
return "%s/%s" % tuple(query.split('+', 1))
def cheat_wrapper(query, request_options=None, output_format='ansi'):
"""
Function that delivers cheat sheet for `query`.
@@ -26,16 +37,6 @@ def cheat_wrapper(query, request_options=None, output_format='ansi'):
Additional request options specified in `request_options`.
"""
def _add_section_name(query):
# temporary solution before we don't find a fixed one
if ' ' not in query and '+' not in query:
return query
if '/' in query:
return query
if ' ' in query:
# for standalone queries only that may contain ' '
return "%s/%s" % tuple(query.split(' ', 1))
return "%s/%s" % tuple(query.split('+', 1))
def _rewrite_aliases(word):
if word == ':bash.completion':
+25
View File
@@ -0,0 +1,25 @@
from cheat_wrapper import _add_section_name
unchanged = """
python/:list
ls
btrfs~volume
:intro
:cht.sh
python/copy+file
python/rosetta/:list
emacs:go-mode/:list
"""
split = """
python copy file
python/copy file
"""
def test_header_split():
for inp in unchanged.strip().splitlines():
assert inp == _add_section_name(inp)
for test in split.strip().split('\n\n'):
inp, outp = test.split('\n')
assert outp == _add_section_name(inp)
+1
View File
@@ -15,3 +15,4 @@ pycld2
colorama
pyyaml
python-Levenshtein
pytest