def test_bedtools_window_sm(): """ These two flags have almost the same name, and almost the same description """ flags = [ Flag( synonyms=["-sm"], description= "Only report hits in B that overlap A on the _same_ strand.", args=EmptyFlagArg(), ), Flag( synonyms=["-sm"], description= "Only report hits in B that overlap A on the _opposite_ strand.", args=EmptyFlagArg(), ), Flag( synonyms=["-c"], description= "For each entry in A, report the number of overlaps with B.", args=EmptyFlagArg(), ), ] args = WrapperGenerator().choose_variable_names(flags) assert len(set([arg.name for arg in args])) == 3
def test_same_arg(): """ Normally we ignore one-character flag names, and instead try to read their descriptions for a more informative name. However, if the descriptions are identical to each other, we have to fall back to the description """ flags = [ Flag(synonyms=["-a"], description="", args=SimpleFlagArg("SomeThing")), Flag(synonyms=["-b"], description="", args=SimpleFlagArg("SomeThing")), ] names = WrapperGenerator().choose_variable_names(flags) assert names[0].name == "a" assert names[1].name == "b"
def test_snake_short(snake_gen): flag = Flag( synonyms=["-t"], description="number of threads [1]", args=EmptyFlagArg() ) names = snake_gen.choose_variable_names([flag], length=2) assert "number" in names[0].name assert "threads" in names[0].name
def test_snake_long(snake_gen): flag = Flag( synonyms=["-g", "--genomepaths", "--genomefolders"], description="number of threads [1]", args=EmptyFlagArg(), ) names = snake_gen.choose_variable_names([flag], length=2) assert names[0].name == "genome_folders"
def test_name_to_words_symbol(gen): """ Check that we can get an argument name even if the argument's flag is a symbol """ arg = Flag( synonyms=["-@"], description="Number of additional threads to use", args=EmptyFlagArg(), ) name = gen.choose_variable_names([arg])[0].name assert name == "at"
def test_samtools_dict_output(): gen = WdlGenerator() arg = Flag( synonyms=["-o", "--output"], description="file to write out dict file [stdout]", args=SimpleFlagArg(name="str"), ) name = gen.choose_variable_names([arg])[0].name # The WDL converter should avoid naming a variable "output" since that's a WDL keyword assert name != "output" # Also, since we have a description, the generator shouldn't choose the lazy option of var_output assert name != "var_output"
def test_name_to_words(gen): """ Check that we can get an argument name even if the argument's flag is a symbol """ arg = Flag( synonyms=["--genomepaths"], description="", args=EmptyFlagArg(), ) name = gen.choose_variable_names([arg])[0].name assert "genome" in name assert "paths" in name
def visit_short_flag_list(s, loc, toks): return [ Flag.from_synonyms( [FlagSynonym(name="-" + flag, argtype=EmptyFlagArg())], description=None) for flag in toks[1:] ]
options_placeholder = (Regex( "options?", flags=re.IGNORECASE).suppress().setName("OptionsPlaceholder")) list_element = ( (OneOrMore(options_placeholder ^ mandatory_element ^ variable_element) + Literal(".")[2, 3] + Optional(options_placeholder ^ mandatory_element ^ variable_element) ).setParseAction(visit_list_element).setName("list_element")) """ When one or more arguments are allowed, e.g. "<in2.bam> ... <inN.bam>" """ usage_flag = (And([flag_with_arg ]).setParseAction(lambda s, loc, toks: Flag.from_synonyms( toks, description="")).setName("usage_flag")) usage_element <<= Or([ optional_section, list_element, # short_flag_list, usage_flag, variable_element, options_placeholder, mandatory_element, ]).setName("usage_element") stack = [1] def visit_usage(s, loc, toks):
def test_camel_short(camel_gen): flag = Flag( synonyms=["-t"], description="number of threads [1]", args=EmptyFlagArg() ) names = camel_gen.choose_variable_names([flag], length=3) assert names[0].name == "numberOfThreads"
def test_bwt2sa_i(gen): arg = Flag(synonyms=["-i"], description="", args=SimpleFlagArg(name="32")) name = gen.choose_variable_names([arg])[0].name # 32 isn't a valid variable name, so the only option here is to use the letter i assert name == "i"