Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nose of yeti #135

Merged
merged 5 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ Alternatively tox may be used::
> cd modules
> tox

The tests are written using http://noseofyeti.readthedocs.io which is a project
that uses python codecs to create a basic RSpec style DSL for writing tests.

Tests are grouped by their module inside the ``tests`` folder. Note that we name
each folder as "<module>_tests" so that import statements for that module don't
get clobbered by these test files.
Expand All @@ -47,9 +44,6 @@ Code style
We use the black project (https://black.readthedocs.io/en/stable/) to format the
python code in this repository.

Note that because of the noseOfYeti tests, the environment needs a particular
version of black and also NOSE_OF_YETI_BLACK_COMPAT=true

All the developer needs to know is that either their editor is run in the same
session as a ``source run.sh activate`` or that they run::

Expand Down
14 changes: 6 additions & 8 deletions apps/interactor/tests/commander/commands/test_animation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: spec

import asyncio
from unittest import mock

Expand All @@ -13,9 +11,9 @@ def default_async_timeout() -> float:
return 15


describe "Animation Commands":
describe "V1":
async it "can get info and help", server:
class TestAnimationCommands:
class TestV1:
async def test_it_can_get_info_and_help(self, server):
await server.assertCommand(
"/v1/lifx/command",
{"command": "animation/info"},
Expand All @@ -38,7 +36,7 @@ def default_async_timeout() -> float:
assert "This animation has the following options:" in got
assert "colour range options" in got

async it "can control an animation", server:
async def test_it_can_control_an_animation(self, server):
await server.assertCommand(
"/v1/lifx/command",
{"command": "animation/info"},
Expand Down Expand Up @@ -153,7 +151,7 @@ def default_async_timeout() -> float:
assert info["animations"] == {identity2: mock.ANY}
assert info["paused"] == []

async it "pausing an animation actually pauses the animation", devices, server:
async def test_it_pausing_an_animation_actually_pauses_the_animation(self, devices, server):
tile = devices["tile"]
io = tile.io["MEMORY"]
store = devices.store(tile)
Expand Down Expand Up @@ -217,7 +215,7 @@ def default_async_timeout() -> float:
json_output={"animations": {}, "paused": []},
)

async it "can get information", server:
async def test_it_can_get_information(self, server):
# start
got = await server.assertCommand(
"/v1/lifx/command",
Expand Down
11 changes: 6 additions & 5 deletions apps/interactor/tests/commander/commands/test_clean.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# coding: spec

import asyncio
from unittest import mock

from photons_app import mimic

describe "Clean":
describe "v1":

async it "has v1 routes", async_timeout, devices: mimic.DeviceCollection, server, responses:
class TestClean:
class TestV1:

async def test_it_has_v1_routes(
self, async_timeout, devices: mimic.DeviceCollection, server, responses
):
async_timeout.set_timeout_seconds(15)

all_ok = {"results": {d.serial: "ok" for d in devices}}
Expand Down
17 changes: 8 additions & 9 deletions apps/interactor/tests/commander/commands/test_control.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# coding: spec

from unittest import mock

from photons_app.mimic.event import Events
from photons_control.colour import ColourParser
from photons_messages import DeviceMessages, LightMessages

describe "Control":
describe "v1":
async it "has query commands", devices, server, responses:

class TestControl:
class TestV1:
async def test_it_has_query_commands(self, devices, server, responses):
await server.assertCommand(
"/v1/lifx/command",
{"command": "query", "args": {"pkt_type": 101}},
Expand Down Expand Up @@ -65,7 +64,7 @@
json_output=responses.multizone_state_responses,
)

async it "has set commands", devices, server:
async def test_it_has_set_commands(self, devices, server):
expected = {"results": {device.serial: "ok" for device in devices}}

await server.assertCommand(
Expand Down Expand Up @@ -155,7 +154,7 @@
if device is not kitchen_light:
devices.store(device).assertNoSetMessages()

async it "has power_toggle command", devices, server:
async def test_it_has_power_toggle_command(self, devices, server):
expected = {"results": {device.serial: "ok" for device in devices}}

for device in devices:
Expand Down Expand Up @@ -229,7 +228,7 @@
)
devices.store(device).clear()

async it "has power_toggle group command", devices, server:
async def test_it_has_power_toggle_group_command(self, devices, server):
expected = {"results": {device.serial: "ok" for device in devices}}

await server.assertCommand(
Expand Down Expand Up @@ -286,7 +285,7 @@
)
devices.store(device).clear()

async it "has transform command", async_timeout, devices, server:
async def test_it_has_transform_command(self, async_timeout, devices, server):
async_timeout.set_timeout_seconds(5)
# Just power
expected = {"results": {device.serial: "ok" for device in devices}}
Expand Down
21 changes: 12 additions & 9 deletions apps/interactor/tests/commander/commands/test_discovery.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# coding: spec

import uuid

from photons_app import mimic

describe "Discovery":
describe "v1":
async it "has v1 routes", devices: mimic.DeviceCollection, server, responses:

class TestDiscovery:
class TestV1:
async def test_it_has_v1_routes(self, devices: mimic.DeviceCollection, server, responses):
await server.assertCommand(
"/v1/lifx/command",
{"command": "discover"},
Expand Down Expand Up @@ -67,23 +66,27 @@
"reply": [device.serial for device in devices],
}

describe "v2":
async it "GET /v2/discover/serials", devices: mimic.DeviceCollection, server, responses:
class TestV2:
async def test_it_GET_v2_discover_serials(
self, devices: mimic.DeviceCollection, server, responses
):
serials = await server.assertMethod("GET", "/v2/discover/serials")
assert sorted(serials) == sorted(device.serial for device in devices)

serials = await server.assertMethod("GET", "/v2/discover/serials/match:label=kitchen")
assert serials == ["d073d5000001"]

async it "GET /v2/discover/info", devices: mimic.DeviceCollection, server, responses:
async def test_it_GET_v2_discover_info(
self, devices: mimic.DeviceCollection, server, responses
):
await server.assertMethod(
"GET", "/v2/discover/info", json_output=responses.discovery_response
)

info = await server.assertMethod("GET", "/v2/discover/info/match:label=kitchen")
assert info == {"d073d5000001": responses.discovery_response["d073d5000001"]}

async it "PUT /v2/discover", devices: mimic.DeviceCollection, server, responses:
async def test_it_PUT_v2_discover(self, devices: mimic.DeviceCollection, server, responses):
await server.assertMethod(
"PUT",
"/v2/discover",
Expand Down
28 changes: 15 additions & 13 deletions apps/interactor/tests/commander/commands/test_effects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: spec

from unittest import mock

import pytest
Expand Down Expand Up @@ -391,9 +389,9 @@ def __init__(s):
return Results()


describe "Effects":
describe "v1":
async it "can start effects", server, results:
class TestEffects:
class TestV1:
async def test_it_can_start_effects(self, server, results):
results.effects_running["results"]["d073d5000008"]["effect"]["type"] = "MORPH"
palette = results.effects_running["results"]["d073d5000007"]["effect"]["options"][
"palette"
Expand Down Expand Up @@ -435,7 +433,7 @@ def __init__(s):
json_output=results.effects_stopped,
)

async it "can apply a theme first", server, results:
async def test_it_can_apply_a_theme_first(self, server, results):
await server.assertCommand(
"/v1/lifx/command",
{
Expand All @@ -449,7 +447,7 @@ def __init__(s):
json_output=results.success,
)

async it "can start just matrix effects", server, results:
async def test_it_can_start_just_matrix_effects(self, server, results):
await server.assertCommand(
"/v1/lifx/command",
{"command": "effects/status"},
Expand Down Expand Up @@ -500,7 +498,7 @@ def __init__(s):
json_output=results.effects_stopped,
)

async it "can start just linear effects", server, results:
async def test_it_can_start_just_linear_effects(self, server, results):
await server.assertCommand(
"/v1/lifx/command",
{"command": "effects/status"},
Expand Down Expand Up @@ -536,7 +534,7 @@ def __init__(s):
json_output=results.effects_stopped,
)

async it "can start linear effects and power on", devices, server, results:
async def test_it_can_start_linear_effects_and_power_on(self, devices, server, results):
for device in devices:
await device.change_one("power", 0, event=None)

Expand All @@ -553,7 +551,7 @@ def __init__(s):
if device.serial in ("d073d5000005", "d073d5000006"):
assert device.attrs.power == 65535

async it "can start matrix effects and power on", devices, server, results:
async def test_it_can_start_matrix_effects_and_power_on(self, devices, server, results):
for device in devices:
await device.change_one("power", 0, event=None)

Expand All @@ -570,7 +568,9 @@ def __init__(s):
if device.serial in ("d073d5000007", "d073d5000008"):
assert device.attrs.power == 65535

async it "can start matrix and linear effects without powering on", devices, server, results:
async def test_it_can_start_matrix_and_linear_effects_without_powering_on(
self, devices, server, results
):
for device in devices:
await device.change_one("power", 0, event=None)

Expand All @@ -591,7 +591,9 @@ def __init__(s):
for device in devices:
assert device.attrs.power == 0

async it "can stop matrix and linear effects without powering on", devices, server, results:
async def test_it_can_stop_matrix_and_linear_effects_without_powering_on(
self, devices, server, results
):
for device in devices:
await device.change_one("power", 0, event=None)

Expand All @@ -612,7 +614,7 @@ def __init__(s):
for device in devices:
assert device.attrs.power == 0

async it "works if devices are offline", devices, server, results, sender:
async def test_it_works_if_devices_are_offline(self, devices, server, results, sender):
offline1 = devices["d073d5000001"].offline()
offline5 = devices["d073d5000005"].offline()
offline7 = devices["d073d5000007"].offline()
Expand Down
10 changes: 4 additions & 6 deletions apps/interactor/tests/commander/commands/test_help.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: spec

import asyncio
from textwrap import dedent
from typing import ClassVar
Expand Down Expand Up @@ -100,9 +98,9 @@ async def server2(server_wrapper, final_future: asyncio.Future, sender: Communic
yield server


describe "commands":
describe "v1":
async it "has a help command", server2:
class TestCommands:
class TestV1:
async def test_it_has_a_help_command(self, server2):
want = dedent(
"""
Command test
Expand All @@ -129,7 +127,7 @@ async def server2(server_wrapper, final_future: asyncio.Future, sender: Communic
text_output=want,
)

async it "works for all commands as 200", server:
async def test_it_works_for_all_commands_as_200(self, server):
available: set[str] = set()
for cmd in server.server.store.commands:
if isinstance(cmd, _WithV1Http):
Expand Down
8 changes: 3 additions & 5 deletions apps/interactor/tests/commander/commands/test_progress_cb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: spec

import asyncio
import random

Expand Down Expand Up @@ -108,14 +106,14 @@ class Problem(InteractorError):
}


describe "Commands":
class TestCommands:

def command(self, command):
serial = "d073d5{:06d}".format(random.randrange(1, 9999))
cmd = {"command": command, "args": {"serial": serial}}
return cmd, serial

async it "has progress cb functionality for http", server:
async def test_it_has_progress_cb_functionality_for_http(self, server):
command, serial = self.command("test_no_error")
await server.assertCommand(
"/v1/lifx/command", command, status=200, json_output={"serial": serial}
Expand All @@ -131,7 +129,7 @@ def command(self, command):
"/v1/lifx/command", command, status=200, json_output={"serial": serial}
)

async it "has progress cb functionality for websockets", server:
async def test_it_has_progress_cb_functionality_for_websockets(self, server):
async with server.ws_stream() as stream:

# Done progress
Expand Down
8 changes: 3 additions & 5 deletions apps/interactor/tests/commander/commands/test_scenes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: spec

from unittest import mock

import pytest
Expand All @@ -12,9 +10,9 @@ async def start_database(server):
await conn.run_sync(server.server.database.Base.metadata.create_all)


describe "Scene":
describe "v1":
async it "has scene commands", async_timeout, devices, server, responses:
class TestScene:
class TestV1:
async def test_it_has_scene_commands(self, async_timeout, devices, server, responses):
# sqlite is very slow on github actions for some reason
async_timeout.set_timeout_seconds(20)

Expand Down
13 changes: 6 additions & 7 deletions apps/interactor/tests/commander/commands/test_status.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# coding: spec

from photons_app import mimic

describe "Status":
describe "v1":

async it "has v1 routes", devices: mimic.DeviceCollection, server, responses:
class TestStatus:
class TestV1:

async def test_it_has_v1_routes(self, devices: mimic.DeviceCollection, server, responses):
await server.assertCommand(
"/v1/lifx/command", {"command": "status"}, json_output={"on": True}
)

await server.assertMethod("GET", "/v1/lifx/status", json_output={"on": True})

describe "v2":
class TestV2:

async it "GET /v2/status", devices: mimic.DeviceCollection, server, responses:
async def test_it_GET_v2_status(self, devices: mimic.DeviceCollection, server, responses):
await server.assertMethod("GET", "/v2/status", json_output={"on": True})
Loading
Loading