root/branch/UMPA/tests/unit/test_extensions/test_schedule.py @ 4542

Revision 4542, 2.5 kB (checked in by getxsick, 4 years ago)

Ticket #308 - new schedule.send() API

Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Copyright (C) 2009 Adriano Monteiro Marques.
5#
6# Author: Bartosz SKOWRON <getxsick at gmail dot com>
7#
8# This library is free software; you can redistribute it and/or modify
9# it under the terms of the GNU Lesser General Public License as published
10# by the Free Software Foundation; either version 2.1 of the License, or
11# (at your option) any later version.
12#
13# This library is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16# License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public License
19# along with this library; if not, write to the Free Software Foundation,
20# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22import os
23import time
24
25import py.test
26
27import umpa
28from umpa.protocols import IP
29from umpa.extensions import schedule
30
31
32class TestExtensionSchedule(object):
33    def test_send_schedule_attr(self):
34        assert hasattr(umpa.Socket, 'send_schedule')
35
36class TestExtensionScheduleRoot(object):
37    def setup_class(cls):
38        # EUID has to be 0 for POSIX
39        if os.name == 'posix' and os.geteuid()!=0:
40            py.test.skip('root-priviliges are needed')
41
42    def test_extra_args(self):
43        schedule.send(0, umpa.Packet(IP()))
44        schedule.send(0, (umpa.Packet(IP()), umpa.Packet(IP())))
45        schedule.send(0, [umpa.Packet(IP()), umpa.Packet(IP())])
46        schedule.send(0, (umpa.Packet(IP()), umpa.Packet(IP())),
47                                                            umpa.Packet(IP()))
48        schedule.send(0, (umpa.Packet(IP()), umpa.Packet(IP())),
49                                        umpa.Packet(IP()), umpa.Packet(IP()))
50
51    def test_detach(self):
52        try:
53            schedule.send(0, [], detach=True)
54        except NotImplementedError:
55            py.test.skip("not implemented yet")
56
57    def test_delay(self):
58        delay = 2
59        before = int(time.time())
60        schedule.send(delay)
61        after = int(time.time())
62        assert after-before >= delay
63
64    def test_interval(self):
65        # TODO: should be test better when async will be available
66        interval = 2
67        p = (umpa.Packet(IP()), umpa.Packet(IP()))
68        before = int(time.time())
69        schedule.send(0, p, interval=interval)
70        after = int(time.time())
71        assert after-before >= interval*len(p)
Note: See TracBrowser for help on using the browser.