Exemple #1
0
def test_multitest_drivers_in_testplan(runpath):
    """TODO."""
    for idx, opts in enumerate((dict(name="MyPlan",
                                     runpath=runpath), dict(name="MyPlan"))):
        plan = TestplanMock(**opts)
        server = TCPServer(name="server")
        client = TCPClient(
            name="client",
            host=context(server.cfg.name, "{{host}}"),
            port=context(server.cfg.name, "{{port}}"),
        )
        mtest = MultiTest(
            name="Mtest",
            suites=[MySuite()],
            environment=[server, client],
            initial_context={"test_key": "test_value"},
        )

        plan.add(mtest)
        assert server.status.tag == ResourceStatus.NONE
        assert client.status.tag == ResourceStatus.NONE

        plan.run()
        res = plan.result

        assert res.run is True
        assert res.report.passed
        if idx == 0:
            assert plan.runpath == runpath
        assert mtest.runpath == os.path.join(plan.runpath,
                                             slugify(mtest.uid()))
        assert server.runpath == os.path.join(mtest.runpath, server.uid())
        assert client.runpath == os.path.join(mtest.runpath, client.uid())
        assert server.status.tag == ResourceStatus.STOPPED
        assert client.status.tag == ResourceStatus.STOPPED
Exemple #2
0
    def export(self, source):
        """Create multiple XML files in the given directory for each top level test group report."""
        xml_dir = self.cfg.xml_dir

        if os.path.exists(xml_dir):
            shutil.rmtree(xml_dir)

        os.makedirs(xml_dir)

        files = set(os.listdir(xml_dir))

        for child_report in source:
            filename = '{}.xml'.format(slugify(child_report.name))
            filename = unique_name(filename, files)
            files.add(filename)
            file_path = os.path.join(self.cfg.xml_dir, filename)

            # If a report has XML string attribute it was mostly generated via parsing
            # a JUnit compatible XML file already, meaning we don't need to re-generate
            # the XML contents, but can directly write the contents to a file instead.
            if hasattr(child_report, 'xml_string'):
                with open(file_path, 'w') as xml_target:
                    xml_target.write(child_report.xml_string)
            else:
                renderer = self.renderer_map.get(child_report.category, BaseRenderer)()
                element = etree.ElementTree(renderer.render(child_report))
                element.write(
                    file_path,
                    pretty_print=True,
                    xml_declaration=True,
                    encoding='UTF-8'
                )

        TESTPLAN_LOGGER.exporter_info(
            '%s XML files created at: %s', len(source), xml_dir)
Exemple #3
0
 def __init__(
     self,
     name,
     msgclass,
     codec,
     host,
     port,
     sender,
     target,
     version="FIX.4.2",
     sendersub=None,
     interface=None,
     connect_at_start=True,
     logon_at_start=True,
     custom_logon_tags=None,
     receive_timeout=30,
     logon_timeout=10,
     logoff_timeout=3,
     **options
 ):
     options.update(self.filter_locals(locals()))
     options.setdefault("file_logger", "{}.log".format(slugify(name)))
     super(FixClient, self).__init__(**options)
     self._host = None
     self._port = None
     self._client = None
Exemple #4
0
 def _define_remote_dirs(self):
     """Define mandatory directories in remote host."""
     testplan_path_dirs = ['', 'var', 'tmp', getpass.getuser(), 'testplan']
     self._remote_testplan_path = '/'.join(
         testplan_path_dirs + ['remote_workspaces',
                               slugify(self.cfg.parent.parent.name)])
     self._remote_testplan_runpath = '/'.join(
         [self._remote_testplan_path, 'runpath', str(self.cfg.index)])
Exemple #5
0
 def __init__(self, **options):
     super(HTTPClient, self).__init__(**options)
     self._host = None
     self._port = None
     self.timeout = None
     self.interval = None
     self.responses = None
     self._logname = '{0}.log'.format(slugify(self.cfg.name))
 def test_comparison(self, env, result):
     if self._boobytrap_path.exists():
         self._boobytrap_path.unlink()
         print("Killing worker {}".format(os.getpid()))
         os.kill(os.getpid(), 9)
     result.equal(1, 1, "equality description")
     result.log(env.parent.runpath)
     assert isinstance(env.parent.cfg, MultiTestConfig)
     assert os.path.exists(env.parent.runpath) is True
     assert env.parent.runpath.endswith(slugify(env.parent.cfg.name))
