Ejemplo n.º 1
0
    def test_set_variable(self):
        def func1(_: '#x') -> '#y':
            return 2

        def func2(_: '#x') -> '#z':
            return 3

        startup = Startup()
        startup.set('#x', 1)
        self.assertDictEqual({'#x': 1}, startup.call())

        # Call Startup.set() before registering functions.
        startup = Startup()
        startup.set('#x', 1)
        startup.set('#z', 0)
        startup(func1)
        startup(func2)
        self.assertDictEqual({'#x': 1, '#y': 2, '#z': 3}, startup.call())

        # Call Startup.set() after registering functions.
        startup = Startup()
        startup(func1)
        startup(func2)
        startup.set('#x', 1)
        startup.set('#z', 0)
        self.assertDictEqual({'#x': 1, '#y': 2, '#z': 3}, startup.call())

        # Overwrite Startup.set().
        startup = Startup()
        startup.set('x', 1)
        self.assertDictEqual({'x': 2}, startup.call(x=2))

        with self.assertRaises(StartupError):
            startup.set('v', 1)
Ejemplo n.º 2
0
    def test_annotate_all_nonoptional_parameters(self):
        startup = Startup()

        def func1(x):
            pass

        def func2(x, y=1):
            pass

        def func3(x, y=1, z=2):
            pass

        def func4(*, a):
            pass

        def func5(*, a, b=1):
            pass

        def func6(*, a, b=1, c=2):
            pass

        self.assertRaises(StartupError, startup, func1)
        self.assertRaises(StartupError, startup, func2)
        self.assertRaises(StartupError, startup, func3)
        self.assertRaises(StartupError, startup, func4)
        self.assertRaises(StartupError, startup, func5)
        self.assertRaises(StartupError, startup, func6)
Ejemplo n.º 3
0
    def test_wrong_annotations(self):
        startup = Startup()

        def func1(_: ('x', )):
            pass

        def func2(_: ['x', 'y']):
            pass

        def func3(_: 1):
            pass

        def func4() -> 1:
            pass

        def func5() -> []:
            pass

        def func6() -> (1, '2'):
            pass

        self.assertRaises(StartupError, startup, func1)
        self.assertRaises(StartupError, startup, func2)
        self.assertRaises(StartupError, startup, func3)
        self.assertRaises(StartupError, startup, func4)
        self.assertRaises(StartupError, startup, func5)
        self.assertRaises(StartupError, startup, func6)
Ejemplo n.º 4
0
    def test_multiple_return_1(self):
        startup = Startup()
        data = []

        @startup
        def func() -> ('x', 'y', 'z'):
            return 'x-str', 'y-str', 'z-str'

        @startup
        def func_z(z: 'z'):
            self.assertEqual('z-str', z)
            data.append('z')

        @startup
        def func_x(x: 'x'):
            self.assertEqual('x-str', x)
            data.append('x')

        @startup
        def func_y(y: 'y'):
            self.assertEqual('y-str', y)
            data.append('y')

        self.assertEqual({
            'x': 'x-str',
            'y': 'y-str',
            'z': 'z-str'
        }, startup.call())
        self.assertEqual(['x', 'y', 'z'], data)
Ejemplo n.º 5
0
    def test_join(self):
        startup = Startup()
        data = []

        @startup
        def func2() -> 'x':
            data.append(2)
            return 2

        @startup
        def func1() -> 'x':
            data.append(1)
            return 1

        @startup
        def func3() -> 'x':
            data.append(3)
            return 3

        @startup
        def func_join_1(x: ['x']):
            self.assertEqual([1, 2, 3], x)
            data.append('join')

        self.assertEqual({'x': 3}, startup.call())
        self.assertEqual([1, 2, 3, 'join'], data)
Ejemplo n.º 6
0
    def test_class_and_method(self):
        startup = Startup()

        @startup.with_annotations({'return': 'foo'})
        class Foo:
            def __init__(self):
                pass

        @startup.with_annotations({'return': 'bar'})
        class Bar:
            @classmethod
            def c(cls):
                return 'c'

            def m(self):
                return 'm'

        self.assertListEqual(['self'], inspect.getfullargspec(Foo).args)
        self.assertListEqual([], inspect.getfullargspec(Bar).args)

        self.assertListEqual(['cls'], inspect.getfullargspec(Bar.c).args)
        self.assertTrue(inspect.ismethod(Bar.c))

        self.assertListEqual(['self'], inspect.getfullargspec(Bar().m).args)
        self.assertTrue(inspect.ismethod(Bar().m))

        startup.add_func(Bar.c, {'return': 'c'})
        startup.add_func(Bar().m, {'return': 'm'})

        variables = startup.call()
        self.assertTrue(isinstance(variables['foo'], Foo))
        self.assertTrue(isinstance(variables['bar'], Bar))
        self.assertEqual('c', variables['c'])
        self.assertTrue('m', variables['m'])
