How to write unit testcase to check if input file is a csv file (with assert statement) using python?

Viewed 316

I have already witten a python code to convert json file to csv file in pycharm IDE like this:

import pandas as pd
import csv

df = pd.read_json(r"json file path")
df.to_csv(r"csv file path")


def read_data(data):
    with open(data, "r") as f:
        data = [row for row in csv.reader(f.read().splitlines())]
        return data
data = "generatedcsvfilename.csv"
read_data(data)

Now I have to read the generated csv file to write unit testcases in python.

POSSIBLE TESTCASES:

  1. To check if CSV file has been generated from json file in the specified folder.

  2. To check if the file extension is .csv

  3. To check if the CSV file is not empty.

Please help me to write unit testcases for the above listed testcases in python

Suggest me some more possible testcases if any.

0 Answers
Related