Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit 8f87eae

Browse files
Refactor TestEmitJsonSpec (#490)
Uses the `kprove` fixture to generate the JSON spec in a temporary directory. --------- Co-authored-by: devops <[email protected]>
1 parent 628fd17 commit 8f87eae

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.328
1+
0.1.329

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyk"
7-
version = "0.1.328"
7+
version = "0.1.329"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

src/pyk/ktool/kprove.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,13 @@ def prove_cterm(
308308
next_states = [mlAnd([constraint_subst.unapply(ns), constraint_subst.ml_pred]) for ns in next_states]
309309
return next_states if len(next_states) > 0 else [mlTop()]
310310

311-
def get_claims(
311+
def get_claim_modules(
312312
self,
313313
spec_file: Path,
314314
spec_module_name: str | None = None,
315315
include_dirs: Iterable[Path] = (),
316316
md_selector: str | None = None,
317-
claim_labels: Iterable[str] | None = None,
318-
exclude_claim_labels: Iterable[str] | None = None,
319-
) -> list[KClaim]:
317+
) -> KFlatModuleList:
320318
with self._temp_file() as ntf:
321319
self.prove(
322320
spec_file,
@@ -326,10 +324,25 @@ def get_claims(
326324
dry_run=True,
327325
args=['--emit-json-spec', ntf.name],
328326
)
329-
flat_module_list = kast_term(json.loads(Path(ntf.name).read_text()), KFlatModuleList)
327+
return kast_term(json.loads(Path(ntf.name).read_text()), KFlatModuleList)
330328

331-
all_claims = {c.label: c for m in flat_module_list.modules for c in m.claims}
329+
def get_claims(
330+
self,
331+
spec_file: Path,
332+
spec_module_name: str | None = None,
333+
include_dirs: Iterable[Path] = (),
334+
md_selector: str | None = None,
335+
claim_labels: Iterable[str] | None = None,
336+
exclude_claim_labels: Iterable[str] | None = None,
337+
) -> list[KClaim]:
338+
flat_module_list = self.get_claim_modules(
339+
spec_file=spec_file,
340+
spec_module_name=spec_module_name,
341+
include_dirs=include_dirs,
342+
md_selector=md_selector,
343+
)
332344

345+
all_claims = {c.label: c for m in flat_module_list.modules for c in m.claims}
333346
unfound_labels = []
334347
claim_labels = list(all_claims.keys()) if claim_labels is None else claim_labels
335348
exclude_claim_labels = [] if exclude_claim_labels is None else exclude_claim_labels

src/tests/integration/kprove/test_emit_json_spec.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
from __future__ import annotations
22

3-
import json
43
from pathlib import Path
54
from typing import TYPE_CHECKING
65

76
import pytest
87

9-
from pyk.kast import kast_term
108
from pyk.kast.inner import EMPTY_ATT
119
from pyk.kast.manip import remove_generated_cells
12-
from pyk.kast.outer import KDefinition, KFlatModuleList, KRequire
10+
from pyk.kast.outer import KDefinition, KRequire
1311
from pyk.kast.pretty import paren
14-
from pyk.ktool.kprove import _kprove
1512
from pyk.prelude.ml import is_top
1613
from pyk.testing import KProveTest
1714

@@ -31,12 +28,10 @@ class TestEmitJsonSpec(KProveTest):
3128
def _update_symbol_table(symbol_table: SymbolTable) -> None:
3229
symbol_table['_+Int_'] = paren(symbol_table['_+Int_'])
3330

34-
@pytest.fixture(scope='class')
35-
def spec_module(self, definition_dir: Path) -> KFlatModule:
31+
@pytest.fixture
32+
def spec_module(self, kprove: KProve) -> KFlatModule:
3633
spec_file = K_FILES / 'looping-spec.k'
37-
spec_json_file = definition_dir / 'looping-spec.json'
38-
_kprove(spec_file, kompiled_dir=definition_dir, emit_json_spec=spec_json_file, dry_run=True)
39-
kfml = kast_term(json.loads(spec_json_file.read_text()), KFlatModuleList)
34+
kfml = kprove.get_claim_modules(spec_file)
4035
module = kfml.modules[0]
4136
claim = module.claims[0]
4237
claim = claim.let(body=remove_generated_cells(claim.body), att=EMPTY_ATT)

0 commit comments

Comments
 (0)