Ejemplo n.º 1
0
 def __wrappers__(self):
     wrappers = {}
     for case_func in self.case_funcs:
         case_func, metadata = extract_metadata(case_func)
         wrapper = CaseWrapper(case_func, parent=self, metadata=metadata)
         wrappers[wrapper.id] = wrapper
     return wrappers
Ejemplo n.º 2
0
    def __init__(self, parent=None):
        super(DataDescribe, self).__init__(parent=parent)
        self.cases = {}

        # Generate new functions and monkey-patch
        for case_func in self.case_funcs:
            extracted_func, base_metadata = extract_metadata(case_func)

            for name, data in self.DATASET.items():
                args, meta = data, dict(base_metadata)

                # Handle complex dataset item
                if 'args' in data and 'meta' in data:
                    args = data.get('args', {})
                    meta.update(data.get('meta', {}))

                # Extract name, args and duplicate function
                func_name = '{0}_{1}'.format(extracted_func.__name__, name)
                new_func = copy_function(extracted_func, func_name)
                kwargs = get_function_kwargs(extracted_func, args)

                # Monkey-patch and add to cases list
                setattr(self, func_name, new_func)
                wrapper = CaseWrapper(new_func, parent=self,
                                      execute_kwargs=kwargs, metadata=meta)
                self.cases[wrapper.id] = wrapper
Ejemplo n.º 3
0
 def __wrappers__(self):
     wrappers = {}
     for case_func in self.case_funcs:
         case_func, metadata = extract_metadata(case_func)
         wrapper = CaseWrapper(case_func, parent=self, metadata=metadata)
         wrappers[wrapper.id] = wrapper
     return wrappers
Ejemplo n.º 4
0
 def __wrappers__(self):
     wrappers = []
     for case_func in self.case_funcs:
         case_func, metadata = extract_metadata(case_func)
         wrappers.append(CaseWrapper(case_func, parent=self,
                                     metadata=metadata))
     return wrappers
Ejemplo n.º 5
0
    def test_extract_metadata_w_skip_after(self):
        @metadata(type='testing')
        @skip('testing_skip')
        def sample_func():
            pass

        func, meta = util.extract_metadata(sample_func)
        self.assertEqual(meta.get('type'), 'testing')
Ejemplo n.º 6
0
    def test_extract_metadata(self):
        @metadata(type='testing')
        def sample_func():
            pass

        func, meta = util.extract_metadata(sample_func)
        self.assertEqual(func.__name__, 'sample_func')
        self.assertEqual(meta.get('type'), 'testing')
Ejemplo n.º 7
0
    def test_extract_metadata_w_skip_after(self):

        @metadata(type='testing')
        @skip('testing_skip')
        def sample_func():
            pass

        func, meta = util.extract_metadata(sample_func)
        self.assertEqual(meta.get('type'), 'testing')
Ejemplo n.º 8
0
    def test_extract_metadata(self):

        @metadata(type='testing')
        def sample_func():
            pass

        func, meta = util.extract_metadata(sample_func)
        self.assertEqual(func.__name__, 'sample_func')
        self.assertEqual(meta.get('type'), 'testing')
Ejemplo n.º 9
0
    def __init__(self, parent=None):
        super(DataDescribe, self).__init__(parent=parent)
        self.cases = {}

        self.dup_count = 0
        self.dups = set()

        # Generate new functions and monkey-patch
        for case_func in self.case_funcs:
            extracted_func, base_metadata = extract_metadata(case_func)

            for name, data in self.DATASET.items():
                args, meta = data, dict(base_metadata)

                # Handle complex dataset item
                if 'args' in data and 'meta' in data:
                    args = data.get('args', {})
                    meta.update(data.get('meta', {}))

                # Skip duplicates
                if args:
                    key_args = convert_to_hashable(args)
                    if key_args in self.dups:
                        self.dup_count += 1
                        continue
                    else:
                        self.dups.add(key_args)

                # Extract name, args and duplicate function
                func_name = '{0}_{1}'.format(extracted_func.__name__, name)
                new_func = copy_function(extracted_func, func_name)
                kwargs = get_function_kwargs(extracted_func, args)

                # Monkey-patch and add to cases list
                setattr(self, func_name, new_func)
                wrapper = CaseWrapper(new_func, parent=self,
                                      execute_kwargs=kwargs, metadata=meta)
                self.cases[wrapper.id] = wrapper