コード例 #1
0
def testReadingEmptyConfigFile(filename):
    with open(filename, 'w'):
        pass

    config = readOpsirc(filename)

    assert {} == config
コード例 #2
0
def testIgnoringUnknownKeywords(filename):
    with open(filename, 'w') as f:
        f.write('hello = world\n')
        f.write('i coded = a bot\n')
        f.write('and I liked it\n')

    config = readOpsirc(filename)

    assert not config
コード例 #3
0
def testIgnoringEmptyValues(filename):
    with open(filename, 'w') as f:
        f.write('username=\n')
        f.write('username = foo\n')
        f.write('username =     \n')

    config = readOpsirc(filename)

    assert len(config) == 1
    assert config['username'] == 'foo'
コード例 #4
0
def testIgnoringComments(filename):
    with open(filename, 'w') as f:
        f.write(';address = https://bad.guy.dream:12345/c3\n')
        f.write('# address = https://blue.pill.dream:12345/c3\n')
        f.write('address = https://lullaby.machine.dream:12345/c3\n')
        f.write('  # address = https://last.one.neo:12345/c3\n')

    config = readOpsirc(filename)

    assert len(config) == 1
    assert config['address'] == 'https://lullaby.machine.dream:12345/c3'
コード例 #5
0
def testReadingConfigFileIgnoresLeadingAndTrailingSpacing(filename):
    with open(filename, 'w') as f:
        f.write('   address = https://lullaby.machine.dream:12345/c3\n')
        f.write('username=hanz   \n')
        f.write('        password   = gr3tel      \n')

    config = readOpsirc(filename)

    assert len(config) == 3
    assert config['address'] == 'https://lullaby.machine.dream:12345/c3'
    assert config['username'] == 'hanz'
    assert config['password'] == 'gr3tel'
コード例 #6
0
def testReadingPasswordFromCredentialsfile(filename):
    password = randomString(32)

    pwdfile = filename + '.secret'
    with codecs.open(pwdfile, 'w', 'utf-8') as f:
        f.write(password + '\n')

    with open(filename, 'w') as f:
        f.write('address = https://lullaby.machine.dream:12345/c3\n')
        f.write('username = hanz\n')
        f.write('password file = {}\n'.format(pwdfile))

    config = readOpsirc(filename)

    assert len(config) == 3
    assert config['address'] == 'https://lullaby.machine.dream:12345/c3'
    assert config['username'] == 'hanz'
    assert config['password'] == password
コード例 #7
0
def testReadingMissingFileReturnsNoConfig(tempDir):
    assert {} == readOpsirc('iamnothere')