コード例 #1
0
 def setUp(self):
     
     func_call1 = FunctionCall.from_function(simple)
     func_call2 = FunctionCall.from_function(with_defaults)
     
     self.statements = [func_call1,func_call2]
     unittest.TestCase.setUp(self)
コード例 #2
0
    def setUp(self):

        func_call1 = FunctionCall.from_function(simple)
        func_call2 = FunctionCall.from_function(with_defaults)

        self.statements = [func_call1, func_call2]
        unittest.TestCase.setUp(self)
コード例 #3
0
    def _test_py_modules_in_directory(self, lib_dir):

        py_files = glob(os.path.join(lib_dir,'*.py'))
        module_names = []
        for path in py_files:
            base_name = os.path.basename(path)
            module_name, ext = os.path.splitext(base_name)
            module_names.append(module_name)

        for module_name in module_names:
            # fixme: do this with pkgutil?
            try:
                # Skip modules that don't import.  Since not all modules
                # in the standard library will import on all platforms.
                exec "import %s" % module_name
                module = eval(module_name)
            except ImportError:
                module = None

            if module:
                functions = _get_functions(module)

                for function in functions:
                    func = FunctionCall.from_function(function)
                    signature = func.call_signature
コード例 #4
0
    def test_simple(self):

        func_call = FunctionCall.from_function(simple)

        inputs = func_call.inputs

        # Check the names.
        desired = ['a','b']
        self.assertEqual([x.name for x in inputs], desired)

        # And the default values.
        desired = [None, None]
        self.assertEqual([x.default for x in inputs], desired)

        # And the values values.
        desired = ['a', 'b']
        self.assertEqual([x.binding for x in inputs], desired)

        # Now check the output names.
        outputs = [x.name for x in func_call.outputs]
        desired = ['x','y']
        self.assertEqual(outputs, desired)

        # Check the module.
        # fixme: Do we actually want to test this here?  I think only if
        #        we choose to move module up to the func_call level.
        desired = simple.__module__
        self.assertEqual(func_call.function.module, desired)
コード例 #5
0
    def test_unbound_default_call_signature(self):


        func = FunctionCall.from_function(with_defaults)

        desired = 'x, y = with_defaults(a, b=b)'
        self.assertEqual(func.call_signature, desired)
コード例 #6
0
    def test_simple(self):

        func_call = FunctionCall.from_function(simple)

        inputs = func_call.inputs

        # Check the names.
        desired = ['a', 'b']
        self.assertEqual([x.name for x in inputs], desired)

        # And the default values.
        desired = [None, None]
        self.assertEqual([x.default for x in inputs], desired)

        # And the values values.
        desired = ['a', 'b']
        self.assertEqual([x.binding for x in inputs], desired)

        # Now check the output names.
        outputs = [x.name for x in func_call.outputs]
        desired = ['x', 'y']
        self.assertEqual(outputs, desired)

        # Check the module.
        # fixme: Do we actually want to test this here?  I think only if
        #        we choose to move module up to the func_call level.
        desired = simple.__module__
        self.assertEqual(func_call.function.module, desired)
コード例 #7
0
    def _test_py_modules_in_directory(self, lib_dir):

        py_files = glob(os.path.join(lib_dir, '*.py'))
        module_names = []
        for path in py_files:
            base_name = os.path.basename(path)
            module_name, ext = os.path.splitext(base_name)
            module_names.append(module_name)

        for module_name in module_names:
            # fixme: do this with pkgutil?
            try:
                # Skip modules that don't import.  Since not all modules
                # in the standard library will import on all platforms.
                exec "import %s" % module_name
                module = eval(module_name)
            except ImportError:
                module = None

            if module:
                functions = _get_functions(module)

                for function in functions:
                    func = FunctionCall.from_function(function)
                    signature = func.call_signature
コード例 #8
0
    def test_no_return(self):

        func = FunctionCall.from_function(no_return)

        # Now check the output names.
        outputs = [x.name for x in func.outputs]
        desired = []
        self.assertEqual(outputs, desired)
コード例 #9
0
    def test_no_return(self):

        func = FunctionCall.from_function(no_return)


        # Now check the output names.
        outputs = [x.name for x in func.outputs]
        desired = []
        self.assertEqual(outputs, desired)
