Пример #1
0
 def test_addKey(self):
     print "Testing addKey()...",
     print "good key...",
     good = keys.addKey(KEY)
     self.assert_(good, "FAILED (wrong return type on good key)")
     self.assert_(KEY in keys._KEYS, "FAILED (didnt add good key)")
     print "bad key ...",
     bad = keys.addKey("foo")
     self.assert_(not bad, "FAILED (wront return type on bad key)")
     self.assert_("foo" not in keys._KEYS, "FAILED (added bad key to _KEYS)")
     print "forced bad key...",
     bad = keys.addKey("foo", force_=True)
     self.assert_(bad, "FAILED (wrong return type on forced key)")
     self.assert_("foo" in keys._KEYS, "FAILED (didnt force bad to _KEYS)")
     self.assert_(keys._KEYS[keys._KEYS.index("foo")].active == False, "FAILED (didnt make bad key inactive)")
     print "OK"
Пример #2
0
def main():
    options, args = handleopts()

    if args: kfname = args[0]
    else: kfname = None
    keys.loadKeys(kfname)

    if options.add:
        if keys.addKey(options.add):
            print "Successfully added key: %s" % (options.add)
            keys.saveKeys()
            sys.exit(0)
        else:
            print "Invalid key: %s, exiting" % (options.add)
            sys.exit(1)

    elif options.remove:
        # Note on implementation this will call keys.remove(key) in a try
        # block like above
        print "Option currently disabled, key removal is not yet implemented"
        sys.exit(1)

    else:
        i = 0
        for k in keys._KEYS:
            i += 1
            print '%s. %s: %s' % (i,k.name, k)
        sys.exit(0)
Пример #3
0
 def test_addKey(self):
     print 'Testing addKey()...',
     print 'good key...',
     good=keys.addKey(KEY)
     self.assert_(good, 'FAILED (wrong return type on good key)')
     self.assert_(KEY in keys._KEYS, 'FAILED (didnt add good key)')
     print 'bad key ...',
     bad = keys.addKey('foo')
     self.assert_(not bad, "FAILED (wront return type on bad key)")
     self.assert_('foo' not in keys._KEYS, 'FAILED (added bad key to _KEYS)')
     print 'forced bad key...',
     bad = keys.addKey('foo',force_=True)
     self.assert_(bad, "FAILED (wrong return type on forced key)")
     self.assert_('foo' in keys._KEYS, 'FAILED (didnt force bad to _KEYS)')
     self.assert_(keys._KEYS[keys._KEYS.index('foo')].active == False,
                  "FAILED (didnt make bad key inactive)")
     print "OK"