From b7700b8588f368a8879190ba4ac67828d9fdef47 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 22 Feb 2020 12:14:48 -0800 Subject: [PATCH] convert babi into a package --- babi/__init__.py | 0 babi/__main__.py | 4 +++ babi.py => babi/main.py | 0 setup.cfg | 9 +++++-- tests/features/__init__.py | 0 tests/{ => features}/command_mode_test.py | 0 tests/{ => features}/conftest.py | 9 ++++--- tests/{ => features}/current_position_test.py | 0 tests/{ => features}/cut_uncut_test.py | 0 tests/{ => features}/go_to_line_test.py | 0 tests/{ => features}/indent_test.py | 0 tests/{ => features}/movement_test.py | 0 tests/{ => features}/multiple_files_test.py | 0 tests/{ => features}/perf_log_test.py | 0 tests/{ => features}/replace_test.py | 0 tests/{ => features}/resize_test.py | 8 +++--- tests/{ => features}/save_test.py | 0 tests/{ => features}/search_test.py | 0 tests/{ => features}/sort_test.py | 0 tests/{ => features}/status_test.py | 0 tests/{ => features}/suspend_test.py | 6 ++--- tests/{ => features}/text_editing_test.py | 0 tests/{ => features}/undo_redo_test.py | 0 tests/file_test.py | 4 +-- tests/get_lines_test.py | 6 ++--- tests/list_spy_test.py | 26 +++++++++---------- 26 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 babi/__init__.py create mode 100644 babi/__main__.py rename babi.py => babi/main.py (100%) create mode 100644 tests/features/__init__.py rename tests/{ => features}/command_mode_test.py (100%) rename tests/{ => features}/conftest.py (98%) rename tests/{ => features}/current_position_test.py (100%) rename tests/{ => features}/cut_uncut_test.py (100%) rename tests/{ => features}/go_to_line_test.py (100%) rename tests/{ => features}/indent_test.py (100%) rename tests/{ => features}/movement_test.py (100%) rename tests/{ => features}/multiple_files_test.py (100%) rename tests/{ => features}/perf_log_test.py (100%) rename tests/{ => features}/replace_test.py (100%) rename tests/{ => features}/resize_test.py (96%) rename tests/{ => features}/save_test.py (100%) rename tests/{ => features}/search_test.py (100%) rename tests/{ => features}/sort_test.py (100%) rename tests/{ => features}/status_test.py (100%) rename tests/{ => features}/suspend_test.py (90%) rename tests/{ => features}/text_editing_test.py (100%) rename tests/{ => features}/undo_redo_test.py (100%) diff --git a/babi/__init__.py b/babi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/babi/__main__.py b/babi/__main__.py new file mode 100644 index 0000000..056a5f3 --- /dev/null +++ b/babi/__main__.py @@ -0,0 +1,4 @@ +from babi.main import main + +if __name__ == '__main__': + exit(main()) diff --git a/babi.py b/babi/main.py similarity index 100% rename from babi.py rename to babi/main.py diff --git a/setup.cfg b/setup.cfg index 022fc36..07f0341 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,12 +20,17 @@ classifiers = Programming Language :: Python :: Implementation :: PyPy [options] -py_modules = babi +packages = find: python_requires = >=3.6 [options.entry_points] console_scripts = - babi = babi:main + babi = babi.main:main + +[options.packages.find] +exclude = + tests* + testing* [bdist_wheel] universal = True diff --git a/tests/features/__init__.py b/tests/features/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/command_mode_test.py b/tests/features/command_mode_test.py similarity index 100% rename from tests/command_mode_test.py rename to tests/features/command_mode_test.py diff --git a/tests/conftest.py b/tests/features/conftest.py similarity index 98% rename from tests/conftest.py rename to tests/features/conftest.py index 02baaf2..291a3e8 100644 --- a/tests/conftest.py +++ b/tests/features/conftest.py @@ -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 diff --git a/tests/current_position_test.py b/tests/features/current_position_test.py similarity index 100% rename from tests/current_position_test.py rename to tests/features/current_position_test.py diff --git a/tests/cut_uncut_test.py b/tests/features/cut_uncut_test.py similarity index 100% rename from tests/cut_uncut_test.py rename to tests/features/cut_uncut_test.py diff --git a/tests/go_to_line_test.py b/tests/features/go_to_line_test.py similarity index 100% rename from tests/go_to_line_test.py rename to tests/features/go_to_line_test.py diff --git a/tests/indent_test.py b/tests/features/indent_test.py similarity index 100% rename from tests/indent_test.py rename to tests/features/indent_test.py diff --git a/tests/movement_test.py b/tests/features/movement_test.py similarity index 100% rename from tests/movement_test.py rename to tests/features/movement_test.py diff --git a/tests/multiple_files_test.py b/tests/features/multiple_files_test.py similarity index 100% rename from tests/multiple_files_test.py rename to tests/features/multiple_files_test.py diff --git a/tests/perf_log_test.py b/tests/features/perf_log_test.py similarity index 100% rename from tests/perf_log_test.py rename to tests/features/perf_log_test.py diff --git a/tests/replace_test.py b/tests/features/replace_test.py similarity index 100% rename from tests/replace_test.py rename to tests/features/replace_test.py diff --git a/tests/resize_test.py b/tests/features/resize_test.py similarity index 96% rename from tests/resize_test.py rename to tests/features/resize_test.py index a11a2aa..41510a4 100644 --- a/tests/resize_test.py +++ b/tests/features/resize_test.py @@ -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') diff --git a/tests/save_test.py b/tests/features/save_test.py similarity index 100% rename from tests/save_test.py rename to tests/features/save_test.py diff --git a/tests/search_test.py b/tests/features/search_test.py similarity index 100% rename from tests/search_test.py rename to tests/features/search_test.py diff --git a/tests/sort_test.py b/tests/features/sort_test.py similarity index 100% rename from tests/sort_test.py rename to tests/features/sort_test.py diff --git a/tests/status_test.py b/tests/features/status_test.py similarity index 100% rename from tests/status_test.py rename to tests/features/status_test.py diff --git a/tests/suspend_test.py b/tests/features/suspend_test.py similarity index 90% rename from tests/suspend_test.py rename to tests/features/suspend_test.py index a5f9387..f245aa8 100644 --- a/tests/suspend_test.py +++ b/tests/features/suspend_test.py @@ -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') diff --git a/tests/text_editing_test.py b/tests/features/text_editing_test.py similarity index 100% rename from tests/text_editing_test.py rename to tests/features/text_editing_test.py diff --git a/tests/undo_redo_test.py b/tests/features/undo_redo_test.py similarity index 100% rename from tests/undo_redo_test.py rename to tests/features/undo_redo_test.py diff --git a/tests/file_test.py b/tests/file_test.py index 4307166..47c1346 100644 --- a/tests/file_test.py +++ b/tests/file_test.py @@ -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" diff --git a/tests/get_lines_test.py b/tests/get_lines_test.py index 488a773..a01de74 100644 --- a/tests/get_lines_test.py +++ b/tests/get_lines_test.py @@ -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) diff --git a/tests/list_spy_test.py b/tests/list_spy_test.py index 9823259..2f9d135 100644 --- a/tests/list_spy_test.py +++ b/tests/list_spy_test.py @@ -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']