예제 #1
0
def logmerge_config_object():
    """
    A fixture for supplying a default LogmergeConfig object to test functions.
    """

    # TODO:  Update the default configuration for tests to locations in the test directories.
    config_parser = create_default_config()
    return LogmergeConfig(create_default_config())
예제 #2
0
 def test_handle_output_location_argument_custom_file_exists(
         self, arg_parser, logmerge_config_object, argparse_test_dir):
     configuration = LogmergeConfig(create_default_config())
     argument_list = ["-o", str(Path(argparse_test_dir, "exists.csv"))]
     argument_namespace = arg_parser.parse_args(argument_list)
     with pytest.raises(FileExistsError):
         configuration = update_configuration_from_args(
             configuration, argument_namespace)
예제 #3
0
 def test_handle_output_location_argument_custom_directory(
         self, arg_parser, logmerge_config_object, argparse_test_dir):
     configuration = LogmergeConfig(create_default_config())
     argument_list = ["-o", str(argparse_test_dir)]
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.output_location.parent == argparse_test_dir
     assert configuration.output_location.name.endswith(".csv")
예제 #4
0
 def test_handle_recursive_argument_default(self, arg_parser,
                                            logmerge_config_object,
                                            argparse_test_dir):
     config_file = create_default_config()
     configuration = LogmergeConfig(config_file)
     assert configuration.recursive is False
     argument_list = []
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.recursive is False
예제 #5
0
 def test_handle_recursive_argument_false(self, arg_parser,
                                          logmerge_config_object,
                                          argparse_test_dir):
     config_file = create_default_config()
     config_file["SEARCH"]["AutoRecursive"] = str(True)
     configuration = LogmergeConfig(config_file)
     assert configuration.recursive is True
     argument_list = ["-R"]
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.recursive is False
예제 #6
0
 def test_handle_header_argument_bad(self, arg_parser,
                                     logmerge_config_object,
                                     argparse_test_dir):
     config_file = create_default_config()
     configuration = LogmergeConfig(config_file)
     custom_header = "[\\fnord"
     assert configuration.header == default_header
     argument_list = ["-t", repr(custom_header)]
     args_namespace = arg_parser.parse_args(argument_list)
     with pytest.raises(ArgumentTypeError):
         configuration = update_configuration_from_args(
             configuration, args_namespace)
예제 #7
0
 def test_handle_header_argument_custom(self, arg_parser,
                                        logmerge_config_object,
                                        argparse_test_dir):
     config_file = create_default_config()
     configuration = LogmergeConfig(config_file)
     custom_header = ["one", "two", "three"]
     assert configuration.header == default_header
     argument_list = ["-t", repr(custom_header)]
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.header == custom_header
예제 #8
0
 def test_handle_header_argument_false(self, arg_parser,
                                       logmerge_config_object,
                                       argparse_test_dir):
     # TODO:  Is None how this should be expressed?
     config_file = create_default_config()
     configuration = LogmergeConfig(config_file)
     assert configuration.header == default_header
     argument_list = ["-T"]
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.header is None
예제 #9
0
 def test_handle_header_argument_true(self, arg_parser,
                                      logmerge_config_object,
                                      argparse_test_dir):
     # TODO:  Allow this to be false by default?
     config_file = create_default_config()
     configuration = LogmergeConfig(config_file)
     assert configuration.header == default_header
     argument_list = ["-t"]
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.header == default_header
예제 #10
0
 def test_handle_archive_argument_exists(self, arg_parser,
                                         logmerge_config_object,
                                         argparse_test_dir):
     config_file = create_default_config()
     config_file["ARCHIVE"]["AutoArchive"] = str(False)
     configuration = LogmergeConfig(config_file)
     assert configuration.archive is False
     argument_list = ["-a", str(Path(argparse_test_dir, "exists.csv"))]
     args_namespace = arg_parser.parse_args(argument_list)
     with pytest.raises(FileExistsError):
         configuration = update_configuration_from_args(
             configuration, args_namespace)
예제 #11
0
 def test_handle_archive_argument_default(self, arg_parser,
                                          logmerge_config_object,
                                          argparse_test_dir):
     config_file = create_default_config()
     config_file["ARCHIVE"]["Folder"] = str(argparse_test_dir)
     configuration = LogmergeConfig(config_file)
     argument_list = []
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.archive_folder.parent == argparse_test_dir
     assert configuration.archive is True
예제 #12
0
 def test_handle_output_location_argument_default(self, arg_parser,
                                                  logmerge_config_object,
                                                  argparse_test_dir):
     configfile = create_default_config()
     configfile["OUTPUT"]["Folder"] = str(argparse_test_dir)
     configuration = LogmergeConfig(configfile)
     assert configuration is not None
     argument_list = []
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.output_location.parent == argparse_test_dir
     assert configuration.output_location.name.endswith(".csv")
예제 #13
0
 def test_read_custom_config(self, tmp_path):
     archive_path = Path(tmp_path, "archive")
     config_file_path = Path(tmp_path, "config.cfg")
     assert not config_file_path.exists()
     assert not archive_path.exists()
     archive_path.mkdir()
     assert archive_path.exists()
     cfg = create_default_config()
     cfg["ARCHIVE"]["Folder"] = str(archive_path)
     with config_file_path.open(mode="w") as cfg_outfile:
         cfg.write(cfg_outfile)
     assert config_file_path.exists()
     read_config = load_or_create_configparser(config_file_path)
     assert read_config.get("ARCHIVE", "Folder") == str(archive_path)
예제 #14
0
 def test_handle_archive_argument_custom(self, arg_parser,
                                         logmerge_config_object,
                                         argparse_test_dir):
     config_file = create_default_config()
     config_file["ARCHIVE"]["AutoArchive"] = str(False)
     configuration = LogmergeConfig(config_file)
     assert configuration.archive is False
     argument_list = ["-a", str(Path(argparse_test_dir, "subdirectory"))]
     args_namespace = arg_parser.parse_args(argument_list)
     configuration = update_configuration_from_args(configuration,
                                                    args_namespace)
     assert configuration.archive_folder.parent == Path(
         argparse_test_dir, "subdirectory")
     assert configuration.archive is True
예제 #15
0
 def test_custom_config(self, tmp_path):
     # TODO: Remove this duplication.
     archive_path = Path(tmp_path, "archive")
     config_file_path = Path(tmp_path, "config.cfg")
     assert not config_file_path.exists()
     assert not archive_path.exists()
     archive_path.mkdir()
     assert archive_path.exists()
     cfg = create_default_config()
     cfg["ARCHIVE"]["Folder"] = str(archive_path)
     with config_file_path.open(mode="w") as cfg_outfile:
         cfg.write(cfg_outfile)
     assert config_file_path.exists()
     lmc = get_configuration(config_file_path)
     assert lmc.archive_folder == archive_path