def test_create_empty( self, mocked_path, mocked_user_config_dir, mocked_mkdir_p, mocked_exists, mocked_copyfile, ): """Test create the config file in an empty directory.""" # setup mocks mocked_exists.return_value = False # call the function with self.assertLogs("dakara_base.config") as logger: create_config_file("module.resources", "config.yaml") # assert the call mocked_path.assert_called_with("module.resources", "config.yaml") mocked_mkdir_p.assert_called_with() mocked_exists.assert_called_with() mocked_copyfile.assert_called_with( Path("path") / "to" / "directory" / "config.yaml") # assert the logs self.assertListEqual( logger.output, [ "INFO:dakara_base.config:Config created in '{}'".format( Path("path") / "to" / "directory" / "config.yaml") ], )
def create_config(args): """Create the config file Args: args (argparse.Namespace): arguments from command line. """ create_logger(custom_log_format="%(message)s", custom_log_level="INFO") create_config_file("dakara_player.resources", CONFIG_FILE, args.force) logger.info("Please edit this file")
def test_create_existing_force( self, mocked_input, mocked_path, mocked_user_config_dir, mocked_mkdir_p, mocked_exists, mocked_copyfile, ): """Test create the config file in a non empty directory with force overwrite.""" # call the function create_config_file("module.resources", "config.yaml", force=True) # assert the call mocked_exists.assert_not_called() mocked_input.assert_not_called() mocked_copyfile.assert_called_with( Path("path") / "to" / "directory" / "config.yaml")
def test_create_existing_invalid_input( self, mocked_input, mocked_path, mocked_user_config_dir, mocked_mkdir_p, mocked_exists, mocked_copyfile, ): """Test create the config file in a non empty directory with invalid input.""" # setup mocks mocked_exists.return_value = True mocked_input.return_value = "" # call the function create_config_file("module.resources", "config.yaml") # assert the call mocked_copyfile.assert_not_called()
def test_create_existing_no( self, mocked_input, mocked_path, mocked_user_config_dir, mocked_mkdir_p, mocked_exists, mocked_copyfile, ): """Test create the config file in a non empty directory.""" # setup mocks mocked_exists.return_value = True mocked_input.return_value = "no" # call the function create_config_file("module.resources", "config.yaml") # assert the call mocked_copyfile.assert_not_called() mocked_input.assert_called_with( "{} already exists, overwrite? [y/N] ".format( Path("path") / "to" / "directory" / "config.yaml"))