aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJ08nY2023-10-25 13:05:42 +0200
committerJ08nY2023-10-25 13:05:42 +0200
commit344b6bde5cad1884ac2900d12a3fe84cd168f800 (patch)
treebb19954dd70e1a6c569cdace44ad8970be5c6b4e
parenta8d60bff6d4c70698cb4145cf1cc53cf215d4ad4 (diff)
downloadpyecsca-344b6bde5cad1884ac2900d12a3fe84cd168f800.tar.gz
pyecsca-344b6bde5cad1884ac2900d12a3fe84cd168f800.tar.zst
pyecsca-344b6bde5cad1884ac2900d12a3fe84cd168f800.zip
Add trace_set repr test.
-rw-r--r--pyecsca/sca/trace_set/base.py2
-rw-r--r--test/sca/test_traceset.py30
2 files changed, 29 insertions, 3 deletions
diff --git a/pyecsca/sca/trace_set/base.py b/pyecsca/sca/trace_set/base.py
index 649c8de..4de7a8c 100644
--- a/pyecsca/sca/trace_set/base.py
+++ b/pyecsca/sca/trace_set/base.py
@@ -48,4 +48,4 @@ class TraceSet:
args = ", ".join(
[f"{key}={getattr(self, key)!r}" for key in self._keys]
)
- return f"TraceSet({args})"
+ return f"{self.__class__.__name__}({args})"
diff --git a/test/sca/test_traceset.py b/test/sca/test_traceset.py
index ebc98a1..5a3ed52 100644
--- a/test/sca/test_traceset.py
+++ b/test/sca/test_traceset.py
@@ -15,6 +15,7 @@ from pyecsca.sca import (
PickleTraceSet,
HDF5TraceSet,
Trace,
+ SampleCoding,
)
@@ -40,6 +41,27 @@ def test_create():
assert HDF5TraceSet() is not None
+def test_repr(example_traces, tmp_path):
+ trs = InspectorTraceSet(
+ *example_traces, num_traces=len(example_traces), sample_coding=SampleCoding.Int8, num_samples=5, y_scale=1
+ )
+ r1 = repr(trs)
+ trs.write(tmp_path / "test.trs")
+ r2 = repr(InspectorTraceSet.read(tmp_path / "test.trs"))
+ assert r1
+ assert r2
+
+ cw = ChipWhispererTraceSet(*example_traces)
+ r1 = repr(cw)
+ assert r1
+
+ pickle = PickleTraceSet(*example_traces)
+ r1 = repr(pickle)
+ pickle.write(tmp_path / "test.pickle")
+ r2 = repr(PickleTraceSet.read(tmp_path / "test.pickle"))
+ assert r1 == r2
+
+
def test_trs_load_fname():
with as_file(files(test.data.sca).joinpath("example.trs")) as path:
result = InspectorTraceSet.read(path)
@@ -112,12 +134,16 @@ def test_h5_load_file():
def test_h5_inplace():
- with tempfile.TemporaryDirectory() as dirname, as_file(files(test.data.sca).joinpath("test.h5")) as orig_path:
+ with tempfile.TemporaryDirectory() as dirname, as_file(
+ files(test.data.sca).joinpath("test.h5")
+ ) as orig_path:
path = os.path.join(dirname, "test.h5")
shutil.copy(orig_path, path)
trace_set = HDF5TraceSet.inplace(path)
assert trace_set is not None
- test_trace = Trace(np.array([4, 7], dtype=np.dtype("i1")), meta={"thing": "ring"})
+ test_trace = Trace(
+ np.array([4, 7], dtype=np.dtype("i1")), meta={"thing": "ring"}
+ )
other_trace = Trace(np.array([8, 7], dtype=np.dtype("i1")), meta={"a": "b"})
trace_set.append(test_trace)
assert len(trace_set) == 3