|
1 |
| -from taskit.__main__ import main |
| 1 | +import os |
| 2 | +import sys |
| 3 | +import taskit.__main__ |
| 4 | +from subprocess import run |
| 5 | +from pytest import fixture |
| 6 | +from unittest.mock import Mock, patch |
| 7 | +from taskit.__main__ import main, build_state |
2 | 8 |
|
3 | 9 |
|
4 |
| -# def test_main(): |
5 |
| -# main() |
| 10 | +@fixture(scope='module') |
| 11 | +def taskit_dir(tmpdir_factory: fixture) -> str: |
| 12 | + taskit_dir = tmpdir_factory.mktemp('taskitdir') |
| 13 | + return str(taskit_dir) |
| 14 | + |
| 15 | + |
| 16 | +def test_main(taskit_dir) -> None: |
| 17 | + sandbox = patch.dict(os.environ, {'TASKIT_DIR': taskit_dir}) |
| 18 | + sandbox.start() |
| 19 | + python_bin = sys.executable |
| 20 | + result = run([python_bin, '-m', 'taskit']) |
| 21 | + sandbox.stop() |
| 22 | + assert result.returncode == 0 |
| 23 | + |
| 24 | + |
| 25 | +def test_main_db_file_not_empty(taskit_dir) -> None: |
| 26 | + sandbox = patch.dict(os.environ, {'TASKIT_DIR': taskit_dir}) |
| 27 | + sandbox.start() |
| 28 | + db_path = os.sep.join([taskit_dir, 'db.json']) |
| 29 | + with open(db_path, 'w+') as f: |
| 30 | + f.write('{"projects": {}}') |
| 31 | + python_bin = sys.executable |
| 32 | + result = run([python_bin, '-m', 'taskit']) |
| 33 | + sandbox.stop() |
| 34 | + assert result.returncode == 0 |
| 35 | + |
| 36 | + |
| 37 | +def test_main_exception_handling(taskit_dir, monkeypatch) -> None: |
| 38 | + sandbox = patch.dict(os.environ, {'TASKIT_DIR': taskit_dir}) |
| 39 | + sandbox.start() |
| 40 | + monkeypatch.setattr("taskit.__main__.build_state", lambda x: "NOTHING") |
| 41 | + python_bin = sys.executable |
| 42 | + result = run([python_bin, '-m', 'taskit', 'report', 'tasks']) |
| 43 | + sandbox.stop() |
| 44 | + assert result.returncode != 0 |
0 commit comments