示例#1
0
  def test_set_values(self):
    pars = Params()
    pars.int('count').set(1)
    pars.float('price').set(9.99)

    subpars = Params()
    subpars.bool('flag').set(True)
    pars.group('subgroup', subpars)
    
    set_values(pars, {'count': 5, 'price': 0.5, 'subgroup': {'flag': False}})
    self.assertEqual(pars.get('count').val(), 5)
    self.assertEqual(pars.get('price').val(), 0.5)
    self.assertEqual(pars.get('subgroup').get('flag').val(), False)
示例#2
0
  def test_schema_list_with_values(self):
    pars = Params()
    pars.string('name').set('Moby Dick')
    pars.int('count').set(100)
    pars.float('price').set(9.99)
    pars.bool('soldout').set(False)

    details = Params()
    details.int('page_count').set(345)
    details.string('author').set('Herman Melville')
    pars.group('details', details)

    self.assertEqual(schema_list(pars), [
      {'path': '/name', 'type':'s', 'value':'Moby Dick'},
      {'path': '/count', 'type':'i', 'value':100},
      {'path': '/price', 'type':'f', 'value':9.99},
      {'path': '/soldout', 'type':'b', 'value':False},
      {'path': '/details/page_count', 'type':'i','value':345},
      {'path': '/details/author', 'type':'s','value':'Herman Melville'}
    ])
示例#3
0
  def test_schema_list(self):
    pars = Params()
    pars.string('name')
    pars.int('count')
    pars.float('price')
    pars.bool('soldout')

    details = Params()
    details.int('page_count')
    details.string('author')
    pars.group('details', details)

    self.assertEqual(schema_list(pars), [
      {'path': '/name', 'type':'s'},
      {'path': '/count', 'type':'i'},
      {'path': '/price', 'type':'f'},
      {'path': '/soldout', 'type':'b'},
      {'path': '/details/page_count', 'type':'i'},
      {'path': '/details/author', 'type':'s'}
    ])
示例#4
0
  def test_bool(self):
    params = Params()
    param = params.bool('checked')
    self.assertEqual(param.type, 'b')
    self.assertTrue(isinstance(param, Param))

    param.set('true')
    self.assertEqual(param.val(), True)
    self.assertEqual(param.changeEvent._fireCount, 1)

    param.set('xxx') # will not change the value
    self.assertEqual(param.val(), True)
    self.assertEqual(param.changeEvent._fireCount, 1)

    param.set('false')
    self.assertEqual(param.val(), False)
    self.assertEqual(param.changeEvent._fireCount, 2)

    param.set('yyy') # will not change the value
    self.assertEqual(param.val(), False)
    self.assertEqual(param.changeEvent._fireCount, 2)
示例#5
0
 def test_get(self):
   params = Params()
   param = params.bool('check')
   self.assertEqual(params.get('check'), param)
   self.assertIsNone(params.get('foo'))
示例#6
0
                          default='info')

        opts, args = parser.parse_args()
        lvl = {
            'debug': logging.DEBUG,
            'info': logging.INFO,
            'warning': logging.WARNING,
            'error': logging.ERROR,
            'critical': logging.CRITICAL
        }['debug' if opts.verbose else str(opts.verbosity).lower()]
        logging.basicConfig(level=lvl)

        return opts, args

    opts, args = parse_args()

    params = Params()
    params.string('name')
    params.float('score')
    params.int('level')
    params.bool('highest-score')

    http_server = HttpServer(Server(params))
    try:
        while True:
            time.sleep(0.5)
    except KeyboardInterrupt:
        print("Received Ctrl+C... initiating exit")

    http_server.stop()