Mercurial > ~darius > hgwebdir.cgi > epro
comparison velib_python/test/test_settingsdevice.py @ 8:9c0435a617db
Import velib_python
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sun, 05 Dec 2021 14:35:36 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:982eeffe9d95 | 8:9c0435a617db |
---|---|
1 #!/usr/bin/env python3 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Python | |
5 import logging | |
6 import os | |
7 import sqlite3 | |
8 import sys | |
9 import unittest | |
10 import subprocess | |
11 import time | |
12 import dbus | |
13 import threading | |
14 import fcntl | |
15 from dbus.mainloop.glib import DBusGMainLoop | |
16 | |
17 # Local | |
18 sys.path.insert(1, os.path.join(os.path.dirname(__file__), '../')) | |
19 from settingsdevice import SettingsDevice | |
20 | |
21 logger = logging.getLogger(__file__) | |
22 | |
23 class CreateSettingsTest(unittest.TestCase): | |
24 # The actual code calling VeDbusItemExport is in fixture_vedbus.py, which is ran as a subprocess. That | |
25 # code exports several values to the dbus. And then below test cases check if the exported values are | |
26 # what the should be, by using the bare dbus import objects and functions. | |
27 | |
28 def setUp(self): | |
29 pass | |
30 | |
31 def tearDown(self): | |
32 pass | |
33 | |
34 def test_adding_new_settings(self): | |
35 # to make sure that we make new settings, put something random in its name: | |
36 rnd = os.urandom(16).encode('hex') | |
37 | |
38 # ofcourse below could be simplified, for now just use all settings from the example: | |
39 settings = SettingsDevice( | |
40 bus=dbus.SessionBus() if 'DBUS_SESSION_BUS_ADDRESS' in os.environ else dbus.SystemBus(), | |
41 supportedSettings={ | |
42 'loggingenabled': ['/Settings/' + rnd + '/Logscript/Enabled', 1, 0, 1], | |
43 'proxyaddress': ['/Settings/' + rnd + '/Logscript/Http/Proxy', '', 0, 0], | |
44 'proxyport': ['/Settings/' + rnd + '/Logscript/Http/ProxyPort', '', 0, 0], | |
45 'backlogenabled': ['/Settings/' + rnd + '/Logscript/LogFlash/Enabled', 1, 0, 1], | |
46 'backlogpath': ['/Settings/' + rnd + '/Logscript/LogFlash/Path', '', 0, 0], # When empty, default path will be used. | |
47 'interval': ['/Settings/' + rnd + '/Logscript/LogInterval', 900, 0, 0], | |
48 'url': ['/Settings/' + rnd + '/Logscript/Url', '', 0, 0] # When empty, the default url will be used. | |
49 }, | |
50 eventCallback=self.handle_changed_setting) | |
51 | |
52 """ | |
53 self.assertIs(type(v), dbus.Double) | |
54 self.assertEqual(self.dbusConn.get_object('com.victronenergy.dbusexample', '/Float').GetText(), '1.5') | |
55 """ | |
56 | |
57 def handle_changed_setting(setting, oldvalue, newvalue): | |
58 pass | |
59 | |
60 if __name__ == "__main__": | |
61 logging.basicConfig(stream=sys.stderr) | |
62 logging.getLogger('').setLevel(logging.WARNING) | |
63 DBusGMainLoop(set_as_default=True) | |
64 unittest.main() |