本文整理汇总了Python中commandlines.Command类的典型用法代码示例。如果您正苦于以下问题:Python Command类的具体用法?Python Command怎么用?Python Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_command_obj_defaults_set
def test_command_obj_defaults_set():
set_sysargv(test_command_7)
c = Command()
c.set_defaults({'test': 'arg'})
returned_string = c.obj_string()
returned_string_list = returned_string.split("\n")
assert returned_string_list[2] == """obj.defaults = {'test': 'arg'}"""
示例2: test_command_optdefaults_define_multi_by_set_defaults_method
def test_command_optdefaults_define_multi_by_set_defaults_method():
set_sysargv(test_command_1)
c = Command()
c.set_defaults({'test': 'value', 'another': 'more'})
assert len(c.defaults) == 2
assert c.defaults['test'] == 'value'
assert c.defaults['another'] == 'more'
示例3: test_command_optdefaults_define_multi_by_index
def test_command_optdefaults_define_multi_by_index():
set_sysargv(test_command_1)
c = Command()
c.defaults['test'] = 'value'
c.defaults['another'] = 'more'
assert len(c.defaults) == 2
assert c.defaults['test'] == 'value'
assert c.defaults['another'] == 'more'
示例4: test_command_obj_string
def test_command_obj_string():
set_sysargv(test_command_1)
c = Command()
returned_string = c.obj_string()
returned_string_list = returned_string.split("\n")
assert returned_string_list[0] == "obj.argc = 9"
assert returned_string_list[1] == """obj.arguments = ['subcmd', '-s', '--long', '-n', 'shortdef', '--name', 'longdef', '--nameeq=longdefeq', 'lastpos']"""
assert returned_string_list[2] == """obj.defaults = {}"""
assert returned_string_list[5] == """obj.mdefs = {}"""
assert returned_string_list[6] == """obj.mops = {}"""
assert returned_string_list[7] == """obj.arg0 = 'subcmd'"""
assert returned_string_list[8] == """obj.arg1 = '-s'"""
assert returned_string_list[9] == """obj.arg2 = '--long'"""
assert returned_string_list[10] == """obj.arg3 = '-n'"""
assert returned_string_list[11] == """obj.arg4 = 'shortdef'"""
assert returned_string_list[12] == """obj.arglp = 'lastpos'"""
assert returned_string_list[13] == """obj.subcmd = 'subcmd'"""
assert returned_string_list[14] == """obj.subsubcmd = '-s'"""
示例5: test_command_dnval_nargs
def test_command_dnval_nargs():
set_sysargv(test_command_2)
c = Command()
assert c.does_not_validate_n_args(2) == False
assert c.does_not_validate_n_args(3) == True
set_sysargv(test_command_3)
c = Command()
assert c.does_not_validate_n_args(2) == False
assert c.does_not_validate_n_args(3) == True
set_sysargv(test_command_empty_1)
c = Command()
assert c.does_not_validate_n_args(0) == False
assert c.does_not_validate_n_args(1) == True
示例6: test_command_valid_nargs
def test_command_valid_nargs():
set_sysargv(test_command_2)
c = Command()
assert c.validates_includes_n_args(2) == True
assert c.validates_includes_n_args(3) == False
set_sysargv(test_command_3)
c = Command()
assert c.validates_includes_n_args(2) == True
assert c.validates_includes_n_args(3) == False
set_sysargv(test_command_empty_1)
c = Command()
assert c.validates_includes_n_args(0) == True
assert c.validates_includes_n_args(1) == False
示例7: test_command_optdefaults_contains_default_when_absent
def test_command_optdefaults_contains_default_when_absent():
set_sysargv(test_command_1)
c = Command()
c.set_defaults({'test': 'value'})
assert c.contains_defaults('bogus') == False
示例8: test_command_optdefaults_contains_default_multi_tests_absent_difforder
def test_command_optdefaults_contains_default_multi_tests_absent_difforder():
set_sysargv(test_command_1)
c = Command()
c.set_defaults({'test': 'value', 'another': 'more'})
assert c.contains_defaults('bogus', 'test') == False
示例9: test_command_contains_switches_alt_long
def test_command_contains_switches_alt_long():
set_sysargv(test_command_8)
c = Command()
assert c.contains_switches("name") == True
示例10: test_command_optdefaults_define_by_set_defaults_method
def test_command_optdefaults_define_by_set_defaults_method():
set_sysargv(test_command_1)
c = Command()
c.set_defaults({'test': 'value'})
assert len(c.defaults) == 1
assert c.defaults['test'] == 'value'
示例11: test_command_optdefaults_define_nonstring_by_index
def test_command_optdefaults_define_nonstring_by_index():
set_sysargv(test_command_1)
c = Command()
c.defaults['test'] = 1
assert c.defaults['test'] == 1
示例12: test_command_optdefaults_define_by_index
def test_command_optdefaults_define_by_index():
set_sysargv(test_command_1)
c = Command()
c.defaults['test'] = 'value'
assert len(c.defaults) == 1
assert c.defaults['test'] == 'value'
示例13: test_command_optdefaults_get_default_when_not_string
def test_command_optdefaults_get_default_when_not_string():
set_sysargv(test_command_1)
c = Command()
c.set_defaults({'test': 1})
assert c.get_default('test') == 1
示例14: set_sysargv
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from commandlines import Command
import sys
import shlex
test_command_1 = "spam eggs --toast -b --drink=milk filepath"
test_command_13 = "executable -o path1 -o path2 -t --flag"
test_command_18 = "executable -o path1 -o path2 --file tests/path1 --file tests/path2"
test_command_19 = "executable -mops -t --test=bogus --test=another --help me"
def set_sysargv(argstring):
sys.argv = shlex.split(argstring)
set_sysargv(test_command_13)
c = Command()
print(c.obj_string())
示例15: test_command_contains_mops_multiple
def test_command_contains_mops_multiple():
set_sysargv(test_command_9)
c = Command()
assert c.contains_mops("m", "p", "s") == True