Пример #1
0
 def proxy_function(*args, **kwargs):
     if Compatibility.PY2:
         bound_method = types.MethodType(unbound_method,
                                         Application.active(), Application)
     else:
         bound_method = types.MethodType(unbound_method,
                                         Application.active())
     return bound_method(*args, **kwargs)
Пример #2
0
 def proxy_function(*args, **kwargs):
   if Compatibility.PY2:
     bound_method = types.MethodType(unbound_method,
                                     Application.active(),
                                     Application)
   else:
     bound_method = types.MethodType(unbound_method,
                                     Application.active())
   return bound_method(*args, **kwargs)
Пример #3
0
 def test_app_registry_dependencies_of_list(self):
   self.factory.new_module('first')
   self.factory.new_module('second', dependencies='first')
   self.factory.new_module('third', dependencies=['first', 'second'])
   app = Application(force_args=[])
   app.init()
   assert self.factory.value('first') > 0, 'first callback should be called'
   assert self.factory.value('second') > 0, 'second callback should be called'
   assert self.factory.value('third') > 0, 'third callback should be called'
   assert self.factory.value('first') < self.factory.value('third'), (
       'third callback should be called after first')
   assert self.factory.value('second') < self.factory.value('third'), (
       'third callback should be called after first')
Пример #4
0
  def test_app_add_command_options(self):
    option_name = 'test_option_name'
    option = options.TwitterOption('--test', dest=option_name)

    app = Application()

    @app.command_option(option)
    def test_command():
      pass

    assert not hasattr(app.get_options(), option_name)
    app.add_command_options(test_command)
    assert hasattr(app.get_options(), option_name)
Пример #5
0
 def test_app_registry_dependencies_of_list(self):
   self.factory.new_module('first')
   self.factory.new_module('second', dependencies='first')
   self.factory.new_module('third', dependencies=['first', 'second'])
   app = Application(force_args=[])
   app.init()
   assert self.factory.value('first') > 0, 'first callback should be called'
   assert self.factory.value('second') > 0, 'second callback should be called'
   assert self.factory.value('third') > 0, 'third callback should be called'
   assert self.factory.value('first') < self.factory.value('third'), (
       'third callback should be called after first')
   assert self.factory.value('second') < self.factory.value('third'), (
       'third callback should be called after first')
Пример #6
0
 def test_app_add_options_with_raw(self):
   # raw option
   app = Application(force_args=['--option1', 'option1value', 'extraargs'])
   app.add_option('--option1', dest='option1')
   app.init()
   assert app.get_options().option1 == 'option1value'
   assert app.argv() == ['extraargs']
Пример #7
0
 def test_app_add_options_with_raw(self):
   # raw option
   app = Application(force_args=['--option1', 'option1value', 'extraargs'])
   app.add_option('--option1', dest='option1')
   app.init()
   assert app.get_options().option1 == 'option1value'
   assert app.argv() == ['extraargs']
Пример #8
0
 def test_app_registry_exit_functions(self):
   self.factory.new_module('first')
   self.factory.new_module('second', dependencies='first')
   self.factory.new_module('third', dependencies=['first', 'second'])
   app = Application(force_args=[])
   app.init()
   app._state = app.SHUTDOWN
   app._run_module_teardown()
   assert self.factory.value('third_exit') > 0 and (
     self.factory.value('second_exit') > 0 and self.factory.value('first_exit') > 0), (
     'all exit callbacks should have been called')
   assert self.factory.value('third_exit') < self.factory.value('second_exit')
   assert self.factory.value('third_exit') < self.factory.value('first_exit')
Пример #9
0
  def test_app_copy_command_options(self):
    option1 = options.TwitterOption('--test1')
    option2 = options.TwitterOption('--test2')

    app = Application()

    @app.command_option(option1)
    def test_command():
      pass

    @app.copy_command_options(test_command)
    @app.command_option(option2)
    def test_command_2():
      pass

    assert set([option1, option2]) == set(getattr(test_command_2, Application.OPTIONS_ATTR))
Пример #10
0
    def test_app_add_command_options(self):
        option_name = 'test_option_name'
        option = options.TwitterOption('--test', dest=option_name)

        app = Application()

        @app.command_option(option)
        def test_command():
            pass

        assert not hasattr(app.get_options(), option_name)
        app.add_command_options(test_command)
        assert hasattr(app.get_options(), option_name)
Пример #11
0
 def test_app_registry_exit_functions(self):
   self.factory.new_module('first')
   self.factory.new_module('second', dependencies='first')
   self.factory.new_module('third', dependencies=['first', 'second'])
   app = Application(force_args=[])
   app.init()
   app._state = app.SHUTDOWN
   app._run_module_teardown()
   assert self.factory.value('third_exit') > 0 and (
     self.factory.value('second_exit') > 0 and self.factory.value('first_exit') > 0), (
     'all exit callbacks should have been called')
   assert self.factory.value('third_exit') < self.factory.value('second_exit')
   assert self.factory.value('third_exit') < self.factory.value('first_exit')
Пример #12
0
 def test_app_registry_basic(self):
     self.factory.new_module('hello')
     app = Application(force_args=['--app_debug'])
     app.init()
     assert self.factory.value('hello') == 1, (
         'initialization functions should be invoked on app.init')
Пример #13
0
 def test_app_registry_basic(self):
   self.factory.new_module('hello')
   app = Application(force_args=['--app_debug'])
   app.init()
   assert self.factory.value('hello') == 1, (
       'initialization functions should be invoked on app.init')