def testNoCommand():
    '''
	Tests a case where the command does not exist.
	'''
    config = {
        'commandMapping': {
            'command1': 'method1',
            'command2': 'method2'
        },
        'appHeader': 'My useless program version 0.1',
        'usageString': "Don't use"
    }
    business = Business()
    cmdliner = Pycmdliner(config, business)

    cmdliner.process(['argfargf', 'argf'])
    assert (business.m1 == False)
    assert (business.m2 == False)
    assert (business.m3 == False)

    'try with a default method'
    del config['usageString']
    config['usageMethod'] = 'default'
    cmdliner = Pycmdliner(config, business)

    cmdliner.process(['argfargf', 'argf'])
    assert (business.m1 == False)
    assert (business.m2 == False)
    assert (business.m3 == False)

    'try with a defautl method that does not exist'
    del config['usageMethod']
    config['usageMethod'] = 'Strupniveralms'
    cmdliner = Pycmdliner(config, business)

    try:
        cmdliner.process(['argfargf', 'argf'])
        assert (False)
    except Exception:
        pass
    '''Try with a usage file'''
    del config['usageMethod']
    config['usageFile'] = './testUsage.txt'

    cmdliner = Pycmdliner(config, business)

    cmdliner.process(['argfargf', 'argf'])
    assert (business.m1 == False)
    assert (business.m2 == False)
    assert (business.m3 == False)
def testValidConfig():
    '''
	Tests some cases with valid input configuration
	'''
    config = {'commandMapping': {'command1': 'method1', 'command2': 'method2'}}
    business = Business()
    cmdliner = Pycmdliner(config, business)
    cmdliner.process(['command1'])
    assert (business.m1 == True)
    assert (business.m2 == False)
    assert (business.m3 == False)
def testSingleCommand():
    '''
	Tests the case where the configuration contains only a default command
	not to be provided in input. (commands like ls which take only parameters
		or options)
	'''
    config = {
        'defaultCommand': 'method4',
        'usageString': 'Use at your high risk',
        'appHeader': 'Myapp version 1234.12'
    }
    business = Business()
    cmdliner = Pycmdliner(config, business)

    cmdliner.process([1, 2])
    assert (business.m1 == False)
    assert (business.m2 == False)
    assert (business.m3 == False)
    assert (business.m4 == 3)
def testPassingParameters():
    '''
	Tests a case where the user provides parameters.
	'''
    config = {
        'commandMapping': {
            'command1': 'method1',
            'command4': 'method4'
        },
        'appHeader': 'My useless program version 0.1',
        'usageString': "Don't use"
    }
    business = Business()
    cmdliner = Pycmdliner(config, business)

    cmdliner.process(['command4', 1, 2])
    assert (business.m1 == False)
    assert (business.m2 == False)
    assert (business.m3 == False)
    assert (business.m4 == 3)