convert babi into a package
This commit is contained in:
0
tests/features/__init__.py
Normal file
0
tests/features/__init__.py
Normal file
@@ -10,7 +10,8 @@ from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import babi
|
||||
from babi.main import main
|
||||
from babi.main import VERSION_STR
|
||||
from testing.runner import PrintsErrorRunner
|
||||
|
||||
|
||||
@@ -332,7 +333,7 @@ class DeferredRunner:
|
||||
|
||||
def await_exit(self):
|
||||
with self._patch_curses():
|
||||
babi.main(self.command)
|
||||
main(self.command)
|
||||
# we have already exited -- check remaining things
|
||||
# KeyPress with failing condition or error
|
||||
for i in range(self._i, len(self._ops)):
|
||||
@@ -343,7 +344,7 @@ class DeferredRunner:
|
||||
@contextlib.contextmanager
|
||||
def run_fake(*cmd, **kwargs):
|
||||
h = DeferredRunner(cmd, **kwargs)
|
||||
h.await_text(babi.VERSION_STR)
|
||||
h.await_text(VERSION_STR)
|
||||
yield h
|
||||
|
||||
|
||||
@@ -355,7 +356,7 @@ def run_tmux(*args, colors=256, **kwargs):
|
||||
cmd = ('bash', '-c', f'export TERM={term}; exec {quoted}')
|
||||
with PrintsErrorRunner(*cmd, **kwargs) as h, h.on_error():
|
||||
# startup with coverage can be slow
|
||||
h.await_text(babi.VERSION_STR, timeout=2)
|
||||
h.await_text(VERSION_STR, timeout=2)
|
||||
yield h
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import babi
|
||||
from babi.main import VERSION_STR
|
||||
from testing.runner import and_exit
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ def test_window_height_2(run, tmpdir):
|
||||
h.await_text('hello world')
|
||||
|
||||
with h.resize(width=80, height=2):
|
||||
h.await_text_missing(babi.VERSION_STR)
|
||||
h.await_text_missing(VERSION_STR)
|
||||
h.assert_full_contents('hello world\n\n')
|
||||
h.press('^J')
|
||||
h.await_text('unknown key')
|
||||
|
||||
h.await_text(babi.VERSION_STR)
|
||||
h.await_text(VERSION_STR)
|
||||
|
||||
|
||||
def test_window_height_1(run, tmpdir):
|
||||
@@ -31,7 +31,7 @@ def test_window_height_1(run, tmpdir):
|
||||
h.await_text('hello world')
|
||||
|
||||
with h.resize(width=80, height=1):
|
||||
h.await_text_missing(babi.VERSION_STR)
|
||||
h.await_text_missing(VERSION_STR)
|
||||
h.assert_full_contents('hello world\n')
|
||||
h.press('^J')
|
||||
h.await_text('unknown key')
|
||||
@@ -1,7 +1,7 @@
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
import babi
|
||||
from babi.main import VERSION_STR
|
||||
from testing.runner import PrintsErrorRunner
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ def test_suspend(tmpdir):
|
||||
with PrintsErrorRunner('bash', '--norc') as h:
|
||||
cmd = (sys.executable, '-mcoverage', 'run', '-m', 'babi', str(f))
|
||||
h.press_and_enter(' '.join(shlex.quote(part) for part in cmd))
|
||||
h.await_text(babi.VERSION_STR, timeout=2)
|
||||
h.await_text(VERSION_STR, timeout=2)
|
||||
h.await_text('hello')
|
||||
|
||||
h.press('^Z')
|
||||
@@ -33,7 +33,7 @@ def test_suspend_with_resize(tmpdir):
|
||||
with PrintsErrorRunner('bash', '--norc') as h:
|
||||
cmd = (sys.executable, '-mcoverage', 'run', '-m', 'babi', str(f))
|
||||
h.press_and_enter(' '.join(shlex.quote(part) for part in cmd))
|
||||
h.await_text(babi.VERSION_STR, timeout=2)
|
||||
h.await_text(VERSION_STR, timeout=2)
|
||||
h.await_text('hello')
|
||||
|
||||
h.press('^Z')
|
||||
@@ -1,8 +1,8 @@
|
||||
import babi
|
||||
from babi.main import File
|
||||
|
||||
|
||||
def test_position_repr():
|
||||
ret = repr(babi.File('f.txt'))
|
||||
ret = repr(File('f.txt'))
|
||||
assert ret == (
|
||||
'File(\n'
|
||||
" filename='f.txt',\n"
|
||||
|
||||
@@ -2,7 +2,7 @@ import io
|
||||
|
||||
import pytest
|
||||
|
||||
import babi
|
||||
from babi.main import _get_lines
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -17,11 +17,11 @@ import babi
|
||||
)
|
||||
def test_get_lines(s, lines, nl, mixed):
|
||||
# sha256 tested below
|
||||
ret_lines, ret_nl, ret_mixed, _ = babi._get_lines(io.StringIO(s))
|
||||
ret_lines, ret_nl, ret_mixed, _ = _get_lines(io.StringIO(s))
|
||||
assert (ret_lines, ret_nl, ret_mixed) == (lines, nl, mixed)
|
||||
|
||||
|
||||
def test_get_lines_sha256_checksum():
|
||||
ret = babi._get_lines(io.StringIO(''))
|
||||
ret = _get_lines(io.StringIO(''))
|
||||
sha256 = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||||
assert ret == ([''], '\n', False, sha256)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import pytest
|
||||
|
||||
import babi
|
||||
from babi.main import ListSpy
|
||||
|
||||
|
||||
def test_list_spy_repr():
|
||||
assert repr(babi.ListSpy(['a', 'b', 'c'])) == "ListSpy(['a', 'b', 'c'])"
|
||||
assert repr(ListSpy(['a', 'b', 'c'])) == "ListSpy(['a', 'b', 'c'])"
|
||||
|
||||
|
||||
def test_list_spy_item_retrieval():
|
||||
spy = babi.ListSpy(['a', 'b', 'c'])
|
||||
spy = ListSpy(['a', 'b', 'c'])
|
||||
assert spy[1] == 'b'
|
||||
assert spy[-1] == 'c'
|
||||
with pytest.raises(IndexError):
|
||||
@@ -18,7 +18,7 @@ def test_list_spy_item_retrieval():
|
||||
def test_list_spy_del():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
del spy[1]
|
||||
|
||||
assert lst == ['a', 'c']
|
||||
@@ -31,7 +31,7 @@ def test_list_spy_del():
|
||||
def test_list_spy_del_with_negative():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
del spy[-1]
|
||||
|
||||
assert lst == ['a', 'b']
|
||||
@@ -44,7 +44,7 @@ def test_list_spy_del_with_negative():
|
||||
def test_list_spy_insert():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
spy.insert(1, 'q')
|
||||
|
||||
assert lst == ['a', 'q', 'b', 'c']
|
||||
@@ -57,7 +57,7 @@ def test_list_spy_insert():
|
||||
def test_list_spy_insert_with_negative():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
spy.insert(-1, 'q')
|
||||
|
||||
assert lst == ['a', 'b', 'q', 'c']
|
||||
@@ -70,7 +70,7 @@ def test_list_spy_insert_with_negative():
|
||||
def test_list_spy_set_value():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
spy[1] = 'hello'
|
||||
|
||||
assert lst == ['a', 'hello', 'c']
|
||||
@@ -83,7 +83,7 @@ def test_list_spy_set_value():
|
||||
def test_list_spy_multiple_modifications():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
spy[1] = 'hello'
|
||||
spy.insert(1, 'ohai')
|
||||
del spy[0]
|
||||
@@ -96,7 +96,7 @@ def test_list_spy_multiple_modifications():
|
||||
|
||||
|
||||
def test_list_spy_iter():
|
||||
spy = babi.ListSpy(['a', 'b', 'c'])
|
||||
spy = ListSpy(['a', 'b', 'c'])
|
||||
spy_iter = iter(spy)
|
||||
assert next(spy_iter) == 'a'
|
||||
assert next(spy_iter) == 'b'
|
||||
@@ -108,7 +108,7 @@ def test_list_spy_iter():
|
||||
def test_list_spy_append():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
spy.append('q')
|
||||
|
||||
assert lst == ['a', 'b', 'c', 'q']
|
||||
@@ -121,7 +121,7 @@ def test_list_spy_append():
|
||||
def test_list_spy_pop_default():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
spy.pop()
|
||||
|
||||
assert lst == ['a', 'b']
|
||||
@@ -134,7 +134,7 @@ def test_list_spy_pop_default():
|
||||
def test_list_spy_pop_idx():
|
||||
lst = ['a', 'b', 'c']
|
||||
|
||||
spy = babi.ListSpy(lst)
|
||||
spy = ListSpy(lst)
|
||||
spy.pop(1)
|
||||
|
||||
assert lst == ['a', 'c']
|
||||
|
||||
Reference in New Issue
Block a user