diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2007-03-26 00:14:33 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2007-03-26 00:14:33 +0000 |
| commit | 283c17a74cf11f40b822807f2d9f52644136c749 (patch) | |
| tree | b79b8675a7f27af8a39277b124c1e2e18d10e082 /tests | |
| parent | ed1233982a70e0d9c816b00c8fa78a5521c9d347 (diff) | |
| download | enigma2-283c17a74cf11f40b822807f2d9f52644136c749.tar.gz enigma2-283c17a74cf11f40b822807f2d9f52644136c749.zip | |
start to implement a test environment to run seperate components seperately.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/enigma.py | 103 | ||||
| -rw-r--r-- | tests/fake_time.py | 10 | ||||
| -rw-r--r-- | tests/test_timer.py | 9 |
3 files changed, 122 insertions, 0 deletions
diff --git a/tests/enigma.py b/tests/enigma.py new file mode 100644 index 00000000..9c700ae1 --- /dev/null +++ b/tests/enigma.py @@ -0,0 +1,103 @@ +# fake-enigma + +import fake_time + +class slot: + def __init__(self): + self.list = [ ] + + def get(self): + return self.list + + def __call__(self): + for x in self.list: + x() + +timers = set() + +import time + +##################### ENIGMA BASE + +class eTimer: + def __init__(self): + self.timeout = slot() + self.next_activation = None + + def start(self, msec, singleshot = False): + self.next_activation = time.time() + msec / 1000.0 + self.msec = msec + self.singleshot = singleshot + timers.add(self) + + def stop(): + timers.remove(self) + + def __repr__(self): + return "<eTimer timeout=%s next_activation=%s singleshot=%s>" % (repr(self.timeout), repr(self.next_activation), repr(self.singleshot)) + + def do(self): + if self.singleshot: + self.stop() + self.next_activation += self.msec / 1000.0 + print "next activation now %d " % self.next_activation + self.timeout() + +def runIteration(): + running_timers = list(timers) + assert len(running_timers), "no running timers, so nothing will ever happen!" + running_timers.sort(key=lambda x: x.next_activation) + print running_timers + + next_timer = running_timers[0] + + now = time.time() + delay = next_timer.next_activation - now + + if delay > 0: + time.sleep(delay) + now += delay + + while len(running_timers) and running_timers[0].next_activation <= now: + running_timers[0].do() + running_timers = running_timers[1:] + +stopped = False + +def stop(): + global stopped +# print "STOP NOW" +# stopped = True + +def run(): + stoptimer = eTimer() + stoptimer.start(10000) + stoptimer.timeout.get().append(stop) + while not stopped: + runIteration() + + +##################### ENIGMA GUI + +eSize = None +ePoint = None +gFont = None +eWindow = None +eLabel = None +ePixmap = None +eWindowStyleManager = None +loadPNG = None +addFont = None +gRGB = None +eWindowStyleSkinned = None + +##################### ENIGMA CONFIG + +import Components.config + +my_config = [ +"config.skin.primary_skin=None\n" +] + +Components.config.config.unpickle(my_config) + diff --git a/tests/fake_time.py b/tests/fake_time.py new file mode 100644 index 00000000..09f88b49 --- /dev/null +++ b/tests/fake_time.py @@ -0,0 +1,10 @@ +import time + +real_time = time.time + +time_offset = real_time() + +def my_time(): + return real_time() - time_offset + +time.time = my_time diff --git a/tests/test_timer.py b/tests/test_timer.py new file mode 100644 index 00000000..e1672e72 --- /dev/null +++ b/tests/test_timer.py @@ -0,0 +1,9 @@ +import enigma + +import RecordTimer + +t = RecordTimer.RecordTimer() + + +# run virtual environment +enigma.run() |
