HW3 complete #2
@ -1,31 +1,58 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import time
|
|
||||||
|
|
||||||
from equipment.turtle_device import TurtleDevice
|
from equipment.turtle_device import TurtleDevice
|
||||||
|
|
||||||
|
|
||||||
def test_setup():
|
def test_setup():
|
||||||
td = TurtleDevice() # не падает
|
td = TurtleDevice() # не падает
|
||||||
|
|
||||||
def test_read():
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("trait", "value"), [("DEFAULT_MODE", "standard"), ("DEFAULT_ANGLEOFFSET", 0.0)]
|
||||||
|
)
|
||||||
|
def test_read(trait, value):
|
||||||
td = TurtleDevice()
|
td = TurtleDevice()
|
||||||
assert td.read("DEFAULT_ANGLEOFFSET") == 0
|
assert td.read(trait) == value
|
||||||
|
|
||||||
def test_write():
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("trait", "value_to_pass"),
|
||||||
|
[
|
||||||
|
("DEFAULT_ANGLEOFFSET", 1),
|
||||||
|
("DEFAULT_ANGLEOFFSET", 2),
|
||||||
|
pytest.param("DEFAULT_ANGLEOFFSET", 3.0, marks=pytest.mark.xfail),
|
||||||
|
("DEFAULT_MODE", "other_mode"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_write(trait, value_to_pass):
|
||||||
td = TurtleDevice()
|
td = TurtleDevice()
|
||||||
value_to_pass = 10
|
td.write(trait, value_to_pass)
|
||||||
td.write("DEFAULT_ANGLEOFFSET", value_to_pass)
|
assert td[trait] == value_to_pass
|
||||||
assert td["DEFAULT_ANGLEOFFSET"] == value_to_pass
|
|
||||||
|
|
||||||
def test_invalidate():
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("trait", "value_to_pass"),
|
||||||
|
[
|
||||||
|
("DEFAULT_ANGLEOFFSET", 10),
|
||||||
|
("DEFAULT_MODE", "other mode"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_invalidate(trait, value_to_pass):
|
||||||
td = TurtleDevice()
|
td = TurtleDevice()
|
||||||
value_to_pass = 10
|
td.write(trait, value_to_pass)
|
||||||
td.write("DEFAULT_ANGLEOFFSET", value_to_pass)
|
assert td[trait] != td.read(trait)
|
||||||
td.invalidate("DEFAULT_ANGLEOFFSET") # сносит логическое значение
|
td.invalidate(trait) # сносит логическое значение
|
||||||
assert td["DEFAULT_ANGLEOFFSET"] == 0
|
assert td[trait] == td.read(trait)
|
||||||
|
|
||||||
def test_execute():
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("action", "args", "expected"),
|
||||||
|
[
|
||||||
|
("back", {"distance": 5.0}, (-5.0, 0.0)),
|
||||||
|
pytest.param("back", {"distance": 5.0}, (0.0, -5.0), marks=pytest.mark.xfail),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_execute(action, args, expected):
|
||||||
td = TurtleDevice()
|
td = TurtleDevice()
|
||||||
td.execute("back", **{"distance": 5.0})
|
td.execute(action, **args)
|
||||||
assert td.turtle.pos() == (-5.0 ,0.0)
|
assert td.turtle.pos() == expected
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user