Changeset - 9bdc25ed5df5
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 20 months ago 2023-05-30 02:37:11
drewp@bigasterisk.com
fix tests
2 files changed with 7 insertions and 4 deletions:
0 comments (0 inline, 0 general)
light9/effect/sequencer/eval_faders_test.py
Show inline comments
 
from unittest import mock
 

	
 
from light9.effect.sequencer.eval_faders import FaderEval
 
from light9.effect.settings import DeviceSettings
 
from light9.mock_syncedgraph import MockSyncedGraph
 
from light9.namespaces import L9
 

	
 
PREFIXES = '''
 
@prefix : <http://light9.bigasterisk.com/> .
 
@prefix effect: <http://light9.bigasterisk.com/effect/> .
 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
 
@prefix show: <http://light9.bigasterisk.com/show/dance2023/> .
 
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
 
@prefix dev: <http://light9.bigasterisk.com/theater/test/device/> .
 
@prefix dmxA: <http://light9.bigasterisk.com/output/dmxA/> .
 
'''
 

	
 
NOTE_GRAPH = PREFIXES + '''
 
            :brightness
 
                a :DeviceAttr;
 
                rdfs:label "brightness";
 
                :dataType :scalar .
 

	
 
            :strength
 
                a :EffectAttr;
 
                rdfs:label "strength" .
 

	
 
            :SimpleDimmer
 
                a :DeviceClass;
 
                rdfs:label "SimpleDimmer";
 
                :deviceAttr :brightness;
 
                :attr [ :outputAttr :level; :dmxOffset 0 ] .
 

	
 
            :light1
 
                a :SimpleDimmer;
 
                :dmxUniverse dmxA:;
 
                :dmxBase 178 .
 

	
 
            effect:effect1
 
                a :Effect;
 
                :setting effect:effect1_set1 .
 
            effect:effect1_set1
 
                :device :light1;
 
                :deviceAttr :brightness;
 
                :value 0.5 .
 
            :fade1
 
                a :Fader;
 
                :effect effect:effect1;
 
                :setting :fs1;
 
                :value 0.6 .
 
                :setting :fs1 .
 
            :fs1 
 
                :value 0.6 ;
 
                :effectAttr :strength .
 

	
 
        '''
 

	
 

	
 
class TestFaderEval:
 

	
 
    def test_faderValueScalesEffectSettings(self):
 
        g = MockSyncedGraph(NOTE_GRAPH)
 
        sender = mock.MagicMock()
 

	
 
        f = FaderEval(g)
 
        devSettings = f.computeOutput()
 
        assert devSettings == DeviceSettings(g, [(L9['light1'], L9['brightness'], 0.3)])
 
\ No newline at end of file
light9/effect/settings_test.py
Show inline comments
 
import unittest
 
from typing import cast
 

	
 
from rdfdb.patch import Patch
 
from rdflib import Literal
 

	
 
from light9.effect.settings import DeviceSettings
 
from light9.localsyncedgraph import LocalSyncedGraph
 
from light9.namespaces import DEV, L9
 
from light9.newtypes import DeviceAttr, DeviceUri, HexColor, VTUnion
 

	
 

	
 
def decimalLiteral(value):
 
    return Literal(value, datatype='http://www.w3.org/2001/XMLSchema#decimal')
 

	
 
