Ejemplo n.º 1
0
    def test_encode_non_ascii_errors_strict(self):
        """
    Converting a sequence of trytes into bytes using the `encode`
    method yields non-ASCII characters, and errors='strict'.
    """
        trytes = TryteString(b'ZJVYUGTDRPDYFGFXMK')

        with self.assertRaises(TrytesDecodeError):
            trytes.encode(errors='strict')
Ejemplo n.º 2
0
    def test_encode_partial_sequence_errors_strict(self):
        """
    Attempting to convert an odd number of trytes into bytes using the
    `encode` method with errors='strict'.
    """
        trytes = TryteString(b'RBTC9D9DCDQAEASBYBCCKBFA9')

        with self.assertRaises(TrytesDecodeError):
            trytes.encode(errors='strict')
Ejemplo n.º 3
0
    def test_encode(self):
        """
    Converting a sequence of trytes into a sequence of bytes.
    """
        trytes = TryteString(b'RBTC9D9DCDQAEASBYBCCKBFA')

        self.assertEqual(trytes.encode(), b'Hello, IOTA!')
Ejemplo n.º 4
0
    def test_encode_non_ascii_errors_replace(self):
        """
    Converting a sequence of trytes into bytes using the `encode`
    method yields non-ASCII characters, and errors='replace'.
    """
        trytes = TryteString(b'ZJVYUGTDRPDYFGFXMK')

        self.assertEqual(
            trytes.encode(errors='replace'),
            b'??\xd2\x80??\xc3??',
        )
Ejemplo n.º 5
0
    def test_encode_partial_sequence_errors_replace(self):
        """
    Attempting to convert an odd number of trytes into bytes using the
    `encode` method with errors='replace'.
    """
        trytes = TryteString(b'RBTC9D9DCDQAEASBYBCCKBFA9')

        self.assertEqual(
            trytes.encode(errors='replace'),

            # The extra tryte is replaced with '?'.
            b'Hello, IOTA!?',
        )