diff --git a/generator/generator.py b/generator/generator.py deleted file mode 100644 index 8814a8d..0000000 --- a/generator/generator.py +++ /dev/null @@ -1,279 +0,0 @@ -from datetime import datetime -import json -import os -import re - -DATE = datetime.now() - -OUT = """\"\"\" -Class object for {classname} -Documentation: {documentation} - -Generated by generator/generator.py - {date} -\"\"\" -from Lyric.objects.objects.base import LyricBase - -{inherit} -""" - -CLASS = """ -class {classname}(LyricBase): -{properties} -""" - -PROP = """ - @property - def {key}(self): - return self.attributes.get("{key}", {default}) -""" -PROPCLASS = """ - @property - def {key}(self): - return {name}(self.attributes.get("{key}", {default})) -""" -PROPLISTCLASS = """ - @property - def {key}(self): - return [{name}(x) for x in self.attributes.get("{key}", [])] -""" - -FIXSTURE = """\"\"\" -Generated by generator/generator.py - {date} -\"\"\" -import pytest - - -@pytest.fixture() -def {name}(): - return {content} -""" - -TEST = """\"\"\" -Generated by generator/generator.py - {date} -\"\"\" -from {importfile} import {importclass} -from {fixturefile} import {fixture} - -def {testname}({fixture}): - obj = {importclass}({fixture}) -{assertions} -""" - -INHERIT = [] - - -def get_input(): - with open("generator/input.json") as inputdata: - return json.loads(inputdata.read()) - - -def generateclass(name, data, primary=False): - properties = [] - # print(data) - for key in data: - print(key) - if key.startswith("_"): - continue - if isinstance(data[key], list): - if not isinstance(data[key][0], dict) and not isinstance( - data[key][0], list - ): - properties.append(PROP.format(key=key, default=[])) - continue - _name = key.split("_") - _name = "".join([x.title() for x in _name]) - _name = f"{_name}" - INHERIT.append(generateclass(_name, data[key][0])) - properties.append(PROPLISTCLASS.format(name=_name, key=key)) - continue - if isinstance(data[key], dict): - _name = key.split("_") - _name = "".join([x.title() for x in _name]) - _name = f"{name}{_name}" - INHERIT.append(generateclass(_name, data[key])) - properties.append(PROPCLASS.format(name=_name, key=key, default={})) - continue - if isinstance(data[key], bool): - properties.append(PROP.format(key=key, default=data[key])) - continue - if isinstance(data[key], str): - properties.append(PROP.format(key=key, default='""')) - continue - properties.append(PROP.format(key=key, default=None)) - - if not primary: - return CLASS.format(classname=name, properties="".join(properties)) - docs = input("Documentation URL: ") - classname = input("Main Classname: ") - INHERIT.append( - CLASS.format(classname=f"Lyric{classname}", properties="".join(properties)) - ) - - objectfilename = f"aiolyric/objects/{'/'.join([x.lower() for x in re.findall('[A-Z][a-z]*', classname)])}.py" - if not os.path.exists(os.path.dirname(objectfilename)): - os.makedirs(os.path.dirname(objectfilename)) - with open(os.path.join(os.path.dirname(objectfilename), "__init__.py")) as f: - f.write() - - with open( - objectfilename, - "w", - ) as objfile: - objfile.write( - OUT.format( - classname=f"Lyric{classname}", - properties=properties, - documentation=docs, - inherit="".join(INHERIT), - date=DATE, - ) - ) - - fixturefilename = f"tests/responses/{'/'.join([x.lower() for x in re.findall('[A-Z][a-z]*', classname)])}_fixture.py" - fixturename = f"{fixturefilename.split('/')[-1].replace('.py', '')}_response" - - if not os.path.exists(os.path.dirname(fixturefilename)): - os.makedirs(os.path.dirname(fixturefilename)) - with open( - fixturefilename, - "w", - ) as fixturefile: - fixturefile.write( - FIXSTURE.format( - name=fixturename, - content=data, - date=DATE, - ) - ) - - tmpfilename = [x.lower() for x in re.findall("[A-Z][a-z]*", classname)] - tmpr = tmpfilename.pop() - tmpfilename.append(f"test_{tmpr}") - testfilename = f"tests/objects/{'/'.join(tmpfilename)}.py" - testname = f"test_{tmpr}" - assertions = [] - - for key in data: - if key.startswith("_"): - continue - if not isinstance(data[key], (dict, list)): - assertions.append(f" assert obj.{key} == {fixturename}['{key}']") - if isinstance(data[key], list): - if not isinstance(data[key][0], (dict, list)): - assertions.append( - f" assert obj.{key}[0] == {fixturename}['{key}'][0]" - ) - if isinstance(data[key][0], dict): - for sakey in data[key][0]: - assertions.append( - f" assert obj.{key}[0].{sakey} == {fixturename}['{key}'][0]['{sakey}']" - ) - if isinstance(data[key], dict): - for akey in data[key]: - if not isinstance(data[key][akey], (dict, list)): - assertions.append( - f" assert obj.{key}.{akey} == {fixturename}['{key}']['{akey}']" - ) - if isinstance(data[key][akey], list): - if not isinstance(data[key][akey][0], (dict, list)): - assertions.append( - f" assert obj.{key}.{akey}[0] == {fixturename}['{key}']['{akey}'][0]" - ) - if isinstance(data[key][akey][0], dict): - for sakey in data[key][akey][0]: - assertions.append( - f" assert obj.{key}.{akey}[0].{sakey} == {fixturename}['{key}']['{akey}'][0]['{sakey}']" - ) - if isinstance(data[key][akey], dict): - for bkey in data[key][akey]: - if not isinstance(data[key][akey][bkey], (dict, list)): - assertions.append( - f" assert obj.{key}.{akey}.{bkey} == {fixturename}['{key}']['{akey}']['{bkey}']" - ) - if isinstance(data[key][akey][bkey], list): - if not isinstance(data[key][akey][bkey][0], (dict, list)): - assertions.append( - f" assert obj.{key}.{akey}.{bkey}[0] == {fixturename}['{key}']['{akey}']['{bkey}'][0]" - ) - if isinstance(data[key][akey][bkey][0], dict): - for sakey in data[key][akey][bkey][0]: - assertions.append( - f" assert obj.{key}.{akey}.{bkey}[0].{sakey} == {fixturename}['{key}']['{akey}']['{bkey}'][0]['{sakey}']" - ) - if isinstance(data[key][akey][bkey], dict): - for ckey in data[key][akey][bkey]: - if not isinstance( - data[key][akey][bkey][ckey], (dict, list) - ): - assertions.append( - f" assert obj.{key}.{akey}.{bkey}.{ckey} == {fixturename}['{key}']['{akey}']['{bkey}']['{ckey}']" - ) - if isinstance(data[key][akey][bkey][ckey], list): - if not isinstance( - data[key][akey][bkey][ckey][0], (dict, list) - ): - assertions.append( - f" assert obj.{key}.{akey}.{bkey}.{ckey}[0] == {fixturename}['{key}']['{akey}']['{bkey}']['{ckey}'][0]" - ) - if isinstance(data[key][akey][bkey][ckey][0], dict): - for sakey in data[key][akey][bkey][ckey][0]: - assertions.append( - f" assert obj.{key}.{akey}.{bkey}.{ckey}[0].{sakey} == {fixturename}['{key}']['{akey}']['{bkey}']['{ckey}'][0]['{sakey}']" - ) - if isinstance(data[key][akey][bkey][ckey], dict): - for dkey in data[key][akey][bkey][ckey]: - if not isinstance( - data[key][akey][bkey][ckey][dkey], - (dict, list), - ): - - assertions.append( - f" assert obj.{key}.{akey}.{bkey}.{ckey}.{dkey} == {fixturename}['{key}']['{akey}']['{bkey}']['{ckey}']['{dkey}']" - ) - if isinstance( - data[key][akey][bkey][ckey][dkey], list - ): - if not isinstance( - data[key][akey][bkey][ckey][dkey][0], - (dict, list), - ): - assertions.append( - f" assert obj.{key}.{akey}.{bkey}.{ckey}.{dkey}[0] == {fixturename}['{key}']['{akey}']['{bkey}']['{ckey}']['{dkey}'][0]" - ) - if isinstance( - data[key][akey][bkey][ckey][dkey][0], - dict, - ): - for sakey in data[key][akey][bkey][ - ckey - ][dkey][0]: - assertions.append( - f" assert obj.{key}.{akey}.{bkey}.{ckey}.{dkey}[0].{sakey} == {fixturename}['{key}']['{akey}']['{bkey}']['{ckey}']['{dkey}'][0]['{sakey}']" - ) - continue - - if not os.path.exists(os.path.dirname(testfilename)): - os.makedirs(os.path.dirname(testfilename)) - with open( - testfilename, - "w", - ) as fixturefile: - fixturefile.write( - TEST.format( - importfile=".".join(objectfilename.replace(".py", "").split("/")), - importclass=f"Lyric{classname}", - fixturefile=".".join(fixturefilename.replace(".py", "").split("/")), - fixture=fixturename, - testname=testname, - assertions="\n".join(assertions), - date=DATE, - ) - ) - - -def add_object(): - data = get_input() - generateclass("", data, True) - - -add_object() diff --git a/tests/objects/test_device.py b/tests/objects/test_device.py index c3e409a..22a1875 100644 --- a/tests/objects/test_device.py +++ b/tests/objects/test_device.py @@ -1,10 +1,14 @@ -"""Generated by generator/generator.py - 2020-08-31 14:06:02.854691 -""" +"""Test device object.""" + from aiolyric.objects.device import LyricDevice def test_device(device_fixture_response): - obj = LyricDevice(None, device_fixture_response) + """Test device object.""" + obj = LyricDevice( + None, + device_fixture_response, + ) assert obj.locationID == device_fixture_response["locationID"] assert ( obj.displayedOutdoorHumidity diff --git a/tests/objects/test_location.py b/tests/objects/test_location.py index 7f3224a..c750642 100644 --- a/tests/objects/test_location.py +++ b/tests/objects/test_location.py @@ -1,10 +1,14 @@ -"""Generated by generator/generator.py - 2020-08-31 13:55:49.220121 -""" +"""Tests for the location object""" + from aiolyric.objects.location import LyricLocation def test_location(location_fixture_response): - obj = LyricLocation(None, location_fixture_response) + """Test location object.""" + obj = LyricLocation( + None, + location_fixture_response, + ) assert obj.locationID == location_fixture_response["locationID"] assert obj.name == location_fixture_response["name"] assert obj.country == location_fixture_response["country"] @@ -27,11 +31,15 @@ def test_location(location_fixture_response): ) assert ( obj.devices[0].scheduleCapabilities.availableScheduleTypes - == location_fixture_response["devices"][0]["scheduleCapabilities"]["availableScheduleTypes"] + == location_fixture_response["devices"][0]["scheduleCapabilities"][ + "availableScheduleTypes" + ] ) assert ( obj.devices[0].scheduleCapabilities.schedulableFan - == location_fixture_response["devices"][0]["scheduleCapabilities"]["schedulableFan"] + == location_fixture_response["devices"][0]["scheduleCapabilities"][ + "schedulableFan" + ] ) assert ( obj.devices[0].scheduleType.scheduleType @@ -51,11 +59,15 @@ def test_location(location_fixture_response): ) assert ( obj.devices[0].settings.hardwareSettings.brightness - == location_fixture_response["devices"][0]["settings"]["hardwareSettings"]["brightness"] + == location_fixture_response["devices"][0]["settings"]["hardwareSettings"][ + "brightness" + ] ) assert ( obj.devices[0].settings.hardwareSettings.maxBrightness - == location_fixture_response["devices"][0]["settings"]["hardwareSettings"]["maxBrightness"] + == location_fixture_response["devices"][0]["settings"]["hardwareSettings"][ + "maxBrightness" + ] ) assert ( obj.devices[0].settings.temperatureMode.air @@ -87,7 +99,10 @@ def test_location(location_fixture_response): == location_fixture_response["devices"][0]["isProvisioned"] ) assert obj.devices[0].macID == location_fixture_response["devices"][0]["macID"] - assert obj.devices[0].service.mode == location_fixture_response["devices"][0]["service"]["mode"] + assert ( + obj.devices[0].service.mode + == location_fixture_response["devices"][0]["service"]["mode"] + ) assert ( obj.devices[0].deviceRegistrationDate == location_fixture_response["devices"][0]["deviceRegistrationDate"] @@ -146,7 +161,9 @@ def test_location(location_fixture_response): ) assert ( obj.devices[0].changeableValues.thermostatSetpointStatus - == location_fixture_response["devices"][0]["changeableValues"]["thermostatSetpointStatus"] + == location_fixture_response["devices"][0]["changeableValues"][ + "thermostatSetpointStatus" + ] ) assert ( obj.devices[0].changeableValues.nextPeriodTime @@ -158,11 +175,15 @@ def test_location(location_fixture_response): ) assert ( obj.devices[0].changeableValues.endHeatSetpoint - == location_fixture_response["devices"][0]["changeableValues"]["endHeatSetpoint"] + == location_fixture_response["devices"][0]["changeableValues"][ + "endHeatSetpoint" + ] ) assert ( obj.devices[0].changeableValues.endCoolSetpoint - == location_fixture_response["devices"][0]["changeableValues"]["endCoolSetpoint"] + == location_fixture_response["devices"][0]["changeableValues"][ + "endCoolSetpoint" + ] ) assert ( obj.devices[0].operationStatus.mode @@ -174,7 +195,9 @@ def test_location(location_fixture_response): ) assert ( obj.devices[0].operationStatus.circulationFanRequest - == location_fixture_response["devices"][0]["operationStatus"]["circulationFanRequest"] + == location_fixture_response["devices"][0]["operationStatus"][ + "circulationFanRequest" + ] ) assert ( obj.devices[0].deviceModel @@ -201,7 +224,9 @@ def test_location(location_fixture_response): ) assert ( obj.users[0].locationRoleMapping[0].locationName - == location_fixture_response["users"][0]["locationRoleMapping"][0]["locationName"] + == location_fixture_response["users"][0]["locationRoleMapping"][0][ + "locationName" + ] ) assert ( obj.users[0].locationRoleMapping[0].status diff --git a/tests/objects/test_priority.py b/tests/objects/test_priority.py index 0a3ef49..17faff4 100644 --- a/tests/objects/test_priority.py +++ b/tests/objects/test_priority.py @@ -1,17 +1,42 @@ -"""Generated by generator/generator.py - 2023-07-27 18:30:29.139453 -""" +"""Tests for the Priority object.""" + from aiolyric.objects.priority import LyricPriority def test_priority(priority_fixture_response): + """Test priority object.""" obj = LyricPriority(priority_fixture_response) assert obj.deviceId == priority_fixture_response["deviceId"] assert obj.status == priority_fixture_response["status"] - assert obj.currentPriority.priorityType == priority_fixture_response["currentPriority"]["priorityType"] - assert obj.currentPriority.selectedRooms[0] == priority_fixture_response["currentPriority"]["selectedRooms"][0] - assert obj.currentPriority.rooms[0].id == priority_fixture_response["currentPriority"]["rooms"][0]["id"] - assert obj.currentPriority.rooms[0].roomName == priority_fixture_response["currentPriority"]["rooms"][0]["roomName"] - assert obj.currentPriority.rooms[0].roomAvgTemp == priority_fixture_response["currentPriority"]["rooms"][0]["roomAvgTemp"] - assert obj.currentPriority.rooms[0].roomAvgHumidity == priority_fixture_response["currentPriority"]["rooms"][0]["roomAvgHumidity"] - assert obj.currentPriority.rooms[0].overallMotion == priority_fixture_response["currentPriority"]["rooms"][0]["overallMotion"] - assert obj.currentPriority.rooms[0].accessories == priority_fixture_response["currentPriority"]["rooms"][0]["accessories"] + assert ( + obj.currentPriority.priorityType + == priority_fixture_response["currentPriority"]["priorityType"] + ) + assert ( + obj.currentPriority.selectedRooms[0] + == priority_fixture_response["currentPriority"]["selectedRooms"][0] + ) + assert ( + obj.currentPriority.rooms[0].id + == priority_fixture_response["currentPriority"]["rooms"][0]["id"] + ) + assert ( + obj.currentPriority.rooms[0].roomName + == priority_fixture_response["currentPriority"]["rooms"][0]["roomName"] + ) + assert ( + obj.currentPriority.rooms[0].roomAvgTemp + == priority_fixture_response["currentPriority"]["rooms"][0]["roomAvgTemp"] + ) + assert ( + obj.currentPriority.rooms[0].roomAvgHumidity + == priority_fixture_response["currentPriority"]["rooms"][0]["roomAvgHumidity"] + ) + assert ( + obj.currentPriority.rooms[0].overallMotion + == priority_fixture_response["currentPriority"]["rooms"][0]["overallMotion"] + ) + assert ( + obj.currentPriority.rooms[0].accessories + == priority_fixture_response["currentPriority"]["rooms"][0]["accessories"] + ) diff --git a/tests/responses/device_fixture.py b/tests/responses/device_fixture.py index 02819ae..21cab58 100644 --- a/tests/responses/device_fixture.py +++ b/tests/responses/device_fixture.py @@ -1,10 +1,11 @@ -"""Generated by generator/generator.py - 2020-08-31 14:06:02.854691 -""" +"""Fixtures for device tests.""" + import pytest @pytest.fixture() def device_fixture_response(): + """Return a fixture response for a device.""" return { "locationID": 123456, "displayedOutdoorHumidity": 51, diff --git a/tests/responses/location_fixture.py b/tests/responses/location_fixture.py index 3ead353..3d7e6c8 100644 --- a/tests/responses/location_fixture.py +++ b/tests/responses/location_fixture.py @@ -1,10 +1,11 @@ -"""Generated by generator/generator.py - 2020-08-31 13:55:49.220121 -""" +"""Fixtures for location responses.""" + import pytest @pytest.fixture() def location_fixture_response(): + """Return a fixture response for a location.""" return { "locationID": 123456, "name": "Home", diff --git a/tests/responses/priority_fixture.py b/tests/responses/priority_fixture.py index fbb883f..6157e37 100644 --- a/tests/responses/priority_fixture.py +++ b/tests/responses/priority_fixture.py @@ -1,18 +1,17 @@ -"""Generated by generator/generator.py - 2023-07-27 18:30:29.139453 -""" +"""Fixture for priority response.""" + import pytest @pytest.fixture() def priority_fixture_response(): + """Return a fixture response for a priority.""" return { "deviceId": "00A01AB1ABCD", "status": "NoHold", "currentPriority": { "priorityType": "PickARoom", - "selectedRooms": [ - 0 - ], + "selectedRooms": [0], "rooms": [ { "id": 0, @@ -28,9 +27,9 @@ def priority_fixture_response(): "excludeMotion": False, "temperature": 75.828, "status": "Ok", - "detectMotion": False + "detectMotion": False, } - ] + ], }, { "id": 1, @@ -46,9 +45,9 @@ def priority_fixture_response(): "excludeMotion": False, "temperature": 76, "status": "Ok", - "detectMotion": True + "detectMotion": True, } - ] + ], }, { "id": 2, @@ -64,10 +63,10 @@ def priority_fixture_response(): "excludeMotion": False, "temperature": 76, "status": "Ok", - "detectMotion": True + "detectMotion": True, } - ] - } - ] - } + ], + }, + ], + }, } diff --git a/tests/test__version.py b/tests/test__version.py new file mode 100644 index 0000000..bcb78f2 --- /dev/null +++ b/tests/test__version.py @@ -0,0 +1,8 @@ +"""Test __version__ module.""" + +from aiolyric._version import __version__ + + +def test__version(): + """Test the __version__ string.""" + assert isinstance(__version__.public(), str)