def _read_test(self, table, dialect): tmpfname = self._write_tmpfile(table, dialect) exp = [list(map(str, r)) for r in table] try: self.assertEqual(exp, wrappers.read_csv(tmpfname)) finally: os.unlink(tmpfname)
def _read_test_rows(self, rows, expected): contents = "\n".join(rows) tmpfd, tmpfname = tempfile.mkstemp() tmpid = os.fdopen(tmpfd, "w") tmpid.write(contents) tmpid.close() try: self.assertEqual(expected, wrappers.read_csv(tmpfname)) finally: os.unlink(tmpfname)
def _read_test(self, table, dialect): tmpfd, tmpfname = tempfile.mkstemp() tmpid = os.fdopen(tmpfd, "w") w = writer(tmpid, dialect=dialect) w.writerows(table) tmpid.close() exp = [list(map(str, r)) for r in table] try: self.assertEqual(exp, wrappers.read_csv(tmpfname)) finally: os.unlink(tmpfname)
def handle(self): verbose = self.io.verbosity > 0 num_chars = parse_int(self.option("num-chars"), "num-chars") try: rows = read_csv( self.argument("path"), encoding=self.option("encoding"), num_chars=num_chars, verbose=verbose, ) except NoDetectionResult: self.line("Dialect detection failed.") if self.option("transpose"): rows = list(map(list, zip(*rows))) tabview.view(rows)