diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 02b8cb80..bc35e1a5 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -30,7 +30,13 @@ jobs: - name: Install SWI-Prolog (Windows) if: matrix.os == 'windows-latest' - run: choco install -y swi-prolog + run: | + choco install -y swi-prolog + $swiplHome = "C:\Program Files\swipl" + $swiplBin = Join-Path $swiplHome "bin" + Add-Content -Path $env:GITHUB_PATH -Value $swiplBin + Add-Content -Path $env:GITHUB_ENV -Value "SWI_HOME_DIR=$swiplHome" + & (Join-Path $swiplBin "swipl.exe") --version - name: Install SWI-Prolog (macOS) if: matrix.os == 'macos-latest' diff --git a/tests/conftest.py b/tests/conftest.py index 29cdafb1..ff380b56 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -201,7 +201,7 @@ def kb_add_ground(): @pytest.fixture def kb_add_prolog(): if platform.system() == "Darwin": - return + pytest.skip("Prolog tests are skipped on macOS") kb = PrologKB(pseudo_label_list=list(range(10)), pl_file="examples/mnist_add/add.pl") return kb @@ -219,7 +219,7 @@ def kb_hwf2(): @pytest.fixture def kb_hed(): if platform.system() == "Darwin": - return + pytest.skip("Prolog tests are skipped on macOS") kb = HedKB( pseudo_label_list=[1, 0, "+", "="], pl_file="examples/hed/reasoning/learn_add.pl", diff --git a/tests/test_reasoning.py b/tests/test_reasoning.py index 70b9c96a..8aaa2dd4 100644 --- a/tests/test_reasoning.py +++ b/tests/test_reasoning.py @@ -5,6 +5,12 @@ from ablkit.reasoning import PrologKB, Reasoner +PROLOG_SKIP_ON_DARWIN = pytest.mark.skipif( + platform.system() == "Darwin", + reason="Prolog tests are skipped on macOS", +) + + class TestKBBase(object): def test_init(self, kb_add): assert kb_add.pseudo_label_list == list(range(10)) @@ -55,22 +61,17 @@ def test_abduce_candidates_ground(self, kb_add_ground): assert result == ([(1, 0)], [1]) +@PROLOG_SKIP_ON_DARWIN class TestPrologKB(object): def test_init_pl1(self, kb_add_prolog): - if platform.system() == "Darwin": - return assert kb_add_prolog.pseudo_label_list == list(range(10)) assert kb_add_prolog.pl_file == "examples/mnist_add/add.pl" def test_init_pl2(self, kb_hed): - if platform.system() == "Darwin": - return assert kb_hed.pseudo_label_list == [1, 0, "+", "="] assert kb_hed.pl_file == "examples/hed/reasoning/learn_add.pl" def test_prolog_file_not_exist(self): - if platform.system() == "Darwin": - return pseudo_label_list = [1, 2] non_existing_file = "path/to/non_existing_file.pl" with pytest.raises(FileNotFoundError) as excinfo: @@ -78,14 +79,10 @@ def test_prolog_file_not_exist(self): assert non_existing_file in str(excinfo.value) def test_logic_forward_pl1(self, kb_add_prolog): - if platform.system() == "Darwin": - return result = kb_add_prolog.logic_forward([1, 2]) assert result == 3 def test_logic_forward_pl2(self, kb_hed): - if platform.system() == "Darwin": - return consist_exs = [ [1, 1, "+", 0, "=", 1, 1], [1, "+", 1, "=", 1, 0], @@ -101,8 +98,6 @@ def test_logic_forward_pl2(self, kb_hed): assert kb_hed.logic_forward(inconsist_exs) is False def test_revise_at_idx(self, kb_add_prolog): - if platform.system() == "Darwin": - return result = kb_add_prolog.revise_at_idx([1, 2], 2, [0.1, -0.2, 0.2, -0.3], [0]) assert result == ([[0, 2]], [2]) @@ -190,9 +185,8 @@ def test_batch_abduce_ground(self, kb_add_ground, data_examples_add): (7, 3), ] + @PROLOG_SKIP_ON_DARWIN def test_batch_abduce_prolog(self, kb_add_prolog, data_examples_add): - if platform.system() == "Darwin": - return reasoner1 = Reasoner(kb_add_prolog, "confidence", max_revision=1, require_more_revision=0) reasoner2 = Reasoner(kb_add_prolog, "confidence", max_revision=1, require_more_revision=1) reasoner3 = Reasoner(kb_add_prolog, "confidence", max_revision=2, require_more_revision=0) @@ -212,9 +206,8 @@ def test_batch_abduce_prolog(self, kb_add_prolog, data_examples_add): [7, 3], ] + @PROLOG_SKIP_ON_DARWIN def test_batch_abduce_zoopt(self, kb_add_prolog, data_examples_add): - if platform.system() == "Darwin": - return reasoner1 = Reasoner(kb_add_prolog, "confidence", use_zoopt=True, max_revision=1) reasoner2 = Reasoner(kb_add_prolog, "confidence", use_zoopt=True, max_revision=2) assert reasoner1.batch_abduce(data_examples_add) == [[1, 7], [7, 1], [], [1, 9]]