Exemple #7
0
 def _define_remote_dirs(self):
     """Define mandatory directories in remote host."""
     testplan_path_dirs = ["", "var", "tmp", getpass.getuser(), "testplan"]
     self._remote_testplan_path = "/".join(
         testplan_path_dirs +
         ["remote_worker_area",
          slugify(self.cfg.parent.parent.name)])
     self._remote_testplan_runpath = "/".join(
         [self._remote_testplan_path, "runpath",
          str(self.cfg.remote_host)])
Exemple #8
0
 def test_comparison(self, env, result):
     parent = psutil.Process(self._parent_pid)
     if len(parent.children(recursive=False)) == self._size:
         print("Killing worker {}".format(os.getpid()))
         os.kill(os.getpid(), 9)
     result.equal(1, 1, "equality description")
     result.log(env.parent.runpath)
     assert isinstance(env.parent.cfg, MultiTestConfig)
     assert os.path.exists(env.parent.runpath) is True
     assert env.parent.runpath.endswith(slugify(env.parent.cfg.name))
Exemple #9
0
    def get_proc_env(self):
        self._json_ouput = os.path.join(self.runpath, 'output.json')
        self.logger.debug('Json output: {}'.format(self._json_ouput))
        env = {'JSON_REPORT': self._json_ouput}
        env.update(
            {key.upper(): val
             for key, val in self.cfg.proc_env.items()})

        for driver in self.resources:
            driver_name = driver.uid()
            for attr in dir(driver):
                value = getattr(driver, attr)
                if attr.startswith('_') or callable(value):
                    continue
                env['DRIVER_{}_ATTR_{}'.format(
                    slugify(driver_name).replace('-', '_'),
                    slugify(attr).replace('-', '_')).upper()] = str(value)

        return env
Exemple #10
0
    def read_test_data(self):
        """
        Parse `report.xml` generated by Cppunit test and return the root node.
        XML report should be compatible with xUnit format.

        :return: Root node of parsed raw test data
        :rtype: ``xml.etree.Element``
        """
        if self.cfg.file_output_flag:
            with self.result.report.logged_exceptions(), open(
                    self.report_path) as report_file:
                return objectify.fromstring(
                    self.cppunit_to_junit(report_file.read(),
                                          slugify(self.cfg.name)))
        else:
            with open(self.stdout) as stdout:
                return objectify.fromstring(
                    self.cppunit_to_junit(stdout.read(),
                                          slugify(self.cfg.name)))
Exemple #11
0
    def get_proc_env(self):
        self._json_ouput = os.path.join(self.runpath, "output.json")
        self.logger.debug("Json output: {}".format(self._json_ouput))
        env = {"JSON_REPORT": self._json_ouput}
        env.update(
            {key.upper(): val
             for key, val in self.cfg.proc_env.items()})

        for driver in self.resources:
            driver_name = driver.uid()
            for attr in dir(driver):
                value = getattr(driver, attr)
                if attr.startswith("_") or callable(value):
                    continue
                env["DRIVER_{}_ATTR_{}".format(
                    strings.slugify(driver_name).replace("-", "_"),
                    strings.slugify(attr).replace("-", "_"),
                ).upper()] = str(value)

        return env
Exemple #12
0
 def __init__(self, **options):
     super(HTTPServer, self).__init__(**options)
     self._host = None
     self._port = None
     self.request_handler = None
     self.handler_attributes = None
     self.timeout = None
     self.requests = None
     self.responses = None
     self._server_thread = None
     self._logname = '{0}.log'.format(slugify(self.cfg.name))
Exemple #13
0
    def generate_runpath(self):
        """
        Returns runpath directory based on parent object and configuration.
        """
        # local config has highest precedence
        runpath = self.cfg.get_local("runpath")
        if runpath:
            return runpath(self) if callable(runpath) else runpath
        # else get container's runpath and append uid
        elif self.parent and self.parent.runpath:
            return os.path.join(self.parent.runpath, slugify(self.uid()))

        else:
            return default_runpath(self)
Exemple #14
0
    def _define_remote_dirs(self):
        """Define mandatory directories in remote host."""

        runpath = os.path.join(self.parent.runpath)
        runpath_parts = runpath.split(os.sep)

        # We are not using os.path.join directly in case we are running
        # remote pool from Windows -> Linux hosts
        self._remote_testplan_path = "/".join(
            runpath_parts +
            ["remote_testplan_lib",
             slugify(self.cfg.parent.parent.name)])
        self._remote_testplan_runpath = "/".join(
            runpath_parts +
            ["remote_testplan_runpath",
             str(self.cfg.remote_host)])
