Пример #1
0
    def test_decode_sdata_error(self):
        """
        decode_sdata should raise exception if input data is not
        base16 byte string.
        """
        from garage.utils import decode_sdata

        self._msg("test", "decode_sdata", first=True)

        data = ["<abc>", "écriture", "寫作"]
        result = decode_sdata(data)
        expected = None
        self._msg("data", data)
        self._msg("expected", expected)
        self._msg("result", result)
        self.assertEqual(result, expected)

        data = "écriture 寫作"
        result = decode_sdata(data)
        expected = None
        self._msg("data", data)
        self._msg("expected", expected)
        self._msg("result", result)
        self.assertEqual(result, expected)

        data = b"286C70300A4930"
        result = decode_sdata(data)
        expected = None
        self._msg("data", data)
        self._msg("expected", expected)
        self._msg("result", result)
        self.assertEqual(result, expected)
Пример #2
0
    def test_decode_sdata(self):
        """
        Ensure decode_sdata function is working properly.
        """
        from garage.utils import decode_sdata

        self._msg("test", "decode_sdata", first=True)

        data = b"5674686973206973206120746573740A70310A2E"
        result = decode_sdata(data)
        expected = "this is a test"
        self._msg("data", data)
        self._msg("expected", expected)
        self._msg("result", result)
        self._msg("expected type", type(expected))
        self._msg("result type", type(result))
        self.assertEqual(result, expected)
        self.assertEqual(type(result), type(expected))

        data = b"56686520736169642C2022712026206122203C6162633E20E963726974757265205C75356265625C75346635630A70310A2E"
        result = decode_sdata(data)
        expected = 'he said, "q & a" <abc> écriture 寫作'
        self._msg("data", data)
        self._msg("expected", expected)
        self._msg("result", result)
        self._msg("expected type", type(expected))
        self._msg("result type", type(result))
        self.assertEqual(result, expected)
        self.assertEqual(type(result), type(expected))

        data = b"286C70310A49300A6149310A6149320A6149330A6149340A612E"
        result = decode_sdata(data)
        expected = [n for n in range(5)]
        self._msg("data", data)
        self._msg("expected", expected)
        self._msg("result", result)
        self._msg("expected type", type(expected))
        self._msg("result type", type(result))
        self.assertEqual(result, expected)
        self.assertEqual(type(result), type(expected))