bpo-36582: Make collections.UserString.encode() return bytes, not str (GH-13138) (GH-15557)

(cherry picked from commit 2a16eea71f56c2d8f38c295c8ce71a9a9a140aff)

Co-authored-by: Daniel Fortunov <asqui@users.noreply.github.com>
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py
index 19b0acf..4d1d8b6 100644
--- a/Lib/test/test_userstring.py
+++ b/Lib/test/test_userstring.py
@@ -51,6 +51,20 @@
         str3 = ustr3('TEST')
         self.assertEqual(fmt2 % str3, 'value is TEST')
 
+    def test_encode_default_args(self):
+        self.checkequal(b'hello', 'hello', 'encode')
+        # Check that encoding defaults to utf-8
+        self.checkequal(b'\xf0\xa3\x91\x96', '\U00023456', 'encode')
+        # Check that errors defaults to 'strict'
+        self.checkraises(UnicodeError, '\ud800', 'encode')
+
+    def test_encode_explicit_none_args(self):
+        self.checkequal(b'hello', 'hello', 'encode', None, None)
+        # Check that encoding defaults to utf-8
+        self.checkequal(b'\xf0\xa3\x91\x96', '\U00023456', 'encode', None, None)
+        # Check that errors defaults to 'strict'
+        self.checkraises(UnicodeError, '\ud800', 'encode', None, None)
+
 
 if __name__ == "__main__":
     unittest.main()