def test_bad_file_csv_save(): io = IO() with pytest.raises(TypeError): io.csv_save(["/tmp/test.csv", ","])
def test_bad_file2_csv_save(): io = IO() io.row_list = [2, 2] with pytest.raises(csv.Error): io.csv_save("/tmp/test.csv", ",")
def test_good_path_csv_save(): io = IO() io.csv_save("/tmp/test.csv", ",")
def test_bad_file2_csv_save(): io=IO() io.row_list=[2,2] with pytest.raises(csv.Error): io.csv_save("/tmp/test.csv",",")
def test_bad_file_csv_save(): io=IO() io.row_list=2 with pytest.raises(TypeError): io.csv_save("/tmp/test.csv",",")
def test_good_path_csv_save(): io=IO() io.csv_save("/tmp/test.csv",",")
class AppConfig(object): """This class reads the status of the UI and and parses the data so that it's suitable to be saved as a csv, and the reverse """ def __init__(self, config_file): """Default config, they will be overwritten when a conf is loaded this will be used to write a default config file. If the command line specifies a config file we note it in alternate_config_file and we use it, otherwise we check for the default one. :param alternate_config_file: config file passed as input argument :type alternate_config_file: string :raises: none :returns:none """ self.io = IO() self.config_file = config_file self.config = dict.copy(DEFAULT_CONFIG) def read_conf(self): """Read the configuration file. If the default one doesn't exist we create one with sane values. and then we re-read it. It logs an error if a line of the file is not valid and moves on to the next one. :param: none :raises: none :returns: none """ if os.path.isfile(self.config_file): logger.info("Using config file:{}".format(self.config_file)) self.io.csv_load(self.config_file, "=") error = 0 for row in self.io.row_list: if len(row) == 2 and row[0].strip() in self.config.keys() : self.config[row[0].strip()] = row[1].strip() else: logger.warning("Error in config file line: " + str(row)) else: self.write_conf() self.read_conf() def write_conf(self): """Writes the configuration to file. If the default config path is missing it will be created. If this is not possible the config file will not be saved. :param: none :raises: IOError, OSError if it is not possible to write the config :returns: none """ self.io.row_list = [] try: os.makedirs(os.path.dirname(self.config_file)) except IOError: logger.info("Error while trying to create config "\ "path as {}".format(self.config_file)) except OSError: logger.info("The config directory already exists.") for key in self.config.keys(): row = [] row.append(key) row.append(self.config[key]) self.io.row_list.append(row) self.io.csv_save(self.config_file, "=")