Skip to content

Commit 634b212

Browse files
committed
fix: isolate tests from real KB directories via mocking
1 parent 7b3bc0c commit 634b212

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

tests/test_add_command.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def test_finds_openkb_dir(self, tmp_path, monkeypatch):
3737

3838
def test_returns_none_if_no_openkb(self, tmp_path, monkeypatch):
3939
monkeypatch.chdir(tmp_path)
40-
result = _find_kb_dir()
41-
assert result is None
40+
with patch("openkb.cli.load_global_config", return_value={}):
41+
result = _find_kb_dir()
42+
assert result is None
4243

4344

4445
class TestAddCommand:

tests/test_cli.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import json
2+
from unittest.mock import patch
3+
24
import pytest
35
from click.testing import CliRunner
46

@@ -8,7 +10,8 @@
810

911
def test_init_creates_structure(tmp_path):
1012
runner = CliRunner()
11-
with runner.isolated_filesystem(temp_dir=tmp_path):
13+
with runner.isolated_filesystem(temp_dir=tmp_path), \
14+
patch("openkb.cli.register_kb"):
1215
result = runner.invoke(cli, ["init"])
1316
assert result.exit_code == 0
1417

@@ -42,7 +45,8 @@ def test_init_creates_structure(tmp_path):
4245

4346
def test_init_schema_content(tmp_path):
4447
runner = CliRunner()
45-
with runner.isolated_filesystem(temp_dir=tmp_path):
48+
with runner.isolated_filesystem(temp_dir=tmp_path), \
49+
patch("openkb.cli.register_kb"):
4650
result = runner.invoke(cli, ["init"])
4751
assert result.exit_code == 0
4852

@@ -53,7 +57,8 @@ def test_init_schema_content(tmp_path):
5357

5458
def test_init_already_exists(tmp_path):
5559
runner = CliRunner()
56-
with runner.isolated_filesystem(temp_dir=tmp_path):
60+
with runner.isolated_filesystem(temp_dir=tmp_path), \
61+
patch("openkb.cli.register_kb"):
5762
# First run should succeed
5863
result = runner.invoke(cli, ["init"])
5964
assert result.exit_code == 0

tests/test_list_status.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def _setup_kb(tmp_path: Path) -> Path:
3232
class TestListCommand:
3333
def test_list_no_kb(self, tmp_path):
3434
runner = CliRunner()
35-
with runner.isolated_filesystem(temp_dir=tmp_path):
35+
with runner.isolated_filesystem(temp_dir=tmp_path), \
36+
patch("openkb.cli._find_kb_dir", return_value=None):
3637
result = runner.invoke(cli, ["list"])
3738
assert "No knowledge base found" in result.output
3839

@@ -91,7 +92,8 @@ def test_list_no_concepts_section_when_empty(self, tmp_path):
9192
class TestStatusCommand:
9293
def test_status_no_kb(self, tmp_path):
9394
runner = CliRunner()
94-
with runner.isolated_filesystem(temp_dir=tmp_path):
95+
with runner.isolated_filesystem(temp_dir=tmp_path), \
96+
patch("openkb.cli._find_kb_dir", return_value=None):
9597
result = runner.invoke(cli, ["status"])
9698
assert "No knowledge base found" in result.output
9799

0 commit comments

Comments
 (0)