Exemple #1
0
    def test_type_cast(self):
        self.assertTrue(is_function(int, 1))
        self.assertTrue(is_function(float, 1))
        self.assertTrue(is_function(str, 1))

        self.assertFalse(is_function(int, 0) or is_function(int, 2))
        self.assertFalse(is_function(float, 0) or is_function(float, 2))
        self.assertFalse(is_function(str, 0) or is_function(str, 2))
Exemple #2
0
    def test_coroutine_check(self):
        def f_sync():
            raise RuntimeError('function should not get called')

        self.assertTrue(is_function(f_sync, 0))
        self.assertTrue(is_function(f_sync, 0, coroutine=False))

        # support pre-py3.5 async syntax
        @asyncio.coroutine
        def f_async_old():
            raise RuntimeError('function should not get called')

        self.assertFalse(is_function(f_async_old, 0, coroutine=False))
        self.assertTrue(is_function(f_async_old, 0, coroutine=True))
        self.assertFalse(is_function(f_async_old, 0))

        # test py3.5 syntax async functions
        try:
            from qcodes.tests.py35_syntax import f_async
            py35 = True
        except:
            py35 = False

        if py35:
            self.assertFalse(is_function(f_async, 0, coroutine=False))
            self.assertTrue(is_function(f_async, 0, coroutine=True))
            self.assertFalse(is_function(f_async, 0))
Exemple #3
0
 def test_methods(self):
     a = self.AClass()
     self.assertTrue(is_function(a.method_a, 0))
     self.assertFalse(is_function(a.method_a, 1))
     self.assertTrue(is_function(a.method_b, 1))
     self.assertTrue(is_function(a.method_c, 1, coroutine=True))
Exemple #4
0
    def test_function(self):
        def f0():
            raise RuntimeError('function should not get called')

        def f1(a):
            raise RuntimeError('function should not get called')

        def f2(a, b):
            raise RuntimeError('function should not get called')

        self.assertTrue(is_function(f0, 0))
        self.assertTrue(is_function(f1, 1))
        self.assertTrue(is_function(f2, 2))

        self.assertFalse(is_function(f0, 1) or is_function(f0, 2))
        self.assertFalse(is_function(f1, 0) or is_function(f1, 2))
        self.assertFalse(is_function(f2, 0) or is_function(f2, 1))

        # make sure we only accept valid arg_count
        with self.assertRaises(TypeError):
            is_function(f0, 'lots')
        with self.assertRaises(TypeError):
            is_function(f0, -1)
Exemple #5
0
 def test_non_function(self):
     self.assertFalse(is_function(0, 0))
     self.assertFalse(is_function('hello!', 0))
     self.assertFalse(is_function(None, 0))
Exemple #6
0
 def __init__(self, condition):
     if not is_function(condition, 0):
         raise TypeError('BreakIf condition must be a callable with '
                         'no arguments')
     self.condition = condition