Skip to content

Commit

Permalink
adds github ci workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ju1ius committed Nov 21, 2023
1 parent 1d0f16e commit a761974
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 103 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and test

on:
workflow_dispatch:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
name: Test py@${{matrix.python-version}} / ${{matrix.os}}
runs-on: ${{matrix.os}}
continue-on-error: false
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
python-version:
- "3.11"
steps:
- uses: actions/checkout@v4
# https://github.com/actions/setup-python/issues/659
- name: Install poetry
run: pipx install poetry
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{matrix.python-version}}
cache: poetry
- name: Install dependencies
run: poetry install
- name: Lint
run: |
poetry run ruff format --check .
poetry run ruff check
- name: Test
run: poetry run pytest
6 changes: 3 additions & 3 deletions clisnips/stores/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def watch(
self,
expr: Callable[[State], Watched],
on_change: Callable[[Watched], Any],
sync: bool =False,
deep: bool =False,
immediate: bool =False,
sync: bool = False,
deep: bool = False,
immediate: bool = False,
):
return watch(
fn=lambda: expr(self._state),
Expand Down
10 changes: 6 additions & 4 deletions clisnips/tui/widgets/field/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ class SimpleField(Field, urwid.Pile):
def __init__(self, label: TextMarkup, entry: Entry):
self._entry = entry
urwid.connect_signal(self._entry, 'changed', lambda *w: self._emit('changed'))
super().__init__([
urwid.Text(label),
self._entry, # type: ignore
])
super().__init__(
[
urwid.Text(label),
self._entry, # type: ignore
]
)

def get_value(self):
return self._entry.get_value()
26 changes: 17 additions & 9 deletions tests/database/offset_pager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
('test bar', 6),
('test baz', 3),
('test qux', 4),
('test foobar', 8)
('test foobar', 8),
]


Expand All @@ -24,11 +24,13 @@ def connection():
for i in range(4):
for value, ranking in FIXTURES:
rowid += 1
value = '%s #%s' % (value, rowid)
value = f'{value} #{rowid}'
con.execute(
'''insert into paging_test(rowid, value, ranking)
values(?, ?, ?)''',
(rowid, value, ranking)
"""
insert into paging_test(rowid, value, ranking)
values(?, ?, ?)
""",
(rowid, value, ranking),
)
yield con
con.close()
Expand Down Expand Up @@ -78,15 +80,21 @@ def test_complex_query(connection):
1: [1, 5, 6, 10, 11],
2: [15, 16, 20],
}
pager.set_query('''
pager.set_query(
"""
SELECT i.docid, t.rowid, t.* FROM paging_test t
JOIN paging_test_idx i ON i.docid = t.rowid
WHERE paging_test_idx MATCH :term
''', params)
pager.set_count_query('''
""",
params,
)
pager.set_count_query(
"""
SELECT docid FROM paging_test_idx
WHERE paging_test_idx MATCH :term
''', params)
""",
params,
)
pager.execute()
assert len(pager) == 2, 'Wrong number of pages.'
#
Expand Down
35 changes: 20 additions & 15 deletions tests/database/scroll_cursor_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from clisnips.database import ScrollDirection, SortOrder
from clisnips.database.scrolling_pager import Cursor

Expand All @@ -23,10 +22,12 @@ def test_default_columns():


def test_single_sort_column():
cursor = Cursor.with_columns((
('foo', SortOrder.DESC),
('id', SortOrder.ASC, True),
))
cursor = Cursor.with_columns(
(
('foo', SortOrder.DESC),
('id', SortOrder.ASC, True),
)
)
assert cursor.unique_column == ('id', SortOrder.ASC)
assert cursor.sort_columns == [('foo', SortOrder.DESC)]
assert list(cursor.columns()) == [
Expand All @@ -48,11 +49,13 @@ def test_single_sort_column():


def test_multiple_sort_columns():
cursor = Cursor.with_columns((
('foo', SortOrder.DESC),
('id', SortOrder.ASC, True),
('bar', SortOrder.ASC),
))
cursor = Cursor.with_columns(
(
('foo', SortOrder.DESC),
('id', SortOrder.ASC, True),
('bar', SortOrder.ASC),
)
)
assert cursor.unique_column == ('id', SortOrder.ASC)
assert cursor.sort_columns == [('foo', SortOrder.DESC), ('bar', SortOrder.ASC)]
assert list(cursor.columns()) == [
Expand Down Expand Up @@ -81,11 +84,13 @@ def test_multiple_sort_columns():


def test_update():
cursor = Cursor.with_columns((
('foo', SortOrder.DESC),
('bar', SortOrder.ASC),
('id', SortOrder.ASC, True),
))
cursor = Cursor.with_columns(
(
('foo', SortOrder.DESC),
('bar', SortOrder.ASC),
('id', SortOrder.ASC, True),
)
)
empty = {'id': None, 'foo': None, 'bar': None}
assert cursor.first == cursor.last == empty

Expand Down
19 changes: 11 additions & 8 deletions tests/database/scrolling_pager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ def connection():
for value, ranking in FIXTURES:
rowid += 1
value = '%s #%s' % (value, rowid)
con.execute(
'''INSERT INTO paging_test(rowid, value, ranking) VALUES(?, ?, ?)''',
(rowid, value, ranking)
)
con.execute("""INSERT INTO paging_test(rowid, value, ranking) VALUES(?, ?, ?)""", (rowid, value, ranking))
yield con
con.close()

Expand Down Expand Up @@ -85,15 +82,21 @@ def test_simple_query(connection):
def test_complex_query(connection):
pager = ScrollingPager(connection, 5)
params = {'term': 'foo*'}
pager.set_query('''
pager.set_query(
"""
SELECT i.docid, t.rowid, t.* from paging_test t
JOIN paging_test_idx i ON i.docid = t.rowid
WHERE paging_test_idx MATCH :term
''', params)
pager.set_count_query('''
""",
params,
)
pager.set_count_query(
"""
SELECT docid FROM paging_test_idx
WHERE paging_test_idx MATCH :term
''', params)
""",
params,
)
pager.set_sort_columns([('ranking', SortOrder.DESC), ('rowid', SortOrder.ASC, True)])
expected = {
1: [5, 10, 15, 20, 1],
Expand Down
5 changes: 2 additions & 3 deletions tests/layouts/table_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from clisnips.tui.layouts.table import LayoutColumn, LayoutRow, TableLayout


Expand Down Expand Up @@ -28,10 +27,10 @@ def test_layout():
{'a': 'one', 'b': 'two', 'c': 'three'},
{'a': 'four', 'b': 'five', 'c': 'six'},
]
expected = '''
expected = """
| one | two | three |
| four | five | six |
'''
"""
table.layout(rows, 0)
result = []
for row in table:
Expand Down
25 changes: 14 additions & 11 deletions tests/syntax/command/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_simple_replacement_field():
expected = [
Text('i haz ', 0, 6),
Field('one', 6, 11),
Text(' field', 11, 17)
Text(' field', 11, 17),
]
assert cmd.nodes == expected

