예제 #1
0
 def test_add_argparse(self):
     parser = argparse.ArgumentParser()
     parser.add_argument("--foo")
     args = parser.parse_args(["--foo", "bar"])
     config = Config()
     config.add_from_args(args)
     self.assertEqual("bar", config["foo"])
예제 #2
0
def get_config():
    global parser, args, config
    parser = argparse.ArgumentParser(description='Pre receive hook for git repositories.')
    parser.add_argument('--dry-run', action='store_true', default=False, help='only log problems')
    parser.add_argument('--logfile', default=os.path.join(tempfile.gettempdir(), 'zooker.log'),
                        help='full path of the logfile')
    parser.add_argument('-c', '--config', help='path to config file')
    parser.add_argument('-v', '--verbose', action='count', help='verbose logging (-vv to be more verbose)', default=0)
    parser.add_argument('base', help='base commit hash')
    parser.add_argument('commit', help='new commit hash')
    parser.add_argument('ref', help='commit ref')
    args = parser.parse_args()
    level = [logging.ERROR, logging.INFO, logging.DEBUG]
    if args.logfile == '-':
        logging.basicConfig(format=LOG_CONSOLE_FORMAT, level=level[args.verbose])
    else:
        logging.basicConfig(filename=args.logfile, level=level[args.verbose])
    config = Config(checkers={'WhiteSpaceChecker': '', 'CodeValidatorChecker': ''}).add_from_default_locations()
    config.add_from_args(args)
    if args.config:
        config.add_from_json(args.config)
    return config
예제 #3
0
 def test_create(self):
     config = Config.from_dict({'checkers': { 'WhiteSpaceChecker': '' }})
     checkers = create_checkers(config)
예제 #4
0
 def test_default(self):
     config = Config.from_dict({"foo": "bar"})
     self.assertEqual("bar", config["foo"])
예제 #5
0
 def test_from_file(self):
     path = os.path.dirname(os.path.abspath(__file__))
     config = Config.from_json(os.path.join(path, "someconfig.json"))
     self.assertEqual("bar", config["foo"])
예제 #6
0
 def test_default_chaining(self):
     config = Config.from_dict({"foo": "bar"}).add_from_dict({"baz": "quux"})
     self.assertEqual("quux", config["baz"])
예제 #7
0
 def test_attribute_with_dash(self):
     config = Config.from_dict({"foo-bar": "quux"})
     self.assertEqual("quux", config.foo_bar)
예제 #8
0
 def test_attribute_access(self):
     config = Config.from_dict({"foo": "bar"})
     self.assertEqual("bar", config.foo)