Hi,

I was just trying to integrate the patch from MAHOUT-407 into the head
when I ran into another issue. It seems to me like the default values
given to addOption(...) are not correctly returned by
parseArguments(...). Can anybody please check that? I'm not familiar
enough with CLI to fix it myself.

-sebastian

A unit test to confirm the problem:

package org.apache.mahout.common;

import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ToolRunner;
import org.apache.mahout.common.AbstractJob;
import org.apache.mahout.math.MahoutTestCase;

public class AbstractJobTest extends MahoutTestCase {

  private static class TestJob extends AbstractJob {
    private String valueOfTestOption;
    @Override
    public int run(String[] args) throws Exception {
      addOption("test", "t", "an option having a default value", "default");
      Map<String,String> parsedArgs = parseArguments(args);
      valueOfTestOption = parsedArgs.get("--test");
      return 0;
    }
    public String getValueOfTestOption() {
      return valueOfTestOption;
    }
  }

  private TestJob job;
  private Configuration conf;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    job = new TestJob();
    conf = new Configuration();
    job.setConf(conf);
  }

  public void testValueForOption() throws Exception {
    ToolRunner.run(job, new String[] { "--test", "value" });
    assertEquals("value", job.getValueOfTestOption());
  }

  public void testDefaultValueForOption() throws Exception {
    job.run(new String[] {});
    //this assertion fails with current head
    assertEquals("default", job.getValueOfTestOption());
  }

}

Reply via email to