Esempio n. 1
0
    def test_engine(self):
        engine = Engine('car_engine')
        self.assertEqual(engine.name, 'car_engine')

        engine.power = 1000
        self.assertEqual(engine.power, 1000)

        engine.engine_capacity = 5
        self.assertEqual(engine.engine_capacity, 5)

        engine.count_cylinders = 4
        self.assertEqual(engine.count_cylinders, 4)

        engine.material = 'steel'
        self.assertEqual(engine.material, 'steel')

        engine.fuel_consumption = 9
        self.assertEqual(engine.fuel_consumption, 9)

        engine.fuel_type = 'gasoline'
        self.assertEqual(engine.fuel_type, 'gasoline')

        engine.oil_consumption = 7
        self.assertEqual(engine.oil_consumption, 7)

        engine.oil_type = 'oil'
        self.assertEqual(engine.oil_type, 'oil')

        inf = EnginePrinter()
Esempio n. 2
0
class TestEngineCfg( unittest.TestCase ):
	def setUp( self ):
		self.engine = Engine()
		self.engine.loadCfg()
		self.assertEqual( self.engine.cfg, self.engine.DEFAULT_CFG )

	def test_write_cfg( self ):
		self.engine.writeCfg( 'TEST_DIR/test_cfg_2' )
		self.engine.loadCfg( 'TEST_DIR/test_cfg_2' )
		self.assertEqual( self.engine.cfg, self.engine.DEFAULT_CFG )
		os.unlink( 'TEST_DIR/test_cfg_2' )
Esempio n. 3
0
                        should be in the following format:
                        home_team home_score, away_team away_score
  --standings, -s       Shows the standings and exits. Can be combined with
                        the --import argument.

Author: Nick Eriksson <*****@*****.**>
"""


# Texts for display
INTRO_TEXT = ''
MENU_TEXT = 'Menu:\na) Add a Match\nc) Comprehensive Standings\nm) ' \
            'List Matches\ns) Standings\nq) Quit\n\nMake your choice: '

# Global variables
ENGINE = Engine()
DEFAULT_LEAGUE = 'Default League'

# Help texts
HELP_STANDINGS = 'Shows the standings and exits. Can be combined with the ' \
                 '--import argument.'
HELP_IMPORT = 'Import matches from a file. Each line in the file should ' \
              'contain the result of one match and should be in the ' \
              'following format: home_team home_score, away_team away_score'


def import_matches(path):
    """
    Imports matches from a given file path
    :param path:
    :return:
Esempio n. 4
0
from main import Engine

run = Engine()
run.run()
Esempio n. 5
0
	def setUp( self ):
		self.engine = Engine()
		self.engine.loadCfg()
		self.assertEqual( self.engine.cfg, self.engine.DEFAULT_CFG )
Esempio n. 6
0
    def run(self):
        while self.running:
            if not self.client.outLauncherQueue.empty():
                msg = self.client.outLauncherQueue.get()
                #self.transition(2) or self.name.setText(
                if type(msg) == sendRoom:
                    QApplication.postEvent(
                        self.parent,
                        _Event(lambda: self.parent.listPlayers.clear()))
                    QApplication.postEvent(
                        self.parent, _Event(lambda: self.parent.transition(2)))
                    st = [
                        p.get('username', 'unknown') + "         status: " +
                        ("ready" if p.get('ready', False) else "not ready") +
                        "           Wins: " + str(p.get('wins')) +
                        "           Games: " + str(p.get('games'))
                        for p in msg.playerlist
                    ]
                    QApplication.postEvent(
                        self.parent,
                        _Event(lambda: self.parent.listPlayers.addItems(st)))
                    QApplication.postEvent(
                        self.parent,
                        _Event(
                            lambda: self.parent.name.setText(str(msg.roomId))))
                    self.host = msg.host
                    if self.name == msg.host and self.parent.maps.count() == 0:
                        QApplication.postEvent(
                            self.parent,
                            _Event(lambda: self.parent.maps.clear()))
                        QApplication.postEvent(
                            self.parent,
                            _Event(lambda: self.parent.maps.addItem("Random")))
                        temp = [
                            filename for dirname, dirnames, filenames in
                            os.walk('./saves') for filename in filenames
                        ]
                        QApplication.postEvent(
                            self.parent,
                            _Event(lambda: self.parent.maps.addItems(temp)))
                        QApplication.postEvent(
                            self.parent,
                            _Event(
                                lambda: self.parent.maps.setCurrentIndex(0)))
                    elif self.name != msg.host:
                        QApplication.postEvent(
                            self.parent,
                            _Event(lambda: self.parent.maps.clear()))
                        QApplication.postEvent(
                            self.parent,
                            _Event(lambda: self.parent.maps.
                                   addItem("Random" if not msg.current_game
                                           else msg.current_game)))
                        QApplication.postEvent(
                            self.parent,
                            _Event(
                                lambda: self.parent.maps.setCurrentIndex(0)))
                elif type(msg) == startGame:
                    QApplication.postEvent(
                        self.parent,
                        _Event(lambda: Engine(
                            1, self.name, msg.player_turn, msg.seed, self.
                            client, len(msg.player_list), msg.saved_game)))

                elif type(msg) == LoginAck:
                    if msg.success:
                        QApplication.postEvent(
                            self.parent,
                            _Event(lambda: self.parent.transition(1)))
                    else:
                        print("Could not login")
                elif type(msg) == SendRoomList:
                    QApplication.postEvent(
                        self.parent,
                        _Event(lambda: self.parent.listLobby.clear()))
                    QApplication.postEvent(
                        self.parent,
                        _Event(lambda: self.parent.listLobby.addItems(
                            [str(id) for id in msg.room_list])))
                elif msg is None:
                    break
            #QApplication.postEvent(self.parent, _Event(lambda:self.parent.listLobby.addItem("hello")))
            time.sleep(.1)
