我有两个文件,FinalProject.py和Test_FinalProject.py。
我的测试类的代码是:
import unittest
import FinalProject
class TestFinalProject(unittest.TestCase):
def test_read_dataset(self):
dsm = FinalProject.DatasetManager()
dsm.read_dataset()
self.assertEqual(len(dsm.list_potatoes), 6480)
if __name__ == '__main__':
unittest.main()
每次我从PyCharm或cmd中运行它时,无论我做了什么更改,我的FinalProject.py代码都会运行。我哪里错了?感谢。
编辑:来自FinalProject.py的代码
class DatasetManager():
def __init__(self):
self.list_potatoes = []
self.sorted_list_potatoes = []
def read_dataset(self):
try:
with open('00010014-eng.csv') as csvfile:
reader = csv.reader(csvfile, delimiter='|')
self.list_potatoes = list(reader)
csvfile.close()
except IOError:
print("Could not read file.")
def get_record_count(self):
return len(self.list_potatoes)
答案 0 :(得分:0)
让我们试试这个:
class DatasetManager():
def __init__(self):
self.list_potatoes = []
self.sorted_list_potatoes = []
def read_dataset(self):
try:
with open('00010014-eng.csv') as csvfile:
reader = csv.reader(csvfile, delimiter='|')
self.list_potatoes += list(reader)
except IOError:
print("Could not read file.")
def get_record_count(self):
return len(self.list_potatoes)