Ejemplo n.º 7
0
    def test_unsatisfable_dependency_1(self):
        startup = Startup()

        @startup
        def foo(x: ['x'], y: 'y'):
            pass

        self.assertRaises(StartupError, startup.call, y=1)
Ejemplo n.º 8
0
    def test_annotate_twice(self):
        startup = Startup()

        def func():
            pass

        self.assertEqual(func, startup(func))
        self.assertRaises(StartupError, startup, func)
Ejemplo n.º 9
0
    def test_with_annotations(self):
        startup = Startup()

        @startup.with_annotations({'a': 'a', 'b': 'b', 'return': 'c'})
        def func(a, b):
            return (a, b)

        self.assertDictEqual({
            'a': 1,
            'b': 2,
            'c': (1, 2)
        }, startup.call(a=1, b=2))
Ejemplo n.º 10
0
    def test_multiple_return_2(self):
        startup = Startup()

        @startup
        def func_repeat() -> ('x', 'x', 'x'):
            return 1, 3, 2

        @startup
        def func_collect(xs: ['x']) -> 'xs':
            return xs

        self.assertEqual({'xs': [1, 3, 2], 'x': 2}, startup.call())
Ejemplo n.º 11
0
    def start_application(self):
        try:
            # Get an instance of startup, inject the configuration.
            startup = Startup(self.configuration)

            # Initialize needed services.
            startup.build_service_collection()

            # Start the Bot.
            startup.initialize_zombie()

        except ValueError as err:
            log.error(err)
        except Exception:
            log.exception('Something bad happened.')
Ejemplo n.º 12
0
    def test_unsatisfable_dependency_2(self):
        startup = Startup()

        @startup
        def func1(_: 'x') -> 'y':
            pass

        @startup
        def func2(_: 'y') -> 'z':
            pass

        @startup
        def func3(_: 'y') -> 'x':
            pass

        self.assertRaises(StartupError, startup.call)
Ejemplo n.º 13
0
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((680, 740))
        pygame.display.set_caption("Pacman Portal")

        self.maze = Maze(self.screen,
                         mazefile='maze.txt',
                         brickfile='square',
                         portalfile='close_portal',
                         shieldfile='shield',
                         powerfile='powerpil',
                         pointsfile='points',
                         foodfile='cherry')
        self.menu = Startup(self.screen, 'title.png', 'playbutton.png')
        self.pacman = Pacman(self.screen)
        self.ghosts = Ghosts(self.screen)

        self.eloop = EventLoop(finished=False)
Ejemplo n.º 14
0
    def test_lexicographical_order(self):
        startup = Startup()
        data = []

        @startup
        def func2():
            data.append(2)

        @startup
        def func1():
            data.append(1)

        @startup
        def func3():
            data.append(3)

        self.assertEqual({}, startup.call())
        self.assertEqual([1, 2, 3], data)
        # You cannot call run() again, by the way.
        self.assertRaises(StartupError, startup.call)
Ejemplo n.º 15
0
    def test_sequential_order(self):
        startup = Startup()
        data = []

        @startup
        def func3(x: 'x') -> 'y':
            data.append(x)
            return x - 1

        @startup
        def func2(y: 'y') -> 'z':
            data.append(y)
            return y - 1

        @startup
        def func1(z: 'z'):
            data.append(z)

        self.assertEqual({'x': 3, 'y': 2, 'z': 1}, startup.call(x=3))
        self.assertEqual([3, 2, 1], data)
Ejemplo n.º 16
0
    def __init__(self, ai_settings, screen, msg):
        """Create the play button."""
        self.startup = Startup(screen)
        self.ai_settings = ai_settings
        self.screen = screen
        self.screen_rect = screen.get_rect()

        # Set the dimensions and properties of the button
        self.width, self.height = 200, 50
        self.button_color = (0, 255, 0)
        self.text_color = (255, 255, 255)
        self.black = (0, 0, 0)
        self.font = pygame.font.SysFont(None, 48)

        # Build the button's rect object and center it
        self.rect = pygame.Rect(0, 0, self.width, self.height)
        self.rect.center = self.screen_rect.center

        # The button message needs to be prepped only once
        self.msg_image, self.msg_image_rect = None, None
        self.prep_msg(msg)