コード例 #10
0
    def test_label_name(self):

        func = FunctionCall.from_function(simple)
        self.assertEqual(func.label_name, "simple")

        func.function.name = "no_return"
        self.assertEqual(func.label_name, "no_return")

        func.function.library_name = "foo"
        self.assertEqual(func.label_name, "foo")
コード例 #11
0
    def test_name_change_updates_call_signature(self):

        func = FunctionCall.from_function(simple)

        desired = 'x, y = simple(a, b)'
        self.assertEqual(func.call_signature, desired)

        func.label_name = 'baz'
        desired = 'x, y = baz(a, b)'
        self.assertEqual(func.call_signature, desired)
コード例 #12
0
    def test_name_change_updates_call_signature(self):

        func = FunctionCall.from_function(simple)

        desired = 'x, y = simple(a, b)'
        self.assertEqual(func.call_signature, desired)

        func.label_name = 'baz'
        desired = 'x, y = baz(a, b)'
        self.assertEqual(func.call_signature, desired)
コード例 #13
0
    def test_label_name(self):

        func = FunctionCall.from_function(simple)
        self.assertEqual(func.label_name,"simple")

        func.function.name = "no_return"
        self.assertEqual(func.label_name, "no_return")

        func.function.library_name = "foo"
        self.assertEqual(func.label_name,"foo")
コード例 #14
0
    def test_with_defaults_none(self):

        func = FunctionCall.from_function(with_defaults_none)

        inputs = func.inputs

        # Check the names.
        desired = ['a', 'b']
        self.assertEqual([x.name for x in inputs], desired)

        # And the default values.
        desired = [None, 'None']
        self.assertEqual([x.default for x in inputs], desired)
コード例 #15
0
    def test_with_defaults_none(self):

        func = FunctionCall.from_function(with_defaults_none)

        inputs = func.inputs

        # Check the names.
        desired = ['a','b']
        self.assertEqual([x.name for x in inputs], desired)

        # And the default values.
        desired = [None, 'None']
        self.assertEqual([x.default for x in inputs], desired)
コード例 #16
0
    def test_with_defaults(self):
        func = FunctionCall.from_function(with_defaults)

        inputs = func.inputs

        # Check the names.
        desired = ['a','b']
        self.assertEqual([x.name for x in inputs], desired)

        # And the default values.
        desired = [None, '3']
        self.assertEqual([x.default for x in inputs], desired)

        # Now check the output names.
        outputs = [x.name for x in func.outputs]
        desired = ['x','y']
        self.assertEqual(outputs, desired)
コード例 #17
0
    def test_with_defaults(self):
        func = FunctionCall.from_function(with_defaults)

        inputs = func.inputs

        # Check the names.
        desired = ['a', 'b']
        self.assertEqual([x.name for x in inputs], desired)

        # And the default values.
        desired = [None, '3']
        self.assertEqual([x.default for x in inputs], desired)

        # Now check the output names.
        outputs = [x.name for x in func.outputs]
        desired = ['x', 'y']
        self.assertEqual(outputs, desired)
コード例 #18
0
    def test_simple_call_signature(self):

        func = FunctionCall.from_function(simple)

        desired = 'x, y = simple(a, b)'
        self.assertEqual(func.call_signature, desired)
コード例 #19
0
    def test_empty_return_call_signature(self):

        func = FunctionCall.from_function(empty_return)

        desired = 'empty_return(a, b)'
        self.assertEqual(func.call_signature, desired)
コード例 #20
0
    def test_unbound_default_call_signature(self):

        func = FunctionCall.from_function(with_defaults)

        desired = 'x, y = with_defaults(a, b=b)'
        self.assertEqual(func.call_signature, desired)
コード例 #21
0
    def test_empty_return_call_signature(self):

        func = FunctionCall.from_function(empty_return)

        desired = 'empty_return(a, b)'
        self.assertEqual(func.call_signature, desired)
コード例 #22
0
    def test_simple_call_signature(self):

        func = FunctionCall.from_function(simple)

        desired = 'x, y = simple(a, b)'
        self.assertEqual(func.call_signature, desired)