Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _write_error_test(self, exc, fields, **kwargs):
with tempfile.TemporaryFile("w+", newline="", prefix="ccsv_") as fp:
writer = clevercsv.writer(fp, **kwargs)
with self.assertRaises(exc):
writer.writerow(fields)
fp.seek(0)
self.assertEqual(fp.read(), "")
def _df_test(self, table, dialect, **kwargs):
tmpfd, tmpfname = tempfile.mkstemp(prefix="ccsv_", suffix=".csv")
tmpid = os.fdopen(tmpfd, "w")
w = writer(tmpid, dialect=dialect)
w.writerows(table)
tmpid.close()
exp_df = pd.DataFrame.from_records(table[1:], columns=table[0])
df = wrappers.csv2df(tmpfname)
try:
self.assertTrue(df.equals(exp_df))
finally:
os.unlink(tmpfname)
def _df_test(self, table, dialect, **kwargs):
tmpfd, tmpfname = tempfile.mkstemp(prefix="ccsv_", suffix=".csv")
tmpid = os.fdopen(tmpfd, "w")
w = writer(tmpid, dialect=dialect)
w.writerows(table)
tmpid.close()
exp_df = pd.DataFrame.from_records(table[1:], columns=table[0])
df = wrappers.csv2df(tmpfname)
try:
self.assertTrue(df.equals(exp_df))
finally:
os.unlink(tmpfname)
def _write_tmpfile(self, table, dialect):
""" Write a table to a temporary file using specified dialect """
tmpfd, tmpfname = tempfile.mkstemp(prefix="ccsv_", suffix=".csv")
tmpid = os.fdopen(tmpfd, "w")
w = writer(tmpid, dialect=dialect)
w.writerows(table)
tmpid.close()
return tmpfname
def _write_tmpfile(self, table, dialect):
""" Write a table to a temporary file using specified dialect """
tmpfd, tmpfname = tempfile.mkstemp(prefix="ccsv_", suffix=".csv")
tmpid = os.fdopen(tmpfd, "w")
w = writer(tmpid, dialect=dialect)
w.writerows(table)
tmpid.close()
return tmpfname