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)
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)
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))
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())
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)
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)
def test_unsatisfable_dependency_1(self): startup = Startup() @startup def foo(x: ['x'], y: 'y'): pass self.assertRaises(StartupError, startup.call, y=1)
def test_annotate_twice(self): startup = Startup() def func(): pass self.assertEqual(func, startup(func)) self.assertRaises(StartupError, startup, func)
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'])
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)
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)
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 text_to_columns(self): ''' When the file is first produced all contents are in column A, separated by semicolons.This method opens up the- new .iff and delimits the text into columns. This method directly takes over keyboard using pyautogui package. ''' sleep(5) Startup.excel() #opens excel sleep(3) hotkey('ctrl','o') #'Open' file dialogue sleep(1) press('right') for _ in range(3): press('down') sleep(.25) press('esc') for _ in range(5): press('down') sleep(1) press('enter') sleep(1) typewrite('H:\Amex.iif') #types file name press('enter') sleep(1) press('d') #selects 'Delimited' option sleep(.5) press('n') #selects 'Next' option sleep(.5) press('m') #selects 'Semicolon' option sleep(.5) press('f') #selects 'Finish' option sleep(.5) hotkey('ctrl','s') #Saves file sleep(.5) press('y') #selects 'Yes' option hotkey('alt','f') #selects 'Office Button' in Excel press('x') #exits Excel press('n') #selects 'No' option sleep(1)
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)
class Button: 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 prep_msg(self, msg): """Prepare the message.""" self.msg_image = self.font.render(msg, True, self.text_color, self.black) self.msg_image_rect = self.msg_image.get_rect() self.msg_image_rect.center = self.rect.center def draw_button(self): """Draw the play button on the screen.""" # Black screen self.screen.fill(self.black) # self.screen.fill(self.button_color, self.rect) self.screen.blit(self.msg_image, self.msg_image_rect) self.startup.draw_images()
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)
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)
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.')
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
def __init__(self): self.conn_pool = Startup.get_connection_pool() self.server = None
# First call to startup. # Create MapRedis, MapMySql, MapMongo and MapCassandra objects # Create test payloads # Pass objects created above with payloads created above to MapActions and hopefully shit works # If it works and data is CRUDed as expected, then HURRAH!! else back to the drawing board. from startup import Startup from datasources import MapRedis, MapMySql, MapCassandra, MapMongo, MapActions # First call to startup. pool = Startup.get_connection_pool() # Create MapRedis, MapMySql, MapMongo and MapCassandra objects # mr = MapRedis.MapRedis(pool).server # ms = MapMySql.MapMySql(pool).server #mc = MapCassandra.MapCassandra(pool).server mm = MapMongo.MapMongo(pool).server # Create test payloads # prc = {'key': 'testkey', 'value': 'test value'} # prr = {'command': 'get', 'key': 'testkey'} # pru = {} # prd = {'command': 'del', 'key': 'testkey'} # psc = {'query': 'insert into test values(45, \'test text 3\');'} # psr = {'query': 'select * from test where test = 45;'} # psu = {'query': 'update test set value = \'new test text\' where test = 45;'} # psd = {'query': 'delete from test where test = 45;'} # pcc = { # 'query': 'insert into test(test, value) values(4, \'test text\');'} # pcr = {'query': 'select * from test;'} # pcu = {'query': 'update test set value = \'new test text\' where test = 4;'} # pcd = {'query': 'delete from test where test = 4;'}
# # # # # # # # # # # # 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()
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)
class Game: """Runs the game""" 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) def __str__(self): return 'Game(Pacman Portal), maze=' + str(self.maze) + ')' def play(self): # Starts the game eloop = EventLoop(self.screen, self.settings, self.play_button, self.score_button, self.maze, self.stats, self.sb, self.pacman, self.pac, self.ghosts, self.points, self.pills, self.fruits, self.portal, finished=False) # loops while not finished while not eloop.finished: # Check events eloop.check_events() if self.stats.game_active: # spawns fruits at random times if self.delay == self.timer: self.maze.create_fruit(self.stats.fruit_count) if self.stats.fruit_count >= 3: self.stats.fruit_count = 0 else: self.stats.fruit_count += 1 self.delay = 0 self.timer = random.randint(3000, 5001) else: self.delay += 1 # deletes fruit after a period of time if self.count == self.timer2: self.fruits.empty() self.count = 0 else: self.count += 1 # updates sprites self.pac.update() self.ghosts.update() self.portal.update() # Checks for collision eloop.check_collisions() self.update_screen() def update_screen(self): """Updates what is on the screen""" self.screen.fill(self.settings.bg_color) # displays statrup screen if not self.stats.game_active and not self.stats.score_screen_active: self.play_button.draw_button() self.score_button.draw_button() # displays score screen if score button is pressed if not self.stats.game_active and self.stats.score_screen_active: self.sb.draw_score_screen() self.back_button.draw_back() # Main game starts if active if self.stats.game_active: self.maze.blitme() self.pac.draw(self.screen) self.points.draw(self.screen) self.pills.draw(self.screen) self.fruits.draw(self.screen) self.ghosts.draw(self.screen) if not self.settings.play_once: self.settings.ghost.play(-1) self.settings.play_once = True self.sb.show_score() pygame.display.flip()
from flask import Flask from startup import Startup app = Flask(__name__) x = Startup(app)
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
#!/usr/bin/python import code from server import Server from client import Client from startup import Startup # Set up the classes for the server client and introduction server = Server() client = Client() startup = Startup(client, server) def initialise(event, type): """Initialise the start of chat after the startup is complete Keyword arguments: event -- the name of the event type -- the type of chat instance started """ if type == 'sender': input() def input(): """Prepends "Say:" to the next line""" message = raw_input('Say: ') say(message) def say(message): """Convenience method for calling client.send()
from keras import backend as K from pymongo import MongoClient from django.shortcuts import render from django.conf import settings from django.core.files.storage import FileSystemStorage from django.http import HttpResponse from django.http import HttpResponseBadRequest from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt abspath = '/opt/faiss/webapp/media/' #loading index and DCNN here Startup.loadIndex() Startup.loadVgg19() Startup.connMongo() print "Get debugColl collection.." db = Startup.client.faissdb debugColl = db.test def clearKeras(): print '...Clearing Keras session' K.clear_session() print 'Done.' def quitHandler(): print '...Saving index' faiss.write_index(Startup.index, abspath + 'faiss.index')
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()