def test_compat_name(self): """ A warning is raised when using the codec's old name. """ with catch_warnings(record=True) as warnings: simple_filter('always', category=DeprecationWarning) self.assertEqual( # Provide the old codec name to :py:func:`encode`. encode(b'Hello, IOTA!', AsciiTrytesCodec.compat_name), b'RBTC9D9DCDQAEASBYBCCKBFA', ) self.assertEqual(len(warnings), 1) self.assertEqual(warnings[0].category, DeprecationWarning) self.assertIn('codec will be removed', text_type(warnings[0].message))
def test_as_string_deprecated(self): """ :py:meth:`TryteString.as_string` is deprecated in favor of :py:meth:`TryteString.decode`. """ trytes = TryteString(b'LH9GYEMHCF9GWHZFEELHVFOEOHNEEEWHZFUD') with catch_warnings(record=True) as caught_warnings: simple_filter('always', category=DeprecationWarning) decoded = trytes.as_string() self.assertEqual( [w.category for w in caught_warnings], [DeprecationWarning], ) self.assertEqual(decoded, '你好,世界!')
def test_as_bytes_deprecated(self): """ :py:meth:`TryteString.as_bytes` is deprecated in favor of :py:meth:`TryteString.encode`. """ trytes = TryteString(b'RBTC9D9DCDQAEASBYBCCKBFA') with catch_warnings(record=True) as caught_warnings: simple_filter('always', category=DeprecationWarning) encoded = trytes.as_bytes() self.assertEqual( [w.category for w in caught_warnings], [DeprecationWarning], ) self.assertEqual(encoded, b'Hello, IOTA!')
def test_from_string_deprecated(self): """ :py:meth:`TryteString.from_string` is deprecated in favor of :py:meth:`TryteString.from_unicode`. https://github.com/iotaledger/iota.lib.py/issues/90 """ with catch_warnings(record=True) as caught_warnings: simple_filter('always', category=DeprecationWarning) trytes = TryteString.from_string('你好,世界!') self.assertEqual( [w.category for w in caught_warnings], [DeprecationWarning], ) self.assertEqual( binary_type(trytes), b'LH9GYEMHCF9GWHZFEELHVFOEOHNEEEWHZFUD', )