aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/ec/test_context.py
diff options
context:
space:
mode:
authorJ08nY2019-04-23 23:24:55 +0200
committerJ08nY2019-04-23 23:24:55 +0200
commitf4bcb085cfc9ddac71fe8bb82e8f6719309b2637 (patch)
treeb07b30112fc2661f4fb5da7bfda30975e83077f9 /test/ec/test_context.py
parent28390ec1575e0af026be2bfea6fd0bca8f55c008 (diff)
downloadpyecsca-f4bcb085cfc9ddac71fe8bb82e8f6719309b2637.tar.gz
pyecsca-f4bcb085cfc9ddac71fe8bb82e8f6719309b2637.tar.zst
pyecsca-f4bcb085cfc9ddac71fe8bb82e8f6719309b2637.zip
Exclude some lines from coverage.
Diffstat (limited to '')
-rw-r--r--test/ec/test_context.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/test/ec/test_context.py b/test/ec/test_context.py
index 51fefd7..9e56afb 100644
--- a/test/ec/test_context.py
+++ b/test/ec/test_context.py
@@ -1,8 +1,21 @@
+import ast
from unittest import TestCase
-from pyecsca.ec.context import local, DefaultContext
+from pyecsca.ec.context import local, DefaultContext, OpResult, NullContext, getcontext
+from pyecsca.ec.coordinates import AffineCoordinateModel
+from pyecsca.ec.mod import Mod
from pyecsca.ec.mult import LTRMultiplier
-from test.ec.curves import get_secp128r1
+from pyecsca.ec.point import Point
+from .curves import get_secp128r1
+
+
+class OpResultTests(TestCase):
+
+ def test_repr(self):
+ for op, char in zip((ast.Add(), ast.Sub(), ast.Mult(), ast.Div()), "+-*/"):
+ res = OpResult("X1", Mod(0, 5), op, Mod(2, 5), Mod(3, 5))
+ self.assertEqual(str(res), "X1")
+ self.assertEqual(repr(res), "X1 = 2{}3".format(char))
class ContextTests(TestCase):
@@ -15,9 +28,28 @@ class ContextTests(TestCase):
self.coords.formulas["dbl-1998-cmo"], self.coords.formulas["z"])
def test_null(self):
- self.mult.multiply(59, self.base)
+ with local() as ctx:
+ self.mult.multiply(59, self.base)
+ self.assertIsInstance(ctx, NullContext)
def test_default(self):
with local(DefaultContext()) as ctx:
self.mult.multiply(59, self.base)
self.assertEqual(len(ctx.actions), 10)
+
+ def test_execute(self):
+ with self.assertRaises(ValueError):
+ getcontext().execute(self.coords.formulas["z"], self.base, self.base)
+ with self.assertRaises(ValueError):
+ getcontext().execute(self.coords.formulas["z"],
+ Point(AffineCoordinateModel(self.secp128r1.curve.model),
+ x=Mod(1, 5), y=Mod(2, 5)))
+
+ def test_repr(self):
+ with local(DefaultContext()) as default:
+ self.mult.multiply(59, self.base)
+ str(default)
+ str(default.actions)
+ with local(NullContext()) as null:
+ self.mult.multiply(59, self.base)
+ str(null)