Skip to content

Commit 6e28f8c

Browse files
committed
tests/raise unimplemented
1 parent 3f3b134 commit 6e28f8c

File tree

2 files changed

+102
-20
lines changed

2 files changed

+102
-20
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from __future__ import annotations
2+
3+
import tempfile
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
from chia.plotting.prover import PlotVersion, V2Prover, get_prover_from_file
9+
10+
11+
class TestProver:
12+
def test_v2_prover_init_with_nonexistent_file(self) -> None:
13+
prover = V2Prover("/nonexistent/path/test.plot2")
14+
assert prover.get_version() == PlotVersion.V2
15+
assert prover.get_filename() == Path("/nonexistent/path/test.plot2")
16+
assert prover.get_filename_str() == "/nonexistent/path/test.plot2"
17+
18+
def test_v2_prover_get_size_raises_error(self) -> None:
19+
prover = V2Prover("/nonexistent/path/test.plot2")
20+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
21+
prover.get_size()
22+
23+
def test_v2_prover_get_memo_raises_error(self) -> None:
24+
prover = V2Prover("/nonexistent/path/test.plot2")
25+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
26+
prover.get_memo()
27+
28+
def test_v2_prover_get_compression_level_raises_error(self) -> None:
29+
prover = V2Prover("/nonexistent/path/test.plot2")
30+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
31+
prover.get_compression_level()
32+
33+
def test_v2_prover_get_id_raises_error(self) -> None:
34+
prover = V2Prover("/nonexistent/path/test.plot2")
35+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
36+
prover.get_id()
37+
38+
def test_v2_prover_get_qualities_for_challenge_raises_error(self) -> None:
39+
prover = V2Prover("/nonexistent/path/test.plot2")
40+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
41+
prover.get_qualities_for_challenge(b"challenge")
42+
43+
def test_v2_prover_get_full_proof_raises_error(self) -> None:
44+
prover = V2Prover("/nonexistent/path/test.plot2")
45+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
46+
prover.get_full_proof(b"challenge", 0)
47+
48+
def test_v2_prover_bytes_raises_error(self) -> None:
49+
prover = V2Prover("/nonexistent/path/test.plot2")
50+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
51+
bytes(prover)
52+
53+
def test_v2_prover_from_bytes_raises_error(self) -> None:
54+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
55+
V2Prover.from_bytes(b"test_data")
56+
57+
def test_get_prover_from_file(self) -> None:
58+
prover = get_prover_from_file("/nonexistent/path/test.plot2")
59+
assert prover.get_version() == PlotVersion.V2
60+
with pytest.raises(NotImplementedError, match="V2 plot format is not yet implemented"):
61+
prover.get_size()
62+
63+
def test_get_prover_from_file_with_plot1_still_works(self) -> None:
64+
with tempfile.NamedTemporaryFile(suffix=".plot", delete=False) as f:
65+
temp_path = f.name
66+
try:
67+
with pytest.raises(Exception) as exc_info:
68+
get_prover_from_file(temp_path)
69+
assert not isinstance(exc_info.value, NotImplementedError)
70+
finally:
71+
Path(temp_path).unlink()
72+
73+
def test_unsupported_file_extension_raises_value_error(self) -> None:
74+
"""Test that unsupported file extensions raise ValueError"""
75+
with pytest.raises(ValueError, match="Unsupported plot file"):
76+
get_prover_from_file("/nonexistent/path/test.txt")

chia/plotting/prover.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from abc import ABC, abstractmethod
4+
from enum import IntEnum
45
from pathlib import Path
56
from typing import TYPE_CHECKING
67

@@ -12,6 +13,13 @@
1213
from chiapos import DiskProver
1314

1415

16+
class PlotVersion(IntEnum):
17+
"""Enum for plot format versions"""
18+
19+
V1 = 1
20+
V2 = 2
21+
22+
1523
class ProverProtocol(ABC):
1624
@abstractmethod
1725
def get_filename(self) -> Path:
@@ -34,7 +42,7 @@ def get_compression_level(self) -> uint8:
3442
"""Returns the compression level"""
3543

3644
@abstractmethod
37-
def get_version(self) -> int:
45+
def get_version(self) -> PlotVersion:
3846
"""Returns the plot version"""
3947

4048
@abstractmethod
@@ -64,7 +72,6 @@ class V2Prover(ProverProtocol):
6472

6573
def __init__(self, filename: str):
6674
self._filename = filename
67-
# TODO: todo_v2_plots Implement plot file parsing and validation
6875

6976
def get_filename(self) -> Path:
7077
return Path(self._filename)
@@ -74,40 +81,39 @@ def get_filename_str(self) -> str:
7481

7582
def get_size(self) -> uint8:
7683
# TODO: todo_v2_plots get k size from plot
77-
return uint8(32) # Stub value
84+
raise NotImplementedError("V2 plot format is not yet implemented")
7885

7986
def get_memo(self) -> bytes:
8087
# TODO: todo_v2_plots
81-
return b"" # Stub value
88+
raise NotImplementedError("V2 plot format is not yet implemented")
8289

8390
def get_compression_level(self) -> uint8:
84-
# TODO: Extract compression level from V2 plot file
85-
return uint8(0) # Stub value
91+
# TODO: todo_v2_plots implement compression level retrieval
92+
raise NotImplementedError("V2 plot format is not yet implemented")
8693

87-
def get_version(self) -> int:
88-
return 2
94+
def get_version(self) -> PlotVersion:
95+
return PlotVersion.V2
8996

9097
def __bytes__(self) -> bytes:
9198
# TODO: todo_v2_plots Implement prover serialization for caching
92-
# For now, just serialize the filename as a placeholder
93-
return self._filename.encode("utf-8")
99+
raise NotImplementedError("V2 plot format is not yet implemented")
94100

95101
def get_id(self) -> bytes32:
96102
# TODO: Extract plot ID from V2 plot file
97-
return bytes32(b"") # Stub value
103+
raise NotImplementedError("V2 plot format is not yet implemented")
98104

99-
def get_qualities_for_challenge(self, challenge: bytes) -> list[bytes32]:
105+
def get_qualities_for_challenge(self, _challenge: bytes) -> list[bytes32]:
100106
# TODO: todo_v2_plots Implement plot quality lookup
101-
return [] # Stub value
107+
raise NotImplementedError("V2 plot format is not yet implemented")
102108

103-
def get_full_proof(self, challenge: bytes, index: int, parallel_read: bool = True) -> bytes:
109+
def get_full_proof(self, _challenge: bytes, _index: int, _parallel_read: bool = True) -> bytes:
104110
# TODO: todo_v2_plots Implement plot proof generation
105-
return b""
111+
raise NotImplementedError("V2 plot format is not yet implemented")
106112

107113
@classmethod
108-
def from_bytes(cls, data: bytes) -> V2Prover:
109-
filename = data.decode("utf-8")
110-
return cls(filename)
114+
def from_bytes(cls, _data: bytes) -> V2Prover:
115+
# TODO: todo_v2_plots Implement prover deserialization from cache
116+
raise NotImplementedError("V2 plot format is not yet implemented")
111117

112118

113119
class V1Prover(ProverProtocol):
@@ -131,8 +137,8 @@ def get_memo(self) -> bytes:
131137
def get_compression_level(self) -> uint8:
132138
return uint8(self._disk_prover.get_compression_level())
133139

134-
def get_version(self) -> int:
135-
return 1
140+
def get_version(self) -> PlotVersion:
141+
return PlotVersion.V1
136142

137143
def __bytes__(self) -> bytes:
138144
return bytes(self._disk_prover)

0 commit comments

Comments
 (0)