def test_fast_hand_object(self):
     op = object_packer.ObjectPackerJson(
         (tam_surface.TAMSurface, tam_colors.Color, tam_colors.RGBA))
     self._dump_and_check(
         op,
         tam_surface.TAMSurface(55, 67, "!", tam_colors.RED,
                                tam_colors.GREEN))
     self._dump_and_check(
         op,
         tam_surface.TAMSurface(21, 53, "C", tam_colors.BLUE,
                                tam_colors.YELLOW))
 def test_dict(self):
     op = object_packer.ObjectPackerJson()
     self._dump_and_check(
         op, {
             -44: -44,
             44.0: "lol",
             "cats": "dogs",
             None: "None",
             True: False,
             False: True
         })
Exemplo n.º 3
0
def run_tcp_connection(connection, io=None):
    """
    info: will run a tcp connection
    :param connection: TCPConnection
    :param io: IO or None: None will uses default IO
    :return: None
    """
    if io is None:
        io = tam_identifier.IO
    snapshot = io.get_snapshot()
    try:
        tcp.TCPObjectWrapper(
            connection, io,
            object_packer.ObjectPackerJson(
                (tam_colors.RGBA, tam_colors.Color, tam_surface.TAMSurface)))()
    except tcp.TCPError as error:
        log.warning("run_tcp_connection error: {}".format(error))
    except KeyboardInterrupt:
        log.critical("Caught KeyboardInterrupt")
    finally:
        io.apply_snapshot(snapshot)
        io.clear()
    def test_large_data(self):
        op = object_packer.ObjectPackerJson(
            (tam_surface.TAMSurface, tam_colors.Color, tam_colors.RGBA))
        data = [{
            "dict": {
                "surface 1":
                tam_surface.TAMSurface(55, 67, "!", tam_colors.RED,
                                       tam_colors.GREEN),
                "data": (bytearray((4, 5, 6, 7, 90)), bytes(), bytearray()),
                "surface 2":
                tam_surface.TAMSurface(53, 1, ")", tam_colors.LIGHT_YELLOW,
                                       tam_colors.GRAY)
            }
        }, {1, 2, 3, 4, "1", "4.4", None, (True, False)},
                [
                    tam_colors.COLOR_145, tam_colors.COLOR_142,
                    tam_colors.COLOR_149, "cats and dogs"
                ], (4, 5, (90, -3, "3", [])), None, False, True,
                "this is a test", 0.00001, tam_colors.COLOR_142,
                bytes((1, 2, 3, 4, 5, 6, 66, 55, 88, 12))]

        self._dump_and_check(op, data)
Exemplo n.º 5
0
def get_tcp_io(receiver, wait=True):
    """
    info: will return TCPObjectConnector connected to an io object
    :param receiver: TCPReceiver
    :param wait: bool
    :return: TCPObjectConnector
    """
    connection = receiver.get_host_connection(wait)
    if connection is not None:
        return tcp.TCPObjectConnector(
            connection,
            object_packer=object_packer.ObjectPackerJson(
                (tam_colors.RGBA, tam_colors.Color, tam_surface.TAMSurface)),
            no_return={
                "set_mode", "draw", "start", "done", "printc", "clear",
                "show_console_cursor", "set_color_2", "set_color_16_pal_256",
                "set_color_16", "set_color_256",
                "reset_colors_to_console_defaults", "set_tam_color_defaults",
                "enable_console_keys", "apply_snapshot", "enable_event_bus",
                "prime_event_bus"
            },
            optimizer={"draw"},
            none_generator={"get_event"})
 def test_str(self):
     op = object_packer.ObjectPackerJson()
     self._dump_and_check(op, "cats")
 def test_bool(self):
     op = object_packer.ObjectPackerJson()
     self._dump_and_check(op, True)
 def test_none(self):
     op = object_packer.ObjectPackerJson()
     self._dump_and_check(op, None)
 def test_bytearray(self):
     op = object_packer.ObjectPackerJson()
     self._dump_and_check(op, bytearray((100, 2, 3, 4, 55)))
Exemplo n.º 10
0
 def test_bytes(self):
     op = object_packer.ObjectPackerJson()
     self._dump_and_check(op, bytes((1, 200, 3, 44, 5)))
Exemplo n.º 11
0
 def test_set(self):
     op = object_packer.ObjectPackerJson()
     self._dump_and_check(op, {-44, 44.0, "cats", None, True, False})
Exemplo n.º 12
0
 def test_float(self):
     op = object_packer.ObjectPackerJson()
     self._dump_and_check(op, -44.0)