예제 #1
0
파일: engine.py 프로젝트: hugovk/pytest-cov
    def testnodedown(self, node, error):
        """Collect data file name from slave."""

        # If slave doesn't return any data then it is likely that this
        # plugin didn't get activated on the slave side.
        if not (hasattr(node, 'slaveoutput') and 'cov_slave_node_id' in node.slaveoutput):
            self.failed_slaves.append(node)
            return

        # If slave is not collocated then we must save the data file
        # that it returns to us.
        if 'cov_slave_data' in node.slaveoutput:
            data_suffix = '%s.%s.%06d.%s' % (
                socket.gethostname(), os.getpid(),
                random.randint(0, 999999),
                node.slaveoutput['cov_slave_node_id']
                )

            cov = coverage.coverage(source=self.cov_source,
                                    branch=self.cov_branch,
                                    data_suffix=data_suffix,
                                    config_file=self.cov_config)
            cov.start()
            data = CoverageData()
            data.read_fileobj(StringIO(node.slaveoutput['cov_slave_data']))
            cov.data.update(data)
            cov.stop()
            cov.save()
            path = node.slaveoutput['cov_slave_path']
            self.cov.config.paths['source'].append(path)

        # Record the slave types that contribute to the data file.
        rinfo = node.gateway._rinfo()
        node_desc = self.get_node_desc(rinfo.platform, rinfo.version_info)
        self.node_descs.add(node_desc)
예제 #2
0
    def testnodedown(self, node, error):
        """Collect data file name from slave."""

        # If slave doesn't return any data then it is likely that this
        # plugin didn't get activated on the slave side.
        if not (hasattr(node, 'slaveoutput') and 'cov_slave_node_id' in node.slaveoutput):
            self.failed_slaves.append(node)
            return

        # If slave is not collocated then we must save the data file
        # that it returns to us.
        if 'cov_slave_data' in node.slaveoutput:
            data_suffix = '%s.%s.%06d.%s' % (
                socket.gethostname(), os.getpid(),
                random.randint(0, 999999),
                node.slaveoutput['cov_slave_node_id']
                )

            cov = coverage.Coverage(source=self.cov_source,
                                    branch=self.cov_branch,
                                    data_suffix=data_suffix,
                                    config_file=self.cov_config)
            cov.start()
            data = CoverageData()
            data.read_fileobj(StringIO(node.slaveoutput['cov_slave_data']))
            cov.data.update(data)
            cov.stop()
            cov.save()
            path = node.slaveoutput['cov_slave_path']
            self.cov.config.paths['source'].append(path)

        # Record the slave types that contribute to the data file.
        rinfo = node.gateway._rinfo()
        node_desc = self.get_node_desc(rinfo.platform, rinfo.version_info)
        self.node_descs.add(node_desc)
예제 #3
0
    def test_read_and_write_are_opposites(self):
        covdata1 = CoverageData()
        covdata1.add_arcs(ARCS_3)
        stringio = StringIO()
        covdata1.write_fileobj(stringio)

        stringio.seek(0)
        covdata2 = CoverageData()
        covdata2.read_fileobj(stringio)
        self.assert_arcs3_data(covdata2)
예제 #4
0
    def test_read_and_write_are_opposites(self):
        covdata1 = CoverageData()
        covdata1.add_arcs(ARCS_3)
        stringio = StringIO()
        covdata1.write_fileobj(stringio)

        stringio.seek(0)
        covdata2 = CoverageData()
        covdata2.read_fileobj(stringio)
        self.assert_arcs3_data(covdata2)
예제 #5
0
def pickle2json(infile, outfile):
    """Convert a coverage.py 3.x pickle data file to a 4.x JSON data file."""
    try:
        old_read_raw_data = CoverageData._read_raw_data
        CoverageData._read_raw_data = pickle_read_raw_data

        covdata = CoverageData()

        with open(infile, 'rb') as inf:
            covdata.read_fileobj(inf)

        covdata.write_file(outfile)
    finally:
        CoverageData._read_raw_data = old_read_raw_data
예제 #6
0
파일: pickle2json.py 프로젝트: 2070616d/TP3
def pickle2json(infile, outfile):
    """Convert a coverage.py 3.x pickle data file to a 4.x JSON data file."""
    try:
        old_read_raw_data = CoverageData._read_raw_data
        CoverageData._read_raw_data = pickle_read_raw_data

        covdata = CoverageData()

        with open(infile, 'rb') as inf:
            covdata.read_fileobj(inf)

        covdata.write_file(outfile)
    finally:
        CoverageData._read_raw_data = old_read_raw_data
예제 #7
0
    def testnodedown(self, node, error):
        """Collect data file name from worker."""

        # If worker doesn't return any data then it is likely that this
        # plugin didn't get activated on the worker side.
        output = workeroutput(node, {})
        if 'cov_worker_node_id' not in output:
            self.failed_workers.append(node)
            return

        # If worker is not collocated then we must save the data file
        # that it returns to us.
        if 'cov_worker_data' in output:
            data_suffix = '%s.%s.%06d.%s' % (
                socket.gethostname(), os.getpid(),
                random.randint(0, 999999),
                output['cov_worker_node_id']
                )

            cov = coverage.Coverage(source=self.cov_source,
                                    branch=self.cov_branch,
                                    data_suffix=data_suffix,
                                    config_file=self.cov_config)
            cov.start()
            if coverage.version_info < (5, 0):
                data = CoverageData()
                data.read_fileobj(StringIO(output['cov_worker_data']))
                cov.data.update(data)
            else:
                data = CoverageData(no_disk=True)
                data.loads(output['cov_worker_data'])
                cov.get_data().update(data)
            cov.stop()
            cov.save()
            path = output['cov_worker_path']
            self.cov.config.paths['source'].append(path)

        # Record the worker types that contribute to the data file.
        rinfo = node.gateway._rinfo()
        node_desc = self.get_node_desc(rinfo.platform, rinfo.version_info)
        self.node_descs.add(node_desc)