def create_file(filename): """ >>> create_file("staffinfo2.csv") [] """ csv = CSVOperations(filename, True) return csv.read()
def select_source(self, source, file_path=None, create=False): """ Initialise the data source :param source: <String> :param file_path: <Sting> :param create: <Boolean> :return: None :Author: Zhiming Liu """ # Set _self as an object of data operation when it hasn't been set if source == "csv": self._source = CSVOperations(file_path, create) self.load_data() if source == "db": self._source = Database() self.load_data()
def test_14(self): csv = CSVOperations("staffinfo.csv") self.assertTrue(type(csv.read()) == list)
def test_11(self): csv = CSVOperations("staffinfo.csv") self.assertRaises(AttributeError, csv.save, "This is a data list")
def test_05(self): csv = CSVOperations("staffinfo2.csv") self.assertFalse(csv.file_exist())
def test_02(self): csv = CSVOperations("staffinfo.csv") items = ["EMPID", "GENDER", "AGE", "SALES", "BMI", "SALARY", "BIRTHDAY"] self.assertListEqual(csv._fieldnames, items)
def test_01(self): csv = CSVOperations("staffinfo.csv") self.assertTrue(type(csv._fieldnames) == list)
def import_csv(self, filename): try: csv = CSVOperations(filename) self.import_result(csv.read()) except Exception as e: View.error(e)