Exemple #15
0
    def export(self, source: TestReport) -> str:
        """
        Creates multiple XML files in the given directory for MultiTest.

        :param source:
        :return:
        """
        xml_dir = pathlib.Path(self.cfg.xml_dir).resolve()

        if xml_dir.exists():
            shutil.rmtree(xml_dir)

        xml_dir.mkdir(parents=True, exist_ok=True)

        files = set(os.listdir(xml_dir))

        for child_report in source:
            filename = "{}.xml".format(slugify(child_report.name))
            filename = unique_name(filename, files)
            files.add(filename)
            file_path = xml_dir / filename

            # TODO: "mostly" - is this just confidence or proven?
            # If a report has XML string attribute it was mostly
            # generated via parsing a JUnit compatible XML file
            # already, meaning we don't need to re-generate the XML
            # contents, but can directly write the contents to a file
            # instead.
            if hasattr(child_report, "xml_string"):
                with open(file_path, "w") as xml_target:
                    xml_target.write(child_report.xml_string)
            else:
                renderer = self.renderer_map.get(child_report.category,
                                                 BaseRenderer)()
                element = etree.ElementTree(renderer.render(child_report))
                element.write(
                    str(file_path),
                    pretty_print=True,
                    xml_declaration=True,
                    encoding="utf-8",
                )

        self.logger.exporter_info("%s XML files created at %s", len(source),
                                  xml_dir)
        return str(xml_dir)
Exemple #16
0
 def __init__(self,
              name,
              host,
              port=None,
              protocol="http",
              timeout=5,
              interval=0.01,
              **options):
     options.update(self.filter_locals(locals()))
     options.setdefault("file_logger", "{}.log".format(slugify(name)))
     super(HTTPClient, self).__init__(**options)
     self._host = None
     self._port = None
     self.protocol = None
     self.timeout = None
     self.interval = None
     self.responses = None
     self.request_threads = []
Exemple #17
0
 def __init__(self,
              name,
              host,
              port=None,
              protocol='http',
              timeout=5,
              interval=0.01,
              **options):
     options.update(self.filter_locals(locals()))
     super(HTTPClient, self).__init__(**options)
     self._host = None
     self._port = None
     self.protocol = None
     self.timeout = None
     self.interval = None
     self.responses = None
     self.request_threads = []
     self._logname = '{0}.log'.format(slugify(self.cfg.name))
Exemple #18
0
def generate_path_for_tags(config, tag_dict, filter_type):
    """
      Generate the PDF filename using the given filter and tag context.
      Will trim the filename and append a uuid suffix if it ends up
      being longer than `MAX_FILENAME_LENGTH`.

      TOOD: support custom filename generation & move logic to the exporter.

      >>> generate_pdf_path(
      ...   filter_type='all',
      ...   tag_arg_dict={
      ...     'simple': {'foo', 'bar'},
      ...     'hello': {'world', 'mars'}
      ...   }
      ... )

      <directory>/report-tags-all-foo__bar__hello-world-mars.pdf
    """
    def add_count_suffix(directory, path, count=0):
        """Add a number suffix to file name if files with same names exist."""
        target_path = '{}_{}'.format(path, count) if count else path
        full_path = os.path.join(config.report_dir, target_path + '.pdf')
        if os.path.exists(full_path):
            return add_count_suffix(directory, path, count + 1)
        return full_path

    tag_label = tagging.tag_label(tag_dict).replace(' ', '__').replace(
        '=', '-').replace(',', '-')
    path_template = 'report-tags-{filter_type}-{label}'
    path_kwargs = dict(
        filter_type=filter_type,
        label=slugify(tag_label),
    )

    if config.timestamp:
        path_template += '-{timestamp}'
        path_kwargs['timestamp'] = config.timestamp

    path = path_template.format(**path_kwargs)
    if len(path) >= MAX_FILENAME_LENGTH:
        path = '{}-{}'.format(path[:MAX_FILENAME_LENGTH], uuid.uuid4())

    return add_count_suffix(config.report_dir, path)
