Example #1
0
    def _finish_run(self):
        if self.__dict__.get('_history_off') == True:
            return

        failed = [str(test) for test in self.failed]
        passed = [str(test) for test in self.passed]
        self.regressions = self._previously_passing.intersection(failed)
        self.fixes = self._previously_failing.intersection(passed)

        # Making sure to account for tests that weren't run this time.
        now_passing = self._previously_passing.union(passed).difference(failed)
        now_failing = self._previously_failing.union(failed).difference(passed)

        with working_dir('./data'):
            with open('passing.txt', 'w+') as passing:
                passing.writelines([str(test) + '\n' for test in now_passing])

            with open('failing.txt', 'w+') as failing:
                failing.writelines([str(test) + '\n' for test in now_failing])

        record = history.RunRecord(regressions=self.regressions,
                                   fixes=self.fixes,
                                   passed=self.passed,
                                   failed=self.failed,
                                   skipped=self.skipped,
                                   warned=self.warned)
        record.save()
Example #2
0
    def _finish_run(self):
        if self.__dict__.get('_history_off') == True:
            return

        failed = [str(test) for test in self.failed]
        passed = [str(test) for test in self.passed]
        self.regressions = self._previously_passing.intersection(failed)
        self.fixes = self._previously_failing.intersection(passed)

        # Making sure to account for tests that weren't run this time.
        now_passing = self._previously_passing.union(passed).difference(failed)
        now_failing = self._previously_failing.union(failed).difference(passed)

        with working_dir('./data'):
            with open('passing.txt', 'w+') as passing:
                passing.writelines([str(test) + '\n' for test in now_passing])

            with open('failing.txt', 'w+') as failing:
                failing.writelines([str(test) + '\n' for test in now_failing])

        record = history.RunRecord(
            regressions=self.regressions,
            fixes=self.fixes,
            passed=self.passed,
            failed=self.failed,
            skipped=self.skipped,
            warned=self.warned
        )
        record.save()
Example #3
0
    def run_set(self, test_set):
        self._start_run()

        if len(test_set) == 0:
            raise errors.EmptyTestSet()

        with working_dir(config.test_folder):
            for test in test_set:
                test.run_in_harness(self)

        self._finish_run()
Example #4
0
    def run_set(self, test_set):
        self._start_run()

        if len(test_set) == 0:
            raise errors.EmptyTestSet()

        with working_dir(config.test_folder):
            for test in test_set:
                test.run_in_harness(self)

        self._finish_run()
Example #5
0
def load_all(test_class=Test, filter_fn=None):
    tests = []
    with working_dir(config.test_folder):
        for root, dirs, files in os.walk('.'):
            for filename in files:
                if filename.endswith(SOURCE_EXTENSION):
                    tests.append(test_class(posixpath.join(root, filename)[2:]))

    if filter_fn:
        return filter(filter_fn, tests)

    return tests
Example #6
0
def load_all(test_class=Test, filter_fn=None):
    tests = []
    with working_dir(config.test_folder):
        for root, dirs, files in os.walk('.'):
            for filename in files:
                if filename.endswith(SOURCE_EXTENSION):
                    tests.append(test_class(
                        posixpath.join(root, filename)[2:]))

    if filter_fn:
        return filter(filter_fn, tests)

    return tests
Example #7
0
def load_from_glob(file_glob, test_class=Test):
    """Finds all test files matched by [file_glob] and returns them as a list
    of test objects.
    """
    if '/**' in file_glob or '**/' in file_glob:
        globlib = __import__('yuno.core.recursive_glob', fromlist=['yuno.core'])
    else:
        globlib = __import__('glob')

    tests = []

    with working_dir(config.test_folder):
        return [test_class(path) for path in globlib.glob(file_glob)]
Example #8
0
def load_from_glob(file_glob, test_class=Test):
    """Finds all test files matched by [file_glob] and returns them as a list
    of test objects.
    """
    if '/**' in file_glob or '**/' in file_glob:
        globlib = __import__('yuno.core.recursive_glob',
                             fromlist=['yuno.core'])
    else:
        globlib = __import__('glob')

    tests = []

    with working_dir(config.test_folder):
        return [test_class(path) for path in globlib.glob(file_glob)]