def initialize_startup_matrix(increment, number_of_startups):
  print("Initializing the startup matrix...")
  # Check that an integer mutliple of the increment equals 1.0 


  # Create the startup matrix as a list of list of lists. 
  data = []
  for quality in np.arange(0.0, 1.0+increment, increment):
    row = []
    for control_preference in np.arange(0.0, 1.0+increment, increment):
      cell = []
      for k in range(number_of_startups):
        cell.append(Startup(control_preference, quality))
      row.append(cell)
    data.append(row)

  print("Simulating startups...")
  # Simulate the startups in the list
  [[[simulate(s) for s in column] for column in row] for row in data]
  print("Startups simulated!")

  return data
Ejemplo n.º 18
0
    def __init__(self):
        pygame.init()
        # declares all and sets classes, data, groups
        self.pac = Group()
        self.points = Group()
        self.pills = Group()
        self.fruits = Group()
        self.ghosts = Group()
        self.delay = 0
        self.count = 0
        self.timer = random.randint(3000, 5001)
        self.timer2 = 4500

        self.settings = Settings()
        self.stats = GameStats(self.settings)
        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Pacman Portal")

        self.point = Point(self.screen, self.settings)
        self.maze = Maze(self.screen,
                         self.settings,
                         self.pac,
                         self.points,
                         self.pills,
                         self.fruits,
                         mazefile='images/maze.txt',
                         brickfile='square')
        self.portal = Portal(self.screen, self.settings)
        self.pacman = Pacman(self.screen, self.settings, self.maze,
                             self.portal, self.stats)

        self.sb = Scoreboard(self.settings, self.screen, self.stats, self.maze,
                             self.portal)
        self.play_button = Startup(self.screen, self.settings, 'Play')
        self.score_button = HighScores(self.screen, "High Scores",
                                       self.settings)
        self.back_button = HighScores(self.screen, "Back (B)", self.settings)
Ejemplo n.º 19
0
from flask import Flask
from startup import Startup

app = Flask(__name__)
x = Startup(app)
Ejemplo n.º 20
0
from flask import Flask
from datetime import datetime
import re
from startup import Startup

app = Flask(__name__)
x = Startup()


@app.route('/valor')
def hello_world():
    return 'Hola, World!'


@app.route("/hello/<name>")
def hello_there(name):
    now = datetime.now()
    formatted_now = now.strftime("%A, %d %B, %Y at %X")

    # Filter the name argument to letters only using regular expressions. URL arguments
    # can contain arbitrary text, so we restrict to safe characters only.
    match_object = re.match("[a-zA-Z]+", name)

    if match_object:
        clean_name = match_object.group(0)
    else:
        clean_name = "Friend"

    content = "Hello there, " + clean_name + "! It's " + formatted_now
    return content
Ejemplo n.º 21
0
from overlay_north import server
from startup import Startup
import sys

if __name__ == '__main__':
    startup = Startup()
    if not startup.start():
        print("\r\nUnable to finish startup. Exiting...")
        exit()

    server.app.run(host='0.0.0.0', port='8081', debug=True)


--> To get to the final output, I need to have a dataframe with

"""
increment = 0.2
startup_matrix = initialize_startup_matrix(increment, 20)

analysis = simulation_analysis(startup_matrix)

plot_analysis(increment, analysis)





wat()


test = Startup(0.8,0.6)
simulate(test)  
test.plot()

# wat()





Ejemplo n.º 23
0
#
# # # # # # # # # # #
from tornado.ioloop import IOLoop

from startup import build_host, Startup, IStartup

try:
    from galaxy import injection
except ImportError:

    def injection(stp: IStartup) -> IStartup:
        return stp


if __name__ == "__main__":
    """

    基础使用::

        1. 通常情况下没有特殊需求你可以在mvc下新建自己的控制器-视图-模型等
        2. madtornado4将各种服务作为程序依赖注入到控制器当中,并自动管理生命周期-即自动销毁
        3. 注册service需要在galaxy下的__init__.py中调用stp的方法,支持单例和会话两种注册方式
        4. 获取服务通过Controller的self.obtain()方法,无需担心滥用该方法返回的实例会根据注册生命周期来创建
        5. self.obtain()方法获取的实例还会被挂载到self下面,也可以通过 ``self.服务名`` 来获取实例
        6. madtornado为使用者提供galaxy包空间,可以放置自行编写的内容,不建议放置到其它位置

    """
    print("[madtornado]-Web server is running...")
    build_host(injection(Startup())).start()
    IOLoop.instance().start()