Skip to content

Commit

Permalink
update tests for asyncio
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed Jul 10, 2016
1 parent f00524c commit 67f8691
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
12 changes: 8 additions & 4 deletions mpf/platforms/openpixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import logging
import socket

import asyncio

from mpf.core.platform import LedPlatform
from mpf.platforms.interfaces.rgb_led_platform_interface import RGBLEDPlatformInterface

Expand Down Expand Up @@ -42,7 +44,7 @@ def initialize(self):
def stop(self):
"""Stop platform."""
# disconnect sender
self.opc_client.serial_sender.disconnect()
self.opc_client.serial_sender.close()

def configure_led(self, config, channels):
"""Configure an LED.
Expand Down Expand Up @@ -116,11 +118,13 @@ def __init__(self, machine, config):
self.serial_sender = None
self.channels = list()

#self.serial_sender = OPCSerialSender(self.machine, config)
connector = self.machine.clock.loop.create_connection(asyncio.Protocol, config['host'], config['port'])
self.serial_sender, _ = self.machine.clock.loop.run_until_complete(connector)

# Update the FadeCandy at a regular interval
self.machine.clock.schedule_interval(self.tick, 1 / self.machine.config['mpf']['default_led_hw_update_hz'])

self.serial_sender = OPCSerialSender(self.machine, config)

def add_pixel(self, channel, led):
"""Add a pixel to the list that will be sent to the OPC server.
Expand Down Expand Up @@ -207,7 +211,7 @@ def update_pixels(self, pixels, channel=0):

def send(self, message):
"""Send a message to the socket."""
self.serial_sender.send(message)
self.serial_sender.write(message)


class OPCSerialSender: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion mpf/tests/MpfTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import asyncio
import ruamel.yaml as yaml
from mpf.tmp.time_travel_util import TimeTravelLoop
from mpf.tests.loop import TimeTravelLoop

import mpf.core
import mpf.core.config_validator
Expand Down
8 changes: 3 additions & 5 deletions mpf/tests/test_OPP.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from mpf.platforms.opp import opp
from mpf.platforms.opp.opp_rs232_intf import OppRs232Intf
from mpf.tests.MpfTestCase import MpfTestCase
from mpf.tests.loop import MockSocket


class SerialMock:
class SerialMock(MockSocket):
def read(self, length):
del length
msg = self.queue.get()
Expand All @@ -21,7 +22,7 @@ def read_until(self, char):
del char
return self.read(123)

def ready(self):
def read_ready(self):
return not self.queue.empty()

def write(self, msg):
Expand All @@ -48,9 +49,6 @@ def __init__(self):
self.permanent_commands = {}
self.crashed = False

def close(self):
pass


class TestOPP(MpfTestCase):

Expand Down
3 changes: 0 additions & 3 deletions mpf/tests/test_Openpixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ def get_platform(self):

def setUp(self):
self._messages = []
self._opcthread = openpixel.OPCSerialSender
openpixel.OPCSerialSender = MagicMock()
self._send = openpixel.OpenPixelClient.send
openpixel.OpenPixelClient.send = self._send_mock
super().setUp()
self.assertOpenPixelLedsSent({}, {})

def tearDown(self):
super().tearDown()
openpixel.OPCSerialSender = self._opcthread
openpixel.OpenPixelClient.send = self._send

def _build_message(self, channel, leds):
Expand Down

0 comments on commit 67f8691

Please sign in to comment.