Esempio n. 7
0
 def engine(self):
     self.engine = Engine()
Esempio n. 8
0
 def __init__(self, engine):
     self.engine = Engine()
     self.kill = False
Esempio n. 9
0
class Console:
    def __init__(self, engine):
        self.engine = Engine()
        self.kill = False
    
    def engine(self):
        self.engine = Engine()


    def shell(self, _ = None):
        print('Type help to view commands; e to exit')
        while True:
            x = input(colored('console> ', 'blue'))
            args = x.split(' ')
            if args[0] == 'add': #exampe: console> add AAPL OPT 2020-11-27
                try:
                    new_listener = Listener(args[1], args[2], args[3])
                    self.engine.add(new_listener)
                except e:
                    print('error', e)

            elif args[0] == 'stop':
                if len(args) > 1: #stop listnener by id 
                    for listener in self.engine.listeners:
                        if listener.id == int(args[1]):
                            self.engine.listeners.remove(listener)

                else:  # stop all listeners
                    confirm = input('Stop all listeners [y/n]: ').lower()
                    if confirm == 'y':
                        self.engine.listeners = []

            elif args[0] == 'start':
                self.threadx = Thread(target=self.engine.start, args=(self.kill,))
                self.threadx.daemon = True 
                self.threadx.start() 
                
            elif args[0] == 'exit' or args[0] == 'e':
                exit()

            elif args[0] == 'dump':
                df = pd.DataFrame(self.engine.data)
                df.to_csv('dump.csv')

            elif args[0] == 'load':
                
                if len(args) == 2:
                    filename = args[1]
                else: 
                    filename = input('Filename: ')

                with open(filename, 'r') as f: 
                    recorders = f.readlines()
                
                for recorder in recorders: 
                    recorder = recorder.replace('\n', '')
                    arguements = recorder.split(' ')
                    new_listener = Listener(arguements[0], arguements[1], arguements[2])
                    self.engine.add(new_listener)


            elif args[0] == 'list':
                if len(self.engine.listeners) == 0:
                    print("No listeners yet. Type 'add' to add one!")
                else: 
                    print("  ID | Description")
                    print("-----+-------------------------")
                    for listener in self.engine.listeners:
                        print(f"{listener.id} | ", end="")
                        if listener.equity_type == 'OPT':
                            print(f"Recording {listener.symbol} Options with {listener.expiration} expiration")

            elif args[0] == 'help':
                print("""
                Command     |   Description             |   Syntax 
                add         | Creates a new listener    | add TICKER TYPE EXPIRATION   ex. add MSFT OPT 2020-11-27
                start       | Start all listeners       | start
                stop        | Stop a listener           | stop LISTENER_ID  or stop (to stop all)
                load        | Load listeners from file  | load file.txt or load 
                list        | List active listeners     | list
                exit        | Exit CLI                  | exit
                """)

            elif args[0] == 'generate':
                lines = []
                tickers = input('Enter stock tickers seperated by comma: ').replace(' ', '').split(',')
                dates = input('Enter Expiration dates: ').replace(' ', '').split(',')
                for ticker in tickers: 
                    for date in dates:
                        lines.append(f"{ticker} OPT {date}")

                filename = input("Filepath to write load file: ")
                with open(f"./{filename}", 'w') as f:
                    f.write('\n'.join(lines))

                confirm = input(f"Do you want to load {filename}? [y/n]: ").lower()
                if confirm == 'y':
                    for recorder in lines: 
                        recorder = recorder.replace('\n', '')
                        arguements = recorder.split(' ')
                        new_listener = Listener(arguements[0], arguements[1], arguements[2])
                        self.engine.add(new_listener)
Esempio n. 10
0
                for ticker in tickers: 
                    for date in dates:
                        lines.append(f"{ticker} OPT {date}")

                filename = input("Filepath to write load file: ")
                with open(f"./{filename}", 'w') as f:
                    f.write('\n'.join(lines))

                confirm = input(f"Do you want to load {filename}? [y/n]: ").lower()
                if confirm == 'y':
                    for recorder in lines: 
                        recorder = recorder.replace('\n', '')
                        arguements = recorder.split(' ')
                        new_listener = Listener(arguements[0], arguements[1], arguements[2])
                        self.engine.add(new_listener)




if __name__ == "__main__":
    x = Engine(checkpoints_enabled=True, checkpoints_interval=3)

    c = Console(x)
    c.shell()


#c = Console(x)
#thread2 = Thread(target = c.shell, args=(11, ))
#thread2.daemon = True
#thread2.run()