Example #1
0
 def test_help_is_displayed(self):
     sys.stdout = StringIO()
     try:
         configglue(self.file, args=['', '--help'])
     except SystemExit:
         output = sys.stdout.getvalue()
         sys.stdout = sys.__stdout__
     self.assertTrue('yadda yadda yadda yadda' in output)
Example #2
0
 def test_help_is_displayed(self):
     sys.stdout = StringIO()
     try:
         configglue(self.file, args=['', '--help'])
     except SystemExit:
         output = sys.stdout.getvalue()
         sys.stdout = sys.__stdout__
     self.assertTrue('yadda yadda yadda yadda' in output)
Example #3
0
    def test_help_is_displayed(self):
        new_callable = StringIO
        if PY2:
            new_callable = BytesIO

        with patch('sys.stdout', new_callable=new_callable) as mock_stdout:
            try:
                configglue(self.file, args=['', '--help'])
            except SystemExit:
                output = mock_stdout.getvalue()
        self.assertTrue('yadda yadda yadda yadda' in output)
Example #4
0
 def test_parser_unicode(self):
     s = textwrap.dedent("""
         [__main__]
         bar = zátrapa
     """)
     _, cg, _ = configglue(StringIO(s))
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #5
0
 def test_parser_unicode(self):
     s = textwrap.dedent("""
         [__main__]
         bar = zátrapa
         bar.parser = unicode
         bar.parser.args = utf-8
     """)
     _, cg, _ = configglue(StringIO(s))
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #6
0
 def test_args_win(self):
     parser, options, args = configglue(self.file,
                                        args=['', self.arg + '=5'])
     self.assertEqual(vars(options),
                      {self.opt: '5'})
Example #7
0
 def test_store_false(self):
     parser, options, args = configglue(self.file, args=['', '--bar'])
     self.assertEqual(options.bar, False)
Example #8
0
 def test_no_append(self):
     parser, options, args = configglue(self.file)
     self.assertEqual(options.bar, ['a', 'b'])
Example #9
0
 def test_append(self):
     parser, options, args = configglue(self.file, args=['', '--bar=x'])
     self.assertEqual(options.bar, ['a', 'b', 'x'])
Example #10
0
 def test_main(self):
     parser, options, args = configglue(self.file)
     self.assertEqual(options.a, '1')
Example #11
0
 def test_no_append(self):
     parser, options, args = configglue(self.file)
     self.assertEqual(options.bar, ['a', 'b'])
Example #12
0
 def test_main(self):
     parser, options, args = configglue(self.file)
     self.assertEqual(options.a, '1')
Example #13
0
 def test_parser_none(self):
     s = "[__main__]\nbar = meeeeh\nbar.parser = none"
     _, cg, _ = configglue(StringIO(s), extra_parsers=[("none", str)])
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #14
0
 def test_args_win(self):
     parser, options, args = configglue(self.file,
                                        args=['', self.arg + '=5'])
     self.assertEqual(vars(options), {self.opt: '5'})
Example #15
0
 def test_accepts_args_and_filenames(self):
     parser, options, args = configglue(self.file,
                                        'dummy',
                                        args=['', '--x_a=1'])
     self.assertEqual(options.x_a, '1')
Example #16
0
 def test_ini_file_wins_when_no_args(self):
     parser, options, args = configglue(self.file, args=[])
     self.assertEqual(vars(options), {self.opt: self.val})
Example #17
0
 def test_append(self):
     parser, options, args = configglue(self.file, args=['', '--bar=x'])
     self.assertEqual(options.bar, ['a', 'b', 'x'])
Example #18
0
 def test_append_on_empty(self):
     parser, options, args = configglue(self.file, args=['', '--foo=x'])
     self.assertEqual(options.foo, ['x'])
Example #19
0
 def test_empty(self):
     s = ""
     _, cg, _ = configglue(StringIO(s))
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #20
0
log_file.help = The path to the log file.
log_level.default = INFO
log_level.help = The logging level (DEBUG, INFO, WARNING, ERROR)
log_format.default = %(asctime)s %(levelname)-8s %(name)s: %(message)s
log_format.help = The logging format
"""

# main entry point, parse args and start the service.
if __name__ == '__main__':
    from configglue.inischema.glue import configglue
    from StringIO import StringIO
    config_file = StringIO()
    config_file.write(default_config)
    config_file.seek(0)

    (parser, options,
     argv) = configglue(config_file,
                        args=sys.argv[1:],
                        usage="%prog [options]",
                        extra_parsers=[("comma_separated_list",
                                        comma_separated_list_parser)])

    if not options.groups or not options.interval or not options.timeout:
        parser.print_help()
        sys.exit(2)

    rpc = childutils.getRPCInterface(os.environ)
    hbl = HeartbeatListener(options.timeout, options.interval, options.groups,
                            options.processes, rpc)
    hbl.runforever()
Example #21
0
 def test_main(self):
     s = "[__main__]\nbar = 42\n"
     _, cg, _ = configglue(StringIO(s))
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #22
0
 def test_accepts_args_and_filenames(self):
     parser, options, args = configglue(self.file, 'dummy',
                                        args=['', '--x_a=1'])
     self.assertEqual(options.x_a, '1')
Example #23
0
 def test_parser_bool(self):
     s = "[__main__]\nbar = true\nbar.parser = bool \n"
     _, cg, _ = configglue(StringIO(s))
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #24
0
 def test_store_false(self):
     parser, options, args = configglue(self.file, args=['', '--bar'])
     self.assertEqual(options.bar, False)
Example #25
0
 def test_empty(self):
     parser, options, args = configglue(self.file)
     self.assertEqual(options.x_a, '')
Example #26
0
 def test_nothing(self):
     parser, options, args = configglue(self.file)
     self.assertEqual(options.foo, [])
Example #27
0
 def test_store_true(self):
     parser, options, args = configglue(self.file, args=['', '--foo'])
     self.assertEqual(options.foo, True)
Example #28
0
 def test_empty(self):
     s = ""
     _, cg, _ = configglue(StringIO(s))
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #29
0
 def test_nothing(self):
     parser, options, args = configglue(self.file)
     self.assertEqual(options.foo, [])
Example #30
0
 def test_main(self):
     s = "[__main__]\nbar = 42\n"
     _, cg, _ = configglue(StringIO(s))
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #31
0
 def test_append_on_empty(self):
     parser, options, args = configglue(self.file, args=['', '--foo=x'])
     self.assertEqual(options.foo, ['x'])
Example #32
0
 def test_parser_none(self):
     s = "[__main__]\nbar = meeeeh\nbar.parser = none"
     _, cg, _ = configglue(StringIO(s), extra_parsers=[('none', str)])
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #33
0
 def test_ini_file_wins_when_no_args(self):
     parser, options, args = configglue(self.file, args=[])
     self.assertEqual(vars(options),
                      {self.opt: self.val})
Example #34
0
 def test_empty(self):
     parser, options, args = configglue(self.file)
     self.assertEqual(options.x_a, '')
Example #35
0
 def test_parser_bool(self):
     s = "[__main__]\nbar = true\nbar.parser = bool \n"
     _, cg, _ = configglue(StringIO(s))
     _, sg, _ = schemaconfigglue(ini2schema(StringIO(s)))
     self.assertEqual(vars(cg), vars(sg))
Example #36
0
 def test_store_true(self):
     parser, options, args = configglue(self.file, args=['', '--foo'])
     self.assertEqual(options.foo, True)