Compare commits
No commits in common. "c8dc6f70dc220e5155d7b8801a63b0fc23602884" and "92dea8c2decf27ddb283f016e5bb8b562f125229" have entirely different histories.
c8dc6f70dc
...
92dea8c2de
@ -1,82 +0,0 @@
|
|||||||
from dataclasses import dataclass
|
|
||||||
from typing import Optional, Collection, Any
|
|
||||||
from abc import abstractmethod
|
|
||||||
|
|
||||||
class DeviceLifecycleState:
|
|
||||||
pass # TODO(Homework #3)
|
|
||||||
|
|
||||||
|
|
||||||
class DevaceError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NonReadableTrait(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NonWritableTrait(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class TraitDescriptor:
|
|
||||||
name: str
|
|
||||||
info: Optional[str] = None
|
|
||||||
readable: bool = True
|
|
||||||
writable: bool = False
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class ActionDescriptor:
|
|
||||||
name: str
|
|
||||||
arguments: dict[str, type]
|
|
||||||
info: Optional[str] = None
|
|
||||||
|
|
||||||
|
|
||||||
class Device:
|
|
||||||
# TODO(Homework #3)
|
|
||||||
_state = DeviceLifecycleState.INIT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self) -> DeviceLifecycleState:
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
self._state = DeviceLifecycleState.CLOSE
|
|
||||||
|
|
||||||
def trait_descriptors(self) -> Collection[TraitDescriptor]:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def action_descriptors(self) -> Collection[ActionDescriptor]:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def __getitem__(self, trait_name: str) -> Optional[Any]:
|
|
||||||
"""Return logical state of trait `trait_name`."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class SynchronyDevice(Device):
|
|
||||||
|
|
||||||
def open(self):
|
|
||||||
self._state = DeviceLifecycleState.OPEN
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def execute(self, action_name: str, *args, **kwargs):
|
|
||||||
"""Execute action `action_name`, using `args` and `kwargs` as action argument."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def read(self, trait_name: str) -> Any:
|
|
||||||
"""Read physical state of trait `trait_name` from device."""
|
|
||||||
raise NonReadableTrait
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def write(self, trait_name: str, value: Any) -> bool:
|
|
||||||
"""Pass `value` to trait `trait_name` of device."""
|
|
||||||
raise NonWritableTrait
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def invalidate(self, trait_name: str):
|
|
||||||
"""Invalidate logical state of trait `trait_name`"""
|
|
||||||
pass
|
|
@ -1,8 +0,0 @@
|
|||||||
from turtle import Turtle
|
|
||||||
from controls.device import SynchronyDevice
|
|
||||||
|
|
||||||
class TurtleDevice(SynchronyDevice):
|
|
||||||
pass # TODO(Homework #3)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
from unittest import TestCase
|
|
||||||
|
|
||||||
from controls.device import DeviceLifecycleState
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceLifecycleStateTest(TestCase):
|
|
||||||
|
|
||||||
def setUp(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_enum(self):
|
|
||||||
self.assertEqual(DeviceLifecycleStateTest["INIT"], DeviceLifecycleStateTest.INIT)
|
|
@ -1,13 +0,0 @@
|
|||||||
from unittest import TestCase
|
|
||||||
|
|
||||||
from equipment.turtle_device import TurtleDevice
|
|
||||||
|
|
||||||
|
|
||||||
class TurtleDeviceTest(TestCase):
|
|
||||||
|
|
||||||
def setUp(self) -> None:
|
|
||||||
self.device = TurtleDevice()
|
|
||||||
|
|
||||||
def test_open(self):
|
|
||||||
self.device.open()
|
|
||||||
self.device.close()
|
|
Loading…
Reference in New Issue
Block a user