Skip to content

Commit

Permalink
use recommended convention for testing that no warnings were raised
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Feb 24, 2023
1 parent 01022c8 commit a60fdf9
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/ecdsa/test_der.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,22 @@ def test_old_call_convention(self):

def test_new_call_convention(self):
"""This is how it should be called now."""
warnings.simplefilter("always")
with pytest.warns(None) as warns:
# make sure no warnings are raised
with warnings.catch_warnings():
warnings.simplefilter("error")
der = encode_bitstring(b"\xff", 0)

# verify that new call convention doesn't raise Warnings
self.assertEqual(len(warns), 0)

self.assertEqual(der, b"\x03\x02\x00\xff")

def test_implicit_unused_bits(self):
"""
Writing bit string with already included the number of unused bits.
"""
warnings.simplefilter("always")
with pytest.warns(None) as warns:
# make sure no warnings are raised
with warnings.catch_warnings():
warnings.simplefilter("error")
der = encode_bitstring(b"\x00\xff", None)

# verify that new call convention doesn't raise Warnings
self.assertEqual(len(warns), 0)

self.assertEqual(der, b"\x03\x02\x00\xff")

def test_explicit_unused_bits(self):
Expand Down Expand Up @@ -203,22 +199,20 @@ def test_old_call_convention(self):
self.assertEqual(rest, b"")

def test_new_call_convention(self):
warnings.simplefilter("always")
with pytest.warns(None) as warns:
# make sure no warnings are raised
with warnings.catch_warnings():
warnings.simplefilter("error")
bits, rest = remove_bitstring(b"\x03\x02\x00\xff", 0)

self.assertEqual(len(warns), 0)

self.assertEqual(bits, b"\xff")
self.assertEqual(rest, b"")

def test_implicit_unexpected_unused(self):
warnings.simplefilter("always")
with pytest.warns(None) as warns:
# make sure no warnings are raised
with warnings.catch_warnings():
warnings.simplefilter("error")
bits, rest = remove_bitstring(b"\x03\x02\x00\xff", None)

self.assertEqual(len(warns), 0)

self.assertEqual(bits, (b"\xff", 0))
self.assertEqual(rest, b"")

Expand Down

0 comments on commit a60fdf9

Please sign in to comment.