aboutsummaryrefslogtreecommitdiff
path: root/test/utils.py
diff options
context:
space:
mode:
authorJ08nY2018-11-20 00:36:46 +0100
committerJ08nY2019-03-14 18:03:54 +0100
commite0a6e7c452cd55365096bc3e4b8f36f5f9660ae7 (patch)
treebf1c80e015cdfd47d864665946f44a072f7b38db /test/utils.py
downloadpyecsca-e0a6e7c452cd55365096bc3e4b8f36f5f9660ae7.tar.gz
pyecsca-e0a6e7c452cd55365096bc3e4b8f36f5f9660ae7.tar.zst
pyecsca-e0a6e7c452cd55365096bc3e4b8f36f5f9660ae7.zip
Diffstat (limited to 'test/utils.py')
-rw-r--r--test/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/utils.py b/test/utils.py
new file mode 100644
index 0000000..e7d5819
--- /dev/null
+++ b/test/utils.py
@@ -0,0 +1,24 @@
+import matplotlib.pyplot as plt
+from unittest import TestCase
+from pyecsca import Trace
+from os.path import join, exists
+from os import mkdir, getenv
+
+
+def slow(func):
+ func.slow = 1
+ return func
+
+
+def plot(case: TestCase, *traces: Trace):
+ if getenv("PYECSCA_TEST_PLOTS") is None:
+ return
+ fig = plt.figure()
+ ax = fig.add_subplot(111)
+ for i, trace in enumerate(traces):
+ ax.plot(trace.samples, label=str(i))
+ ax.legend(loc="best")
+ directory = join("test", "plots")
+ if not exists(directory):
+ mkdir(directory)
+ plt.savefig(join(directory, case.id() + ".png"))