Exemplo n.º 1
0
 def test_misfed_serialization(self):
     covdata = CoverageData(no_disk=True)
     bad_data = b'Hello, world!\x07 ' + b'z' * 100
     msg = r"Unrecognized serialization: {} \(head of {} bytes\)".format(
         re.escape(repr(bad_data[:40])),
         len(bad_data),
     )
     with self.assertRaisesRegex(CoverageException, msg):
         covdata.loads(bad_data)
Exemplo n.º 2
0
 def test_misfed_serialization(self):
     covdata = CoverageData(no_disk=True)
     bad_data = b'Hello, world!\x07 ' + b'z' * 100
     msg = r"Unrecognized serialization: {} \(head of {} bytes\)".format(
         re.escape(repr(bad_data[:40])),
         len(bad_data),
     )
     with pytest.raises(DataError, match=msg):
         covdata.loads(bad_data)
Exemplo n.º 3
0
    def test_serialization(self):
        covdata1 = CoverageData(no_disk=True)
        covdata1.add_lines(LINES_1)
        covdata1.add_lines(LINES_2)
        serial = covdata1.dumps()

        covdata2 = CoverageData(no_disk=True)
        covdata2.loads(serial)
        self.assert_line_counts(covdata2, SUMMARY_1_2)
        self.assert_measured_files(covdata2, MEASURED_FILES_1_2)
Exemplo n.º 4
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)