Exemplo n.º 1
0
def smoke_test_module():
    import pickle
    from smoothtest.Logger import Logger
    log = Logger(__name__)
    results = TestResults()
    pickle.dumps(results)
    str(results)
    results._append_exception('test_path', 'exn')
    results.failures = [('bla', 2)]
    results.errors = [('bla', 2)]
    results.total = [('bla', 2)]
    log.i(str(results))
Exemplo n.º 2
0
def smoke_test_module():
    import pickle
    from smoothtest.Logger import Logger
    log = Logger(__name__)
    results = TestResults()
    pickle.dumps(results)
    str(results)
    results._append_exception('test_path', 'exn')
    results.failures = [('bla', 2)]
    results.errors = [('bla', 2)]
    results.total = [('bla', 2)]
    log.i(str(results))
Exemplo n.º 3
0
 def __init__(self, base_url, webdriver, logger=None, settings=None):
     '''
     If you don't ignore __init__, arguments 
     :param base_url: like in _init_webdriver method
     :param webdriver: like in _init_webdriver method
     :param logger: You can optionally pass a smoothtest.Logger instance (or a child class's instance) 
     :param settings: like in _init_webdriver method
     '''
     self._init_webdriver(base_url, webdriver, settings=settings or {})
     self.log = logger or Logger(self.__class__.__name__)
Exemplo n.º 4
0
 def get_xpathbrowser(self, base_url=None, name=''):
     from smoothtest.Logger import Logger
     from .XpathBrowser import XpathBrowser
     base_url = base_url or self.base_url or self.global_settings.get(
         'base_url')
     name = name or self.name
     # Initialize the XpathBrowser class
     return XpathBrowser(base_url,
                         self.acquire_driver(),
                         Logger(name),
                         settings={})
Exemplo n.º 5
0
 def setUp(self):
     self.__level_mngr = WebdriverManager().enter_level(
         level=SINGLE_TEST_LIFE)
     webdriver = self.__level_mngr.acquire_driver()
     logger = Logger(__name__)
     self.browser = XpathBrowser('', webdriver, logger, settings={})
Exemplo n.º 6
0
class AutotestMagics(Magics):
    '''
    Mainly add some "magic" commands to the autotest's Ipython shell.
    '''
    main = None
    log = Logger(name='Ipython Extension')

    def expand_files(self, tests):
        paths = []
        for tst in tests:
            paths += glob.glob(tst)
        return paths

    def __common(self, line):
        from .Command import Command
        command = Command()
        parser = command.get_extension_parser()
        try:
            args, unknown = parser.parse_known_args(shlex.split(line))
            args.tests = self.expand_files(args.tests)
            args.full_reloads = self.expand_files(args.full_reloads)
            test_config = command.get_test_config(args, unknown)
            test_config.update(force=args.force)
            return args, test_config
        except SystemExit:
            # Ignore SystemExit exception since ipython will ignore it anyway
            # (happens when passing --help or on error)
            pass

    def _send(self, test_config):
        self.main.send_test(**test_config)

    def _test_magic_cmd_parser(self):
        parser = ArgumentParser(description='Manually trigger a test.')
        parser.add_argument('-f',
                            '--force',
                            help='Trigger full reload.',
                            default=False,
                            action='store_true')
        return parser

    @line_magic
    def test(self, line):
        parser = self._test_magic_cmd_parser()
        try:
            args = parser.parse_args(shlex.split(line))
            if args.force:
                # Force full reload
                test_config = self.main.test_config.copy()
                test_config.update(force=True)
                self._send(test_config)
            else:
                # Simply invoque .test TODO
                self.main.test()
        except SystemExit:
            pass

    @line_magic
    def autotest(self, line):
        res = self.__common(line)
        if not res:
            return
        args, test_config = res
        if args.update:
            # Update set values
            for k, v in self.main.test_config.iteritems():
                if not test_config.get(k):
                    test_config[k] = v
            if args.smoke is not None:
                test_config['smoke'] = True
            if args.nosmoke is not None:
                test_config['smoke'] = False
            test_config.update(force=args.force)
        self.log.i(
            'Parsing arguments and sending new test config. Check children processes output below...'
        )
        self._send(test_config)
        return 'Done sending new test_config=%r' % test_config

    @line_magic
    def steal_xpathbrowser(self, line):
        parser = ArgumentParser(
            prog='Steal XpathBrowser',
            description=
            'Get an XpathBrowser instance bypassing any locking mechanism. (debugging purposes)'
        )
        parser.add_argument(
            'browser',
            type=str,
            default=self.main._get_browser_name(),
            nargs='?',
            help='The browser we want the XpathBrowser object from.')
        try:
            args = parser.parse_args(shlex.split(line))
        except SystemExit:
            return
        xbrowser = self.main.steal_xpathbrowser(args.browser)
        if not xbrowser:
            self.log.w('No webdriver for browser %r' % args.browser)
        return xbrowser

    @line_magic
    def get(self, line):
        parser = ArgumentParser(
            prog='Get URL page',
            description='Fetch a URL using the current selected browser.')
        parser.add_argument('url', type=str, help='Url we would like to open.')
        parser.add_argument(
            'browser',
            type=str,
            default=self.main._get_browser_name(),
            nargs='?',
            help='The browser name we want to open the Url with.')
        try:
            args = parser.parse_args(shlex.split(line))
        except SystemExit:
            return
        xbrowser = self.main.steal_xpathbrowser(args.browser)
        if not xbrowser:
            return
        u = urlparse.urlparse(args.url)
        if not u.scheme:
            u = ('http', u.netloc, u.path, u.params, u.query, u.fragment)
            url = urlparse.urlunparse(u)
        xbrowser.get_url(url)
        self.log.i('Current url: %r' % xbrowser.current_url())
        return xbrowser

    def _new_browser(self, browser):
        self.log.i('Setting browser to: %s' % browser)
        self.main.new_browser(browser)

    @line_magic
    def firefox(self, line):
        self._new_browser('Firefox')

    @line_magic
    def chrome(self, line):
        self._new_browser('Chrome')

    @line_magic
    def phantomjs(self, line):
        self._new_browser('PhantomJS')

    @line_magic
    def reset(self, line):
        self.main.reset()

    @line_magic
    def test_config(self, line):
        return self.main.test_config
Exemplo n.º 7
0
 def __init__(self, logger=None):
     self.log = logger or Logger(self.__class__.__name__)
Exemplo n.º 8
0
 def print_results(self, test_results):
     from smoothtest.Logger import Logger
     fmt = '%(message)s'
     color = Logger(name='print_results_color', color=True)
     color.set_fmt(fmt)
     normal = Logger(name='print_results')
     normal.set_fmt(fmt)
     detail_dict = test_results.get_detail_dict()
     normal.i('-'*70)
     if any(val for val in detail_dict.values()):
         normal.i('Details:')
         count = 0
         for name, val in detail_dict.iteritems():
             name = name[0].upper() + name[1:]
             count += len(val)
             normal.i('  {name}={val}'.format(name=name, val=val))
         normal.i(test_results)
         color.e('FOUND %s ERROR%s', count, 'S' if count > 1 else '')
     else:
         normal.i(test_results)
         color.i('ALL %s OK', test_results.get_total())
Exemplo n.º 9
0
 def __init__(self, logger=None):
     self.log = logger or Logger('Xpath Shell')