~ubuntu-branches/ubuntu/wily/pyzmq/wily

« back to all changes in this revision

Viewing changes to zmq/tests/test_stopwatch.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-02-24 19:23:15 UTC
  • mfrom: (1.2.1) (9 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20130224192315-qhmwp3m3ymk8r60d
Tags: 2.2.0.1-1
* New upstream release
* relicense debian packaging to LGPL-3
* update watch file to use github directly
  thanks to Bart Martens for the file
* add autopkgtests
* drop obsolete DM-Upload-Allowed
* bump standard to 3.9.4, no changes required

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf8 -*-
 
2
#-----------------------------------------------------------------------------
 
3
#  Copyright (c) 2010-2012 Brian Granger, Min Ragan-Kelley
 
4
#
 
5
#  This file is part of pyzmq
 
6
#
 
7
#  Distributed under the terms of the New BSD License.  The full license is in
 
8
#  the file COPYING.BSD, distributed as part of this software.
 
9
#-----------------------------------------------------------------------------
 
10
 
 
11
#-----------------------------------------------------------------------------
 
12
# Imports
 
13
#-----------------------------------------------------------------------------
 
14
 
 
15
import sys
 
16
import time
 
17
 
 
18
from unittest import TestCase
 
19
 
 
20
from zmq import Stopwatch, ZMQError
 
21
 
 
22
if sys.version_info[0] >= 3:
 
23
    long = int
 
24
 
 
25
class TestStopWatch(TestCase):
 
26
    
 
27
    def test_stop_long(self):
 
28
        """Ensure stop returns a long int."""
 
29
        watch = Stopwatch()
 
30
        watch.start()
 
31
        us = watch.stop()
 
32
        self.assertTrue(isinstance(us, long))
 
33
        
 
34
    def test_stop_microseconds(self):
 
35
        """Test that stop/sleep have right units."""
 
36
        watch = Stopwatch()
 
37
        watch.start()
 
38
        tic = time.time()
 
39
        watch.sleep(1)
 
40
        us = watch.stop()
 
41
        toc = time.time()
 
42
        self.assertAlmostEqual(us/1e6,(toc-tic),places=0)
 
43
    
 
44
    def test_double_stop(self):
 
45
        """Test error raised on multiple calls to stop."""
 
46
        watch = Stopwatch()
 
47
        watch.start()
 
48
        watch.stop()
 
49
        self.assertRaises(ZMQError, watch.stop)
 
50
        self.assertRaises(ZMQError, watch.stop)
 
51