def test_local_children(self): children = [ 'year', 'day', 'month', 'hour', 'minute', 'weekday', 'second', 'milliseconds' ] t = Time() t.configure({'name': 'time', 'parent': None}) l = t.get_child('local') for c in children: if c not in l.children_names(): msg = 'Child "' + str(c) + '" was not found in Local children ' for x in l.children_names(): msg += str(x) + ',' msg = msg[:-1] + '\n' msg = msg + 'Child "' + str( c) + '" should be an inherent child of Local' self.fail(msg) if len(children) != len(l.children_names()): msg = 'Local has a different amount of inherent children then I know about!\n' msg += 'I think it should have only:\n' for c in children: msg += c + '\n' msg += '\nLocal has Children:\n' for c in l.children.names(): msg += c + '\n' self.fail(msg)
def __init__(self): ServiceNode.__init__(self) # Instantiate implicit children. from mpx.service.interactive import InteractiveService InteractiveService().configure({ 'name': 'Interactive Service', 'parent': self, 'debug': 0, 'port': 9666, 'interface': 'localhost' }) from mpx.service.time import Time Time().configure({'name': 'time', 'parent': self}) from mpx.service.session import SessionManager SessionManager().configure({'name': 'session_manager', 'parent': self}) from mpx.service.user_manager import UserManager UserManager().configure({'name': 'User Manager', 'parent': self}) from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER SUBSCRIPTION_MANAGER.configure({ 'name': 'Subscription Manager', 'parent': self }) # Guarantee that /services/garbage_collector will exist, whether or not # there is an entry in the XML file. from mpx.service.garbage_collector import GARBAGE_COLLECTOR # @todo Make ReloadableSingleton! GARBAGE_COLLECTOR.configure({ 'name': 'garbage_collector', 'parent': self })
def test_Time(self): t = time.time() t2 = Time().get() upper_limit = t + .05 lower_limit = t - .05 # Getting 2 different times so as long as we are close! self.failUnless( t2 < upper_limit and t2 > lower_limit, 'Time did not match' + ' time.time()=' + str(t) + ' and Time().get()=' + str(t2))
def __init__(self, name, poll_all): self._name = name self._run = 0 self._running = 0 self._sid = 0 self._changed_values = {} self._values = {} self._poll_all = poll_all self.DELAY = 0.0 self.__doc['DELAY'] = 'Delay in seconds between polling for values.' root = as_internal_node('/') if not root.has_child(name): anchor = CompositeNode() anchor.configure({'name':name,'parent':root}) self._anchor = anchor t = Time() t.configure({'name':'time', 'parent':anchor}) t.start() return
def check_attribute(self, child, attribute): t = Time() t.configure({'name': 'time', 'parent': None}) c = t.get_child(child) c_value = c.get_child(attribute).get() if attribute != 'milliseconds': attributes = { 'year': 0, 'month': 1, 'day': 2, 'hour': 3, 'weekday': 6, 'minute': 4, 'second': 5 } if child == 'UTC': tuple = time.gmtime() elif child == 'local': tuple = time.localtime() real_value = tuple[attributes[attribute]] if c_value != real_value: self.fail(child + ' "' + attribute + '" is not correct\n' + child + ' ' + attribute + ' came back as: ' + str(c_value) + '\n' + 'Correct value: ' + str(real_value)) else: t = time.time() real_value = (t - int(t)) * 1000 if c_value < (real_value + .5) and c_value > (real_value - .5): pass else: self.fail(child + ' "' + attribute + '" is not correct\n' + child + ' ' + attribute + ' came back as: ' + str(c_value) + '\n' + 'Correct value: ' + str(real_value))
def test_for_local_child(self): t = Time() t.configure({'name': 'time', 'parent': None}) self.failUnless(t.has_child('local'), 'No local child!')
def test_for_UTC_child(self): t = Time() t.configure({'name': 'time', 'parent': None}) self.failUnless(t.has_child('UTC'), 'No UTC child!')