Ejemplo n.º 1
0
    def check_filename(self, dumper, ui_test_name, ignores=None):
        ignores = ignores or []

        text = dumper.output
        for ignore in ignores:
            text = text.replace(ignore, '%% FILTERED BY UNITTEST %%')

        today = datetime.date.today()
        text = text.replace(repr(today), 'date.today()')
        text = text.replace(today.strftime('%x'), "YYYY-MM-DD")
        text = text.replace(today.strftime('%Y-%m-%d'), "YYYY-MM-DD")
        text = text.replace(
            repr(datetime.datetime(today.year, today.month, today.day)),
            'datetime.today()')

        text = _UUID_RE.sub("uuid.uuid()", text)

        if os.environ.get('STOQ_USE_GI', '') == '3.0':
            # These are internal changes of GtkDialog which we
            # don't want to see.
            # They can safely be removed when we drop PyGTK support

            # GtkHButtonBox doesn't exist any longer and we don't
            # use GtkVButtonBox
            text = text.replace('GtkButtonBox', 'GtkHButtonBox')
            text = text.replace('GtkBox(PluggableWizard-vbox',
                                'GtkVBox(PluggableWizard-vbox')
            text = text.replace('GtkBox(main_dialog._main_vbox',
                                'GtkVBox(main_dialog._main_vbox')
            text = text.replace('GtkBox(_main_vbox', 'GtkVBox(_main_vbox')
            text = text.replace('stoq+lib+gicompat+', 'Gtk')
        filename = self._get_ui_filename(ui_test_name)
        if not os.path.exists(filename):
            with open(filename, 'w') as f:
                f.write(text)

            self._check_failures(dumper)
            return

        lines = [(line + '\n') for line in text.split('\n')][:-1]
        with open(filename) as f:
            expected = f.readlines()
        difference = diff_lines(expected,
                                lines,
                                short=filename[len(stoq_dir) + 1:])

        # Allow users to easily update uitests by running, for example:
        #   $ STOQ_REPLACE_UITESTS=1 make check-failed
        replace_tests = os.environ.get('STOQ_REPLACE_UITESTS', False)
        if difference and replace_tests:
            print(("\n ** The test %s differed, but being replaced since "
                   "STOQ_REPLACE_UITESTS is set **" % filename))
            with open(filename, 'w') as f:
                f.write(text)
        elif difference:
            self.fail('ui test %s failed:\n%s' % (ui_test_name, difference))

        self._check_failures(dumper)
Ejemplo n.º 2
0
    def check_filename(self, dumper, ui_test_name, ignores=None):
        ignores = ignores or []

        text = dumper.output
        for ignore in ignores:
            text = text.replace(ignore, '%% FILTERED BY UNITTEST %%')

        today = datetime.date.today()
        text = text.replace(repr(today), 'date.today()')
        text = text.replace(today.strftime('%x'), "YYYY-MM-DD")
        text = text.replace(today.strftime('%Y-%m-%d'), "YYYY-MM-DD")
        text = text.replace(
            repr(datetime.datetime(today.year, today.month, today.day)),
            'datetime.today()')

        if os.environ.get('STOQ_USE_GI', '') == '3.0':
            # These are internal changes of GtkDialog which we
            # don't want to see.
            # They can safely be removed when we drop PyGTK support

            # GtkHButtonBox doesn't exist any longer and we don't
            # use GtkVButtonBox
            text = text.replace('GtkButtonBox', 'GtkHButtonBox')
            text = text.replace(
                'GtkBox(PluggableWizard-vbox',
                'GtkVBox(PluggableWizard-vbox')
            text = text.replace(
                'GtkBox(main_dialog._main_vbox',
                'GtkVBox(main_dialog._main_vbox')
            text = text.replace(
                'GtkBox(_main_vbox',
                'GtkVBox(_main_vbox')
            text = text.replace('stoq+lib+gicompat+', 'Gtk')
        filename = self._get_ui_filename(ui_test_name)
        if not os.path.exists(filename):
            open(filename, 'w').write(text)

            self._check_failures(dumper)
            return

        lines = [(line + '\n') for line in text.split('\n')][:-1]
        expected = open(filename).readlines()
        difference = diff_lines(expected,
                                lines,
                                short=filename[len(stoq_dir) + 1:])
        if difference:
            self.fail('ui test %s failed:\n%s' % (
                ui_test_name, difference))

        self._check_failures(dumper)
Ejemplo n.º 3
0
    def check_filename(self, dumper, ui_test_name, ignores=None):
        ignores = ignores or []

        text = dumper.output
        for ignore in ignores:
            text = text.replace(ignore, '%% FILTERED BY UNITTEST %%')

        today = datetime.date.today()
        text = text.replace(repr(today), 'date.today()')
        text = text.replace(today.strftime('%x'), "YYYY-MM-DD")
        text = text.replace(today.strftime('%Y-%m-%d'), "YYYY-MM-DD")
        text = text.replace(
            repr(datetime.datetime(today.year, today.month, today.day)),
            'datetime.today()')

        text = _UUID_RE.sub("uuid.uuid()", text)

        if os.environ.get('STOQ_USE_GI', '') == '3.0':
            # These are internal changes of GtkDialog which we
            # don't want to see.
            # They can safely be removed when we drop PyGTK support

            # GtkHButtonBox doesn't exist any longer and we don't
            # use GtkVButtonBox
            text = text.replace('GtkButtonBox', 'GtkHButtonBox')
            text = text.replace(
                'GtkBox(PluggableWizard-vbox',
                'GtkVBox(PluggableWizard-vbox')
            text = text.replace(
                'GtkBox(main_dialog._main_vbox',
                'GtkVBox(main_dialog._main_vbox')
            text = text.replace(
                'GtkBox(_main_vbox',
                'GtkVBox(_main_vbox')
            text = text.replace('stoq+lib+gicompat+', 'Gtk')
        filename = self._get_ui_filename(ui_test_name)
        if not os.path.exists(filename):
            with open(filename, 'w') as f:
                f.write(text)

            self._check_failures(dumper)
            return

        lines = [(line + '\n') for line in text.split('\n')][:-1]
        with open(filename) as f:
            expected = f.readlines()
        difference = diff_lines(expected,
                                lines,
                                short=filename[len(stoq_dir) + 1:])

        # Allow users to easily update uitests by running, for example:
        #   $ STOQ_REPLACE_UITESTS=1 make check-failed
        replace_tests = os.environ.get('STOQ_REPLACE_UITESTS', False)
        if difference and replace_tests:
            print(("\n ** The test %s differed, but being replaced since "
                   "STOQ_REPLACE_UITESTS is set **" % filename))
            with open(filename, 'w') as f:
                f.write(text)
        elif difference:
            self.fail('ui test %s failed:\n%s' % (
                ui_test_name, difference))

        self._check_failures(dumper)