def raw_data(self, filename): """Return the raw pickled data from `filename`.""" if self.debug and self.debug.should('dataio'): self.debug.write("Reading data from %r" % (filename, )) with open(filename, 'rb') as fdata: data = pickle.load(fdata) return data
def raw_data(self, filename): """Return the raw pickled data from `filename`.""" if self.debug and self.debug.should('dataio'): self.debug.write("Reading data from %r" % (filename,)) with open(filename, 'rb') as fdata: data = pickle.load(fdata) return data
def read(self, directory): """Read the last status in `directory`.""" usable = False try: status_file = os.path.join(directory, self.STATUS_FILE) fstatus = open(status_file, 'rb') try: status = pickle.load(fstatus) finally: fstatus.close() except (IOError, ValueError): usable = False else: usable = True if status['format'] != self.STATUS_FORMAT: usable = False elif status['version'] != coverage.__version__: usable = False if usable: self.files = status['files'] self.settings = status['settings'] else: self.reset()
def raw_data(self, filename): """Return the raw pickled data from `filename`.""" fdata = open(filename, 'rb') try: data = pickle.load(fdata) finally: fdata.close() return data
def raw_data(self, filename): """Return the raw pickled data from `filename`.""" if self.debug and self.debug.should("dataio"): self.debug.write("Reading data from %r" % (filename,)) fdata = open(filename, "rb") try: data = pickle.load(fdata) finally: fdata.close() return data
def raw_data(self, filename): if self.debug and self.debug.should('dataio'): self.debug.write('Reading data from %r' % (filename,)) fdata = open(filename, 'rb') try: data = pickle.load(fdata) finally: fdata.close() return data
def raw_data(self, filename): """Return the raw pickled data from `filename`.""" if self.debug and self.debug.should('dataio'): self.debug.write("Reading data from %r" % (filename, )) fdata = open(filename, 'rb') try: data = pickle.load(fdata) finally: fdata.close() return data
def raw_data(self, filename): if self.debug and self.debug.should('dataio'): self.debug.write('Reading data from %r' % (filename, )) fdata = open(filename, 'rb') try: data = pickle.load(fdata) finally: fdata.close() return data
def test_file_format_with_arcs(self): # Write with CoverageData, then read the pickle explicitly. covdata = CoverageData() covdata.add_arc_data(ARC_DATA_3) covdata.write() with open(".coverage", 'rb') as fdata: data = pickle.load(fdata) self.assertCountEqual(data['lines'].keys(), []) arcs = data['arcs'] self.assertCountEqual(arcs['x.py'], X_PY_ARCS_3) self.assertCountEqual(arcs['y.py'], Y_PY_ARCS_3)
def test_file_format(self): # Write with CoverageData, then read the pickle explicitly. covdata = CoverageData() covdata.add_line_data(DATA_1) covdata.write() with open(".coverage", 'rb') as fdata: data = pickle.load(fdata) lines = data['lines'] self.assertCountEqual(lines.keys(), MEASURED_FILES_1) self.assertCountEqual(lines['a.py'], A_PY_LINES_1) self.assertCountEqual(lines['b.py'], B_PY_LINES_1) # If not measuring branches, there's no arcs entry. self.assertEqual(data.get('arcs', 'not there'), 'not there')
def test_file_format_with_arcs(self): # Write with CoverageData, then read the pickle explicitly. covdata = CoverageData() covdata.add_arc_data(ARC_DATA_3) covdata.write() fdata = open(".coverage", 'rb') try: data = pickle.load(fdata) finally: fdata.close() self.assertSameElements(data['lines'].keys(), []) arcs = data['arcs'] self.assertSameElements(arcs['x.py'], X_PY_ARCS_3) self.assertSameElements(arcs['y.py'], Y_PY_ARCS_3)
def read(self, file_obj): """Read the coverage data from the given file object. Should only be used on an empty CoverageData object. """ try: data = pickle.load(file_obj) if isinstance(data, dict): # Unpack the 'lines' item. self._lines = dict([(f, dict.fromkeys(linenos, None)) for f, linenos in iitems(data.get("lines", {}))]) # Unpack the 'arcs' item. self._arcs = dict([(f, dict.fromkeys(arcpairs, None)) for f, arcpairs in iitems(data.get("arcs", {}))]) self._plugins = data.get("plugins", {}) except Exception: # TODO: this used to handle file-doesnt-exist problems. Do we still need it? pass
def test_file_format(self): # Write with CoverageData, then read the pickle explicitly. covdata = CoverageData() covdata.add_line_data(DATA_1) covdata.write() fdata = open(".coverage", "rb") try: data = pickle.load(fdata) finally: fdata.close() lines = data["lines"] self.assertSameElements(lines.keys(), MEASURED_FILES_1) self.assertSameElements(lines["a.py"], A_PY_LINES_1) self.assertSameElements(lines["b.py"], B_PY_LINES_1) # If not measuring branches, there's no arcs entry. self.assertEqual(data.get("arcs", "not there"), "not there")
def test_file_format(self): # Write with CoverageData, then read the pickle explicitly. covdata = CoverageData() covdata.add_line_data(DATA_1) covdata.write() fdata = open(".coverage", 'rb') try: data = pickle.load(fdata) finally: fdata.close() lines = data['lines'] self.assertSameElements(lines.keys(), EXECED_FILES_1) self.assertSameElements(lines['a.py'], A_PY_LINES_1) self.assertSameElements(lines['b.py'], B_PY_LINES_1) # If not measuring branches, there's no arcs entry. self.assertEqual(data.get('arcs', 'not there'), 'not there')
def read(self, directory): """Read the last status in `directory`.""" usable = False try: status_file = os.path.join(directory, self.STATUS_FILE) status = pickle.load(open(status_file, "rb")) except IOError: usable = False else: usable = True if status['format'] != self.STATUS_FORMAT: usable = False elif status['version'] != coverage.__version__: usable = False if usable: self.files = status['files'] self.settings = status['settings'] else: self.reset()
def read(self, directory): usable = False try: status_file = os.path.join(directory, self.STATUS_FILE) fstatus = open(status_file, 'rb') try: status = pickle.load(fstatus) finally: fstatus.close() except (IOError, ValueError): usable = False else: usable = True if status['format'] != self.STATUS_FORMAT: usable = False elif status['version'] != coverage.__version__: usable = False if usable: self.files = status['files'] self.settings = status['settings'] else: self.reset()
def pickle_read_raw_data(cls_unused, file_obj): """Replacement for CoverageData._read_raw_data.""" return pickle.load(file_obj)