X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=tests%2Ftest_pyderasn.py;h=4febf7400a328699bba1d8d3cc17da131109df8f;hb=43726ca738a6ba3f16ae484d8fa4f1a6b89cbaf1;hp=4edf0608f61f544f9ca5a91d9e9bd9c714e77c39;hpb=6ffa181faaed35d38e9057c473363b5b6e44efd6;p=pyderasn.git diff --git a/tests/test_pyderasn.py b/tests/test_pyderasn.py index 4edf060..4febf74 100644 --- a/tests/test_pyderasn.py +++ b/tests/test_pyderasn.py @@ -32,6 +32,7 @@ from string import whitespace from time import mktime from time import time from unittest import TestCase +from unittest.mock import patch from dateutil.tz import UTC from hypothesis import assume @@ -122,6 +123,7 @@ from pyderasn import UTCTime from pyderasn import UTF8String from pyderasn import VideotexString from pyderasn import VisibleString +import pyderasn max_examples = environ.get("MAX_EXAMPLES") @@ -5061,6 +5063,14 @@ class TestUTCTime(TimeMixin, CommonMixin, TestCase): with self.assertRaisesRegex(ValueError, "only naive"): UTCTime(datetime(2000, 1, 1, 1, tzinfo=UTC)) + def test_raises_if_no_dateutil(self): + with patch("pyderasn.tzUTC", new="missing"): + with self.assertRaisesRegex(NotImplementedError, "dateutil"): + UTCTime(datetime.now()).totzdatetime() + + def test_tzinfo_gives_datetime_with_tzutc_tzinfo(self): + self.assertEqual(UTCTime(datetime.now()).totzdatetime().tzinfo, UTC) + @composite def tlv_value_strategy(draw): @@ -5936,7 +5946,7 @@ def sequences_strategy(draw, seq_klass): return seq_outer, expect_outers -class SeqMixing(object): +class SeqMixin(object): def test_invalid_value_type(self): with self.assertRaises(InvalidValueType) as err: self.base_klass(123) @@ -6450,7 +6460,7 @@ class SeqMixing(object): self.assertTrue(decoded.bered) -class TestSequence(SeqMixing, CommonMixin, TestCase): +class TestSequence(SeqMixin, CommonMixin, TestCase): base_klass = Sequence @given( @@ -6496,7 +6506,7 @@ class TestSequence(SeqMixing, CommonMixin, TestCase): self.assertEqual(seq["ok"], True) -class TestSet(SeqMixing, CommonMixin, TestCase): +class TestSet(SeqMixin, CommonMixin, TestCase): base_klass = Set @settings(max_examples=LONG_TEST_MAX_EXAMPLES) @@ -6611,7 +6621,7 @@ def seqof_values_strategy(draw, schema=None, do_expl=False): ) -class SeqOfMixing(object): +class SeqOfMixin(object): def test_invalid_value_type(self): with self.assertRaises(InvalidValueType) as err: self.base_klass(123) @@ -7081,7 +7091,7 @@ class SeqOfMixing(object): self.assertTrue(decoded.bered) -class TestSequenceOf(SeqOfMixing, CommonMixin, TestCase): +class TestSequenceOf(SeqOfMixin, CommonMixin, TestCase): class SeqOf(SequenceOf): schema = "whatever" base_klass = SeqOf @@ -7165,7 +7175,7 @@ class TestSequenceOf(SeqOfMixing, CommonMixin, TestCase): self.assertFalse(seqof.ready) -class TestSetOf(SeqOfMixing, CommonMixin, TestCase): +class TestSetOf(SeqOfMixin, CommonMixin, TestCase): class SeqOf(SetOf): schema = "whatever" base_klass = SeqOf @@ -7369,10 +7379,10 @@ class TestGoMarshalVectors(TestCase): seq["erste"] = PrintableString("test") self.assertSequenceEqual(seq.encode(), hexdec("3006130474657374")) # Asterisk is actually not allowable - PrintableString._allowable_chars |= set(b"*") + pyderasn.PRINTABLE_ALLOWABLE_CHARS |= set(b"*") seq["erste"] = PrintableString("test*") self.assertSequenceEqual(seq.encode(), hexdec("30071305746573742a")) - PrintableString._allowable_chars -= set(b"*") + pyderasn.PRINTABLE_ALLOWABLE_CHARS -= set(b"*") class Seq(Sequence): schema = (