예제 #1
0
    def test_speed(self):
        obj = self.obj

        mock = MockReader()
        mock.buffer_scale_idx = '100.0'
        obj.add_listener(mock)

        res = {}
        # current measurements shows ~25K samples/sec
        for cnt in (10000, 25000, 50000):
            for a in range(0, cnt):
                sample = (cnt, "", 1, r(1000), r(1000), r(1000), rc(), err(), '', 0)
                mock.data.append(sample)
            before = time.time()
            for point in mock.datapoints():
                pass
            after = time.time()
            res[cnt] = after - before
            ROOT_LOGGER.info("Times: %s", res)

            while mock.results:
                point = mock.results.pop(0)
                overall = point[DataPoint.CURRENT]['']
                self.assertTrue(len(overall[KPISet.PERCENTILES]) > 0)

        for point in mock.datapoints(True):
            pass
예제 #2
0
    def assertFilesEqual(expected,
                         actual,
                         replace_str="",
                         replace_with="",
                         python_files=False):
        def order(line):
            line = line.replace(',', ' ,')  # for imports
            line = line.replace('(', '( ')  # for
            line = line.replace(')', ' )')  # calls
            line = line.split(" ")
            line.sort()
            return ' '.join(line)

        def equal_by_content(diff):
            # todo: it doesn't show diff for follow case, shouldn't we fix it?
            # 01: + func1()
            # 02:   func2()
            # 03: - func1()
            # func1 moved and order has been changed
            act_lines = [line[1:] for line in diff if line.startswith('-')]
            exp_lines = [line[1:] for line in diff if line.startswith('+')]
            for pair in zip(act_lines, exp_lines):
                if order(pair[0]) != order(pair[1]):
                    return False

            return True

        if isinstance(replace_str, str):
            replace_str = [replace_str]
        if isinstance(replace_with, str):
            replace_with = [replace_with]
        with open(expected) as exp, open(actual) as act:
            act_lines = act.readlines()
            exp_lines = exp.readlines()

        subs = dict(zip(replace_str, replace_with))
        subs.update({'<': '< ', '>': ' >'})  # for xml

        for key in subs:
            act_lines = [x.replace(key, subs[key]).rstrip() for x in act_lines]
            exp_lines = [x.replace(key, subs[key]).rstrip() for x in exp_lines]

        if python_files:
            act_lines = astunparse.unparse(ast.parse(
                '\n'.join(act_lines))).split('\n')
            exp_lines = astunparse.unparse(ast.parse(
                '\n'.join(exp_lines))).split('\n')

        diff = list(difflib.unified_diff(exp_lines, act_lines))

        if diff and not equal_by_content(diff[2:]):
            ROOT_LOGGER.info("Replacements are: %s => %s", replace_str,
                             replace_with)
            msg = "Failed asserting that two files are equal:\n%s\nversus\n%s\nDiff is:\n\n%s"
            # here we show full diff, even equal_by_content
            # todo: show only really different lines

            raise AssertionError(msg % (actual, expected, "\n".join(diff)))
예제 #3
0
 def tearDown(self):
     exc, _, _ = sys.exc_info()
     if exc:
         try:
             if hasattr(self, 'obj') and isinstance(self.obj,
                                                    SelfDiagnosable):
                 diags = self.obj.get_error_diagnostics()
                 if diags:
                     for line in diags:
                         ROOT_LOGGER.info(line)
         except BaseException:
             pass
     if self.captured_logger:
         self.captured_logger.removeHandler(self.log_recorder)
         self.log_recorder.close()
예제 #4
0
    def tearDown(self):
        exc, _, _ = sys.exc_info()
        if exc:
            try:
                if hasattr(self, 'obj') and isinstance(self.obj,
                                                       ScenarioExecutor):
                    diags = self.obj.get_error_diagnostics()
                    if diags:
                        for line in diags:
                            ROOT_LOGGER.info(line)
            except BaseException:
                pass
        if self.captured_logger:
            self.captured_logger.removeHandler(self.log_recorder)
            self.log_recorder.close()

        sys.stdout = self.stdout_backup
        super(BZTestCase, self).tearDown()
예제 #5
0
    def test_prepare(self):
        config = json.loads(open(RESOURCES_DIR + "json/passfail.json").read())
        self.configure(config['reporting'][0])
        self.obj.prepare()
        self.assertGreater(len(self.obj.criteria), 0)

        for n in range(0, 10):
            point = random_datapoint(n)
            ROOT_LOGGER.info("%s: %s", n, point)
            self.obj.aggregated_second(point)
            try:
                self.obj.check()
            except AutomatedShutdown:
                pass

        try:
            self.obj.post_process()
        except AutomatedShutdown:
            pass