@@ -153,15 +153,17 @@ def test_load(self):
153153 self .assertEqual (C .output (['path' ]),
154154 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme' )
155155 cookie_encoded = base64 .b64encode (b'Customer="WILE_E_COYOTE"; Path=/acme; Version=1' ).decode ('ascii' )
156- self .assertEqual (C .js_output (), fr"""
156+ with self .assertWarnsRegex (DeprecationWarning , r"BaseCookie\.js_output" ):
157+ self .assertEqual (C .js_output (), fr"""
157158 <script type="text/javascript">
158159 <!-- begin hiding
159160 document.cookie = atob("{ cookie_encoded } ");
160161 // end hiding -->
161162 </script>
162163 """ )
163164 cookie_encoded = base64 .b64encode (b'Customer="WILE_E_COYOTE"; Path=/acme' ).decode ('ascii' )
164- self .assertEqual (C .js_output (['path' ]), fr"""
165+ with self .assertWarnsRegex (DeprecationWarning , r"BaseCookie\.js_output" ):
166+ self .assertEqual (C .js_output (['path' ]), fr"""
165167 <script type="text/javascript">
166168 <!-- begin hiding
167169 document.cookie = atob("{ cookie_encoded } ");
@@ -270,15 +272,17 @@ def test_quoted_meta(self):
270272 self .assertEqual (C .output (['path' ]),
271273 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme' )
272274 expected_encoded_cookie = base64 .b64encode (b'Customer=\" WILE_E_COYOTE\" ; Path=/acme; Version=1' ).decode ('ascii' )
273- self .assertEqual (C .js_output (), fr"""
275+ with self .assertWarnsRegex (DeprecationWarning , r"BaseCookie\.js_output" ):
276+ self .assertEqual (C .js_output (), fr"""
274277 <script type="text/javascript">
275278 <!-- begin hiding
276279 document.cookie = atob("{ expected_encoded_cookie } ");
277280 // end hiding -->
278281 </script>
279282 """ )
280283 expected_encoded_cookie = base64 .b64encode (b'Customer=\" WILE_E_COYOTE\" ; Path=/acme' ).decode ('ascii' )
281- self .assertEqual (C .js_output (['path' ]), fr"""
284+ with self .assertWarnsRegex (DeprecationWarning , r"BaseCookie\.js_output" ):
285+ self .assertEqual (C .js_output (['path' ]), fr"""
282286 <script type="text/javascript">
283287 <!-- begin hiding
284288 document.cookie = atob("{ expected_encoded_cookie } ");
@@ -382,7 +386,8 @@ def test_setter(self):
382386 // end hiding -->
383387 </script>
384388 """ % (expected_encoded_cookie ,)
385- self .assertEqual (M .js_output (), expected_js_output )
389+ with self .assertWarnsRegex (DeprecationWarning , r"Morsel\.js_output" ):
390+ self .assertEqual (M .js_output (), expected_js_output )
386391 for i in ["foo bar" , "foo@bar" ]:
387392 # Try some illegal characters
388393 self .assertRaises (cookies .CookieError ,
@@ -650,16 +655,38 @@ def test_control_characters_output(self):
650655 cookie = cookies .SimpleCookie ()
651656 cookie ["cookie" ] = morsel
652657 with self .assertRaises (cookies .CookieError ):
653- cookie .js_output ()
658+ with self .assertWarnsRegex (DeprecationWarning , r"Morsel\.js_output" ):
659+ cookie .js_output ()
654660
655661 morsel = cookies .Morsel ()
656662 morsel .set ("key" , "value" , "coded-value" )
657663 morsel ._coded_value = c0 # Override private variable.
658664 cookie = cookies .SimpleCookie ()
659665 cookie ["cookie" ] = morsel
660666 with self .assertRaises (cookies .CookieError ):
661- cookie .js_output ()
667+ with self .assertWarnsRegex (DeprecationWarning , r"Morsel\.js_output" ):
668+ cookie .js_output ()
662669
670+ def test_morsel_js_output_deprecated (self ):
671+ morsel = cookies .Morsel ()
672+ morsel .set ("key" , "value" , "value" )
673+ with self .assertWarnsRegex (DeprecationWarning , r"Morsel\.js_output" ) as cm :
674+ result = morsel .js_output ()
675+ self .assertEqual (cm .filename , __file__ )
676+ self .assertIn ("document.cookie" , result )
677+
678+
679+ def test_basecookie_js_output_warns_once (self ):
680+ C = cookies .SimpleCookie ()
681+ C ["key" ] = "value"
682+ with self .assertWarns (DeprecationWarning ) as cm :
683+ C .js_output ()
684+ deprecation_warnings = [
685+ w for w in cm .warnings if issubclass (w .category , DeprecationWarning )
686+ ]
687+ self .assertEqual (len (deprecation_warnings ), 1 )
688+ self .assertRegex (str (deprecation_warnings [0 ].message ), r"BaseCookie\.js_output" )
689+ self .assertEqual (cm .filename , __file__ )
663690
664691def load_tests (loader , tests , pattern ):
665692 tests .addTest (doctest .DocTestSuite (cookies ))
0 commit comments