11from js2pysecrets .decorators import JsFunction , jsNeedless
2- from js2pysecrets .wrapper import wrapper
2+ from js2pysecrets .wrapper import wrapper , chain
33
44import js2pysecrets .node as node
55import pytest
@@ -25,6 +25,11 @@ def invalidFunction(*args, **kwargs):
2525 pass
2626
2727
28+ @JsFunction
29+ def fail (* args , ** kwargs ):
30+ pass
31+
32+
2833@jsNeedless
2934def needless (* args , ** kwargs ):
3035 pass # pragma: no cover
@@ -34,13 +39,30 @@ def test_JsFunction():
3439 assert node .random (128 ) != node .random (32 )
3540
3641
42+ def test_noArgs ():
43+ assert node .init () == None
44+
45+
3746def test_jsNeedless ():
3847 assert not_supported (lambda : needless (33 , "blue" ))
3948
4049
4150def test_Distinct ():
42- command = node .share ("aabb" , 6 , 3 , distinct = True )
43- assert command == "share('aabb', 6, 3)"
51+ assert node .share ("aabb" , 6 , 3 , distinct = True ) == "share('aabb', 6, 3)"
52+ assert node .init (distinct = True ) == "init()"
53+
54+
55+ def test_Chain ():
56+ data = []
57+ data .append (node .setRNG ("testRandom" , distinct = True ))
58+ data .append (node .share ("aabb" , 6 , 3 , distinct = True ))
59+ data .append (node .share ("aabb" , 6 , 3 , distinct = True ))
60+ data .append (node .init (16 , distinct = True ))
61+ data .append (node .share ("aabb" , 6 , 3 , distinct = True ))
62+ data .append (node .share ("aabb" , 6 , 3 , distinct = True ))
63+ results = chain (data )
64+ assert results [1 ][4 ] == results [2 ][4 ]
65+ assert results [4 ][5 ] != results [5 ][5 ]
4466
4567
4668def test_Randomness ():
@@ -87,14 +109,14 @@ def test_CalledProcessError():
87109 assert "Invalid hex character" in str (caught_warnings [0 ].message )
88110
89111
90- # @pytest.mark.filterwarnings("ignore:fail")
91- # def test_JSONDecodeError():
92- # with warnings.catch_warnings(record=True) as caught_warnings:
93- # node. fail()
94- # # Check if any warnings were raised
95- # assert len(caught_warnings) == 1
96- # assert issubclass(caught_warnings[0].category, Warning)
97- # assert "error decoding JSON" in str(caught_warnings[0].message)
112+ @pytest .mark .filterwarnings ("ignore:fail" )
113+ def test_JSONDecodeError ():
114+ with warnings .catch_warnings (record = True ) as caught_warnings :
115+ fail (123 )
116+ # Check if any warnings were raised
117+ assert len (caught_warnings ) == 1
118+ assert issubclass (caught_warnings [0 ].category , Warning )
119+ assert "error decoding JSON" in str (caught_warnings [0 ].message )
98120
99121
100122# @pytest.mark.filterwarnings("ignore:wrapper")
0 commit comments