Example #9
0
def load_by_walking(search_path, test_class=Test):
    """Searches the repo for tests along [search_path], level by level,
    regex-matching folder names and discarding any trees that fail. Prefer this
    over load_regex() for paths whose patterns can be cleanly separated into
    tokens and definitely won't need any backtracking.

    [search_path] should be a list of strings (not compiled regexes) containing
    patterns to match against subfolder names, one for each level of depth.
    Matching will continue til a pattern fails or that depth has been reach, at
    which point any tests found in the bottom folder are returned.

    For example, ['phase(1|2|12)', 'check.*'] will match:
        phase1/check2/
        phase12/check-xyz/
    but won't match:
        phase1/check2/check3/

    """
    isfile, isdir = (os.path.isfile, os.path.isdir)

    def find_tests(folder):
        def is_test(filename):
            is_file = isfile(os.path.join(folder, filename))
            return is_file and filename.endswith(SOURCE_EXTENSION)

        tests = []
        for entry in os.listdir(folder):
            if is_test(entry):
                tests.append(test_class(posixpath.join(folder, entry)))
        return tests

    def search_folder(folder, search_path):
        tests = []

        if len(search_path) == 0:
            return find_tests(folder)
        else:
            folder_contents = os.listdir(folder)

            for item in folder_contents:
                item_path = posixpath.join(folder, item)
                if isdir(item_path) and re.match(search_path[0], item):
                    tests += search_folder(
                        posixpath.join(folder, item), search_path[1:]
                    )
            return tests

    with working_dir(config.test_folder):
        return search_folder('.', search_path)
Example #10
0
def load_all(test_class=Test, filter_fn=None):
    """Returns all the tests (files ending in `config.source_extension`) in the
    repository as a list of [test_class] objects.

    If [filter_fn] is given, includes only tests for which it returns True.

    """
    tests = []
    with working_dir(config.test_folder):
        for root, dirs, files in os.walk('.'):
            for filename in files:
                if filename.endswith(SOURCE_EXTENSION):
                    tests.append(
                        # [2:] strips the ./ added by os.walk()
                        test_class(posixpath.join(root, filename)[2:])
                    )

    if filter_fn:
        return filter(filter_fn, tests)

    return tests
Example #11
0
    def _start_run(self):
        self._previously_failing = set()
        self._previously_passing = set()

        with working_dir('./data'):
            try:
                read_or_create = os.O_RDONLY | os.O_CREAT
                failing = os.fdopen(os.open('failing.txt', read_or_create))
                passing = os.fdopen(os.open('passing.txt', read_or_create))
                self._previously_failing = set([f.strip() for f in failing])
                self._previously_passing = set([p.strip() for p in passing])
            except (IOError, OSError, WindowsError):
                print "WARN: Failed to load history. Results won't be saved."
                self._history_off = True
            finally:
                failing.close()
                passing.close()

        self.passed = []
        self.failed = []
        self.skipped = []
        self.warned = []
        self.regressions = set()
        self.fixes = set()
Example #12
0
    def _start_run(self):
        self._previously_failing = set()
        self._previously_passing = set()

        with working_dir('./data'):
            try:
                read_or_create = os.O_RDONLY | os.O_CREAT
                failing = os.fdopen(os.open('failing.txt', read_or_create))
                passing = os.fdopen(os.open('passing.txt', read_or_create))
                self._previously_failing = set([f.strip() for f in failing])
                self._previously_passing = set([p.strip() for p in passing])
            except (IOError, OSError):
                print "WARN: Failed to load history. Results won't be saved."
                self._history_off = True
            finally:
                failing.close()
                passing.close()

        self.passed = []
        self.failed = []
        self.skipped = []
        self.warned = []
        self.regressions = set()
        self.fixes = set()