Expand All @@ -31,7 +31,7 @@ def test_it_supports_flags():
Field('-1', 6, 10),
Text(' ', 10, 11),
Field('--two', 11, 18),
Text(' flags', 18, 24)
Text(' flags', 18, 24),
]
assert cmd.nodes == expected

Expand All @@ -44,7 +44,7 @@ def test_automatic_numbering():
Field('0', 6, 8),
Text(' ', 8, 9),
Field('1', 9, 11),
Text(' flags', 11, 17)
Text(' flags', 11, 17),
]
assert cmd.nodes == expected

Expand All @@ -55,7 +55,7 @@ def test_conversion():
expected = [
Text('i haz ', 0, 6),
Field('one', 6, 13, '', 'r'),
Text(' field', 13, 19)
Text(' field', 13, 19),
]
assert cmd.nodes == expected

Expand All @@ -66,7 +66,7 @@ def test_format_spec():
expected = [
Text('i haz ', 0, 6),
Field('0', 6, 13, '.1f', None),
Text(' field', 13, 19)
Text(' field', 13, 19),
]
assert cmd.nodes == expected

Expand Down Expand Up @@ -98,11 +98,15 @@ def test_field_getattr():
def test_command_apply():
raw = 'i haz {} {:.2f} fields'
cmd = parse(raw)
output = list(cmd.apply({
'0': 'zaroo',
'1': 1 / 3, # type: ignore (we're testing if it handles other types correctly)
'foo': {'bar': 42}
}))
output = list(
cmd.apply(
{
'0': 'zaroo',
'1': 1 / 3, # type: ignore (we're testing if it handles other types correctly)
'foo': {'bar': 42},
}
)
)
expected = [
(False, 'i haz '),
(True, 'zaroo'),
Expand All @@ -111,4 +115,3 @@ def test_command_apply():
(False, ' fields'),
]
assert expected == output

Loading

0 comments on commit a761974

Please sign in to comment.