vendredi 26 juin 2020

How to do use assertEqual to verify lines in csv loaded?

I am trying to do a unit test in my unit_test.py to verify that all lines from the csv file loaded successfully in the main.py. The code in main.py works perfectly fine and it did show 40000 lines loaded when I tested with "print(len(my_file)" in the main.py. However, when I tried to do self.asserEqual(40000, len(file.filename)) in the unit_test.py, it showed there are only 17 lines. Can someone point me to the right direction? I think I use the assertEqual in a wrong way

Main.py

import csv

datafile = './AB_LA_2019.csv'

class AirbnbData:

........
........
    def load_data(self):
    with open(datafile, 'r', newline='') as file:
        csvreader = csv.reader(file)
        next(file)
        my_file = [(row[1], row[2], int(row[3])) for row in csvreader]
        self._airbnbdata = my_file


    self._generate()

unit_test.py

   import unittest
   import main as airbnb


   class testAirbnb(unittest.TestCase):

       def test_line(self):
       self.assertEqual(40000, len(airbnb.datafile))

Aucun commentaire:

Enregistrer un commentaire