Exemple #19
0
    def export(self, source):
        """
        Create multiple XML files in the given directory for each top
        level test group report.
        """
        xml_dir = self.cfg.xml_dir

        if os.path.exists(xml_dir):
            shutil.rmtree(xml_dir)

        os.makedirs(xml_dir)

        files = set(os.listdir(xml_dir))

        for child_report in source:
            filename = "{}.xml".format(slugify(child_report.name))
            filename = unique_name(filename, files)
            files.add(filename)
            file_path = os.path.join(xml_dir, filename)

            # If a report has XML string attribute it was mostly
            # generated via parsing a JUnit compatible XML file
            # already, meaning we don't need to re-generate the XML
            # contents, but can directly write the contents to a file
            # instead.
            if hasattr(child_report, "xml_string"):
                with open(file_path, "w") as xml_target:
                    xml_target.write(child_report.xml_string)
            else:
                renderer = self.renderer_map.get(child_report.category,
                                                 BaseRenderer)()
                element = etree.ElementTree(renderer.render(child_report))
                element.write(
                    file_path,
                    pretty_print=True,
                    xml_declaration=True,
                    encoding="utf-8",
                )

        xml_dir = os.path.abspath(xml_dir)
        self.logger.exporter_info("%s XML files created at %s", len(source),
                                  xml_dir)
        return xml_dir
Exemple #20
0
    def __init__(self,
                 name,
                 msgclass,
                 codec,
                 host="localhost",
                 port=0,
                 version="FIX.4.2",
                 **options):
        options.update(self.filter_locals(locals()))
        options.setdefault("file_logger", "{}.log".format(slugify(name)))

        if not hasattr(select, "poll"):
            raise RuntimeError(
                "select.poll() is required for FixServer but is not available "
                "on the current platform ({})".format(platform.system()))

        super(FixServer, self).__init__(**options)
        self._host = None
        self._port = None
        self._server = None
Exemple #21
0
    def __init__(self,
                 name,
                 msgclass,
                 codec,
                 host='localhost',
                 port=0,
                 version='FIX.4.2',
                 **options):
        options.update(self.filter_locals(locals()))

        if not hasattr(select, 'poll'):
            raise RuntimeError(
                'select.poll() is required for FixServer but is not available '
                'on the current platform ({})'.format(platform.system()))

        super(FixServer, self).__init__(**options)
        self._host = None
        self._port = None
        self._server = None
        self._logname = '{0}.log'.format(slugify(self.cfg.name))
Exemple #22
0
 def __init__(self,
              name,
              host='localhost',
              port=0,
              request_handler=HTTPRequestHandler,
              handler_attributes=None,
              timeout=5,
              interval=0.01,
              **options):
     options.update(self.filter_locals(locals()))
     super(HTTPServer, self).__init__(**options)
     self._host = None
     self._port = None
     self.request_handler = None
     self.handler_attributes = None
     self.timeout = None
     self.interval = None
     self.requests = None
     self.responses = None
     self._server_thread = None
     self._logname = '{0}.log'.format(slugify(self.cfg.name))
Exemple #23
0
 def __init__(self,
              name,
              host="localhost",
              port=0,
              request_handler=HTTPRequestHandler,
              handler_attributes=None,
              timeout=5,
              interval=0.01,
              **options):
     options.update(self.filter_locals(locals()))
     options.setdefault("file_logger", "{}.log".format(slugify(name)))
     super(HTTPServer, self).__init__(**options)
     self._host = None
     self._port = None
     self.request_handler = None
     self.handler_attributes = None
     self.timeout = None
     self.interval = None
     self.requests = None
     self.responses = None
     self._server_thread = None
Exemple #24
0
    def export(self, source):
        xml_dir = self.cfg.xml_dir

        if os.path.exists(xml_dir):
            shutil.rmtree(xml_dir)

        os.makedirs(xml_dir)

        files = set(os.listdir(xml_dir))

        for child_report in source:
            renderer = self.renderer_map[child_report.category]()
            element = etree.ElementTree(renderer.render(child_report))
            filename = '{}.xml'.format(slugify(child_report.name))
            filename = unique_name(filename, files)
            files.add(filename)

            file_path = os.path.join(self.cfg.xml_dir, filename)
            element.write(file_path, pretty_print=True)

        TESTPLAN_LOGGER.exporter_info(
            '%s XML files created at: %s', len(source), xml_dir)
Exemple #25
0
 def __init__(self, **options):
     super(FixClient, self).__init__(**options)
     self._host = None
     self._port = None
     self._client = None
     self._logname = '{0}.log'.format(slugify(self.cfg.name))
Exemple #26
0
 def test_comparison(self, env, result):
     result.equal(1, 1, "equality description")
     assert isinstance(env.parent.cfg, MultiTestConfig)
     assert os.path.exists(env.parent.runpath)
     assert env.parent.runpath.endswith(slugify(env.parent.cfg.name))