class TestDeviceSettings(unittest.TestCase):
 

	
 
    def setUp(self):
 
        self.graph = LocalSyncedGraph(files=['test/cam/lightConfig.n3', 'test/cam/bg.n3'])
 

	
 
    def testToVectorZero(self):
 
        ds = DeviceSettings(self.graph, [])
 
        self.assertEqual([0] * 30, ds.toVector())
 

	
 
    def testEq(self):
 
        s1 = DeviceSettings(self.graph, [
 
            (L9['light1'], L9['attr1'], 0.5),
 
            (L9['light1'], L9['attr2'], 0.3),
 
        ])
 
        s2 = DeviceSettings(self.graph, [
 
            (L9['light1'], L9['attr2'], 0.3),
 
            (L9['light1'], L9['attr1'], 0.5),
 
        ])
 
        self.assertTrue(s1 == s2)
 
        self.assertFalse(s1 != s2)
 

	
 
    def testMissingFieldsEqZero(self):
 
        self.assertEqual(DeviceSettings(self.graph, [
 
            (L9['aura1'], L9['rx'], 0),
 
        ]), DeviceSettings(self.graph, []))
 

	
 
    def testFalseIfZero(self):
 
        self.assertTrue(DeviceSettings(self.graph, [(L9['aura1'], L9['rx'], 0.1)]))
 
        self.assertFalse(DeviceSettings(self.graph, []))
 

	
 
    def testFromResource(self):
 
        ctx = L9['']
 
        self.graph.patch(
 
            Patch(addQuads=[
 
                (L9['foo'], L9['setting'], L9['foo_set0'], ctx),
 
                (L9['foo_set0'], L9['device'], L9['light1'], ctx),
 
                (L9['foo_set0'], L9['deviceAttr'], L9['brightness'], ctx),
 
                (L9['foo_set0'], L9['value'], Literal(0.1), ctx),
 
                (L9['foo_set0'], L9['value'], decimalLiteral(0.1), ctx),
 
                (L9['foo'], L9['setting'], L9['foo_set1'], ctx),
 
                (L9['foo_set1'], L9['device'], L9['light1'], ctx),
 
                (L9['foo_set1'], L9['deviceAttr'], L9['speed'], ctx),
 
                (L9['foo_set1'], L9['scaledValue'], Literal(0.2), ctx),
 
                (L9['foo_set1'], L9['scaledValue'], decimalLiteral(0.2), ctx),
 
            ]))
 
        s = DeviceSettings.fromResource(self.graph, DeviceUri(L9['foo']))
 

	
 
        self.assertEqual(DeviceSettings(self.graph, [
 
            (L9['light1'], L9['brightness'], 0.1),
 
            (L9['light1'], L9['speed'], 0.2),
 
        ]), s)
 

	
 
    def testToVector(self):
 
        v = DeviceSettings(self.graph, [
 
            (DeviceUri(DEV['aura1']), DeviceAttr(L9['rx']), 0.5),
 
            (DeviceUri(DEV['aura1']), DeviceAttr(L9['color']), HexColor('#00ff00')),
 
        ]).toVector()
 
        self.assertEqual([0, 1, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], v)
 

	
 
    def testFromVector(self):
 
        s = DeviceSettings.fromVector(self.graph, [0, 1, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
 

	
 
        self.assertEqual(
 
            DeviceSettings(self.graph, [
 
                (DeviceUri(DEV['aura1']), DeviceAttr(L9['rx']), 0.5),
 
                (DeviceUri(DEV['aura1']), DeviceAttr(L9['color']), HexColor('#00ff00')),
 
            ]), s)
 

	
 
    def testAsList(self):
 
        sets = [
 
            (DeviceUri(L9['light1']), DeviceAttr(L9['attr2']), cast(VTUnion, 0.3)),
 
            (DeviceUri(L9['light1']), DeviceAttr(L9['attr1']), 0.5),
 
        ]
 
        self.assertCountEqual(sets, DeviceSettings(self.graph, sets).asList())
 

	
 
    def testDevices(self):
 
        s = DeviceSettings(self.graph, [
 
            (DEV['aura1'], L9['rx'], 0),
 
            (DEV['aura2'], L9['rx'], 0.1),
 
        ])
 
        # aura1 is all defaults (zeros), so it doesn't get listed
 
        self.assertCountEqual([DEV['aura2']], s.devices())
 

	
 
    def testAddStatements(self):
 
        s = DeviceSettings(self.graph, [
 
            (DEV['aura2'], L9['rx'], 0.1),
 
        ])
 
        stmts = s.statements(DeviceUri(L9['foo']), L9['ctx1'], L9['s_'], set())
 
        self.maxDiff = None
 
        setting = sorted(stmts)[-1][0]
 
        self.assertCountEqual([
 
            (L9['foo'], L9['setting'], setting, L9['ctx1']),
0 comments (0 inline, 0 general)