Skip to content

Commit

Permalink
Adapt existing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lauft committed Mar 8, 2025
1 parent a5be1df commit 41f53c2
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions test/test_on-modify_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import subprocess

import pytest
from mockito import unstub, verify, when
from mockito import mock, unstub, verify, when

import on_modify

Expand All @@ -45,6 +45,8 @@ def test_hook_should_process_annotate():
"""on-modify hook should process 'task annotate'"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -75,6 +77,8 @@ def test_hook_should_process_append():
"""on-modify hook should process 'task append'"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -105,6 +109,8 @@ def test_hook_should_process_delete():
"""on-modify hook should process 'task delete'"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -135,6 +141,8 @@ def test_hook_should_process_denotate():
"""on-modify hook should process 'task denotate'"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -165,6 +173,8 @@ def test_hook_should_process_done():
"""on-modify hook should process 'task done'"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -194,6 +204,8 @@ def test_hook_should_process_modify_desc():
"""on-modify hook should process 'task modify' for changing description"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -224,6 +236,8 @@ def test_hook_should_process_modify_tags():
"""on-modify hook should process 'task modify' for changing tags"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -256,6 +270,8 @@ def test_hook_should_process_modify_project():
"""on-modify hook should process 'task modify' for changing project"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -288,6 +304,8 @@ def test_hook_should_process_prepend():
"""on-modify hook should process 'task prepend'"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down Expand Up @@ -318,6 +336,8 @@ def test_hook_should_process_start():
"""on-modify hook should process 'task start'"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand All @@ -338,14 +358,16 @@ def test_hook_should_process_start():
}''')
)

verify(subprocess).call(['timew', 'start', 'Foo', ':yes'])
verify(subprocess).call(['timew', 'start', '20190820T203842Z', 'Foo', ':yes'])


@pytest.mark.usefixtures("teardown")
def test_hook_should_process_stop():
"""on-modify hook should process 'task stop'"""

when(subprocess).call(...)
when(subprocess).run(['timew', 'get', 'dom.active.tag.count'], ...).thenReturn(mock({'stdout': '1\n'}))
when(subprocess).run(['timew', 'get', 'dom.active.tag.1'], ...).thenReturn(mock({'stdout': 'Foo\n'}))
on_modify.main(
json.loads(
'''{
Expand Down

0 comments on commit 41f53c2

Please sign in to comment.