def __init__(self): super().__init__() # tables self.category = Table('GroupKala', _('Category')) self.category_map = Table('CategoryMap', _('CategoryMap')) # woocommerce api self.woocommerce = wc.get(wc_api.get(), 'products/categories')
def test_instanciation_with_bad_primary_key_config(self): fields = [Field('name', 'str')] # No primary key with self.assertRaises(Exception): table = Table('table_name', [Field('name', 'str')]) # Several primary keys with self.assertRaises(Exception): table = Table('table_name', [ Field('id_1', 'int', primary_key=True), Field('id_2', 'int', primary_key=True) ])
def test_check_insert(self): fields = [Field('id', 'int', primary_key=True), Field('name', 'str')] table = Table('users', fields) table.insert(id=1, name='Pierre') self.assertTrue(len(table.values) == 1)
def lab_1(): # the path of the atoms table file ATOMS_FILE_PATH = '../data/atoms.txt' # the path of the file to be analyzed and executed SOURCE_FILE_PATH = '../data/p1.txt' # separators file path SEPARATORS_FILE_PATH = '../data/separators.txt' # Reading the source file with open(SOURCE_FILE_PATH, 'r') as input_file: # content = the content of the source file which will be analyzed & executed content = input_file.read() # Reading the symbol table atoms_table = Table() with open(ATOMS_FILE_PATH) as atoms_file: for index, line in enumerate(atoms_file): atoms_table.put(line.strip(), index) # Reading the separators separators = [] with open(SEPARATORS_FILE_PATH, 'r') as input_file: for line in input_file: separators.append(line.strip()) internal_program_form, id_symbol_table, const_symbol_table = lexical_analyze( content, atoms_table, separators) print('Internal program form:\n' + str(internal_program_form)) print('Id table:\n' + str(id_symbol_table)) print('Const table:\n' + str(const_symbol_table))
class TestParseInput(): ''' This class will be used to test the ParseInput. ''' parse_input = ParseInput() table = Table() #used for thorough testing robot = ToyRobot(table) #used for thorough testing full way through def test_place_parse(self): ''' Testing the 'place' command. checking if it returns the expected ''' cmd = self.parse_input.parse("place 1,2,east") assert cmd.value == "place" assert cmd.args == ["1", "2", "east"] def test_case_insensitive_place(self): ''' Ensuring the place command is case insensitive ''' cmd = self.parse_input.parse("PLaCE 1,2,EaST") assert cmd.value == "place" assert cmd.args == ["1", "2", "east"] def test_move_parse(self): ''' Testing if the 'move' command is successfully parsed as expected ''' cmd = self.parse_input.parse("move") assert cmd.value == "move" def test_thorough_move_robot(self): ''' This test will be a thorough test, with a few different components to see if they all work well together ''' cmd = self.parse_input.parse("place 1,2,east") cmd.execute(self.robot) ## check the parse assert cmd.value == "place" assert cmd.args == ["1", "2", "east"] ## check the robot assert self.robot.coordinate == Coordinate(1,2) assert self.robot.direction == Direction("east") def test_cmd_not_found(self): ''' This function aims to test an invalid command ''' with pytest.raises(CommandNotFoundError): cmd = self.parse_input.parse("autocomplete_code")
def test_if_init_state_is_not_given_then_set_all_cell_to_alive(self): # given table = Table(3, 3) # then for row in table._cells: self.assertTrue(all(cell.state for cell in row))
def setUp(self): self.conn = connection.get(**s.get('test_db')) self.test_table = Table('Test') self.test_table.connection = self.conn # create test table sql = """ CREATE TABLE Test( c1 INT PRIMARY KEY, c2 VARCHAR(50) NOT NULL, c3 DATETIME NOT NULL, c4 BIT NOT NULL ) """ cursor = self.conn.cursor() cursor.execute(sql) # insert records into Test table sql = """ INSERT INTO Test(c1, c2, c3, c4) VALUES (?, ?, ?, ?) """ self.records = [ [i, 'test{}'.format(i), datetime.now(), True] for i in range(1, 11) ] cursor.executemany(sql, self.records) cursor.close() self.conn.commit()
def test_get_state_method_works_correct_in_all_cells_alive_condition(self): # given table = Table(3, 3) # then self.assertEqual( table.get_state(), [[True, True, True], [True, True, True], [True, True, True]])
def test_if_size_of_input_state_not_suit_size_of_table_then_raise_exception( self): # given table = Table(3, 3) state = [[True]] with self.assertRaises(ValueError): table.set_state(state)
def setUp(self): table = Table(200) self.player = MartingalePlayer(table) self.player.stake = 100 wheel = Wheel(NonRandom()) # bin_builder = BinBuilder() # bin_builder.build_bins(wheel) self.game = Game(wheel, table)
def test_check_no_exception_if_nullable_field_missing(self): fields = [ Field('id', 'int', primary_key=True), Field('name', 'str'), Field('age', 'int', nullable=True) ] table = Table('users', fields) table.insert(id=5, name='Pierre')
def lexical_analyze(text, atoms_table, separator_list): """ Lexically analyses the source code (text) @param text: string which represents the code to be analyzed @param atoms_table: instance of Table class which holds the codes for the atoms @param separator_list: list of separators @return: (internal form of the program, symbols table, const table) @throws: exception if any error is found inside the text """ atom_list = [] for index, line in enumerate(text.split(NEWLINE)): for token in [x for x in line.split(SPACE) if x != '']: line_atom_list = [ (index + 1, atom) for atom in get_atoms_recursive(token, index, separator_list) if atom != '' ] atom_list = [*atom_list, *line_atom_list] const_symbol_table = Table() id_symbol_table = Table() internal_program_form = [] for atom in atom_list: line_number = atom[0] atom_value = atom[1] if atoms_table.has(atom_value): internal_program_form.append((None, atoms_table.get(atom_value))) elif atom_is_const(atom_value): if not const_symbol_table.has(atom_value): const_symbol_table.append(atom_value) internal_program_form.append( (const_symbol_table.get(atom_value), 0)) elif atom_is_id(atom_value): if not id_symbol_table.has(atom_value): id_symbol_table.append(atom_value) internal_program_form.append((id_symbol_table.get(atom_value), 1)) else: raise SyntaxError('Invalid syntax at line ' + str(line_number) + '. Atom: ' + atom_value) return internal_program_form, id_symbol_table, const_symbol_table
def test_get_num_of_alive_neighbor_works_correct_if_location_is_not_on_the_border( self): # given table = Table(3, 3) state = [[True, False, True], [True, False, True], [True, False, True]] # when table.set_state(state) # then self.assertEqual(table.num_of_alive_neighbor(1, 1), 6)
def setUp(self): table = Table(100) rng = NonRandom() wheel = Wheel(rng) self.game = Game(wheel, table) self.player = MartingalePlayer(table) self.player.stake = 1000 self.player.rounds_to_go = 10 self.outcomes = [Outcome("Black", 1), Outcome("Red", 1)]
def init(self): self.table = Table(20) for i, time in zip(range(1, 21), self.time_data): self.table.table[i] = Customer(CustomerInfo(number=i, table=i, food=1), eating_time=0, total_time=time) self.table.table[i].eating = True return self.table
def test_set_state_method_works_correct_if_given_correct_state(self): # given table = Table(3, 3) state = [[True, False, True], [True, False, True], [True, False, True]] # when table.set_state(state) # then self.assertEqual(table.get_state(), state)
def __init__(self): self.__customer_number = 0 self.__table = Table(20) self.__cook = Cook() self.waiting = [] self.food_name = {1: "스테이크", 2: "스파게티", 3: "마카로니", 4: "그라탱"} self.cooking_time = {1: 30, 2: 20, 3: 10, 4: 15} self.eating_time = {1: 30, 2: 20, 3: 15, 4: 10} self.time = 0
def export_this_table(self, table_name: str, table_metadata: dict): """ Export the contents of a particular table to a csv text file. :param table_name: :param table_metadata: :return: """ self.env.msg.info(f"Exporting table '{table_name}' from group '{table_metadata['group']}'") table = Table(self.env, table_name, table_metadata) self.env.msg.debug(table.export_filepath) table.export()
def setUp(self): table = Table(100) rng = NonRandom() wheel = Wheel(rng) self.inital_player_stake = 1000 self.table = table self.game = Game(wheel, table) self.player = SevenRedsPlayer(table) self.player.stake = self.inital_player_stake self.player.rounds_to_go = 10 self.outcomes = Outcome("Black", 1)
def setUp(self): table = Table(100) rng_wheel = NonRandom() wheel = Wheel(rng_wheel) self.initial_player_stake = 1000 self.table = table self.game = Game(wheel, table) self.player = PlayerFibonacci(table) self.player.stake = self.initial_player_stake self.player.rounds_to_go = 1 self.outcomes = [Outcome("Black", 1), Outcome("Red", 1)]
def __init__(self): player1 = Player(0, 'Winston') player1.small_blind = True player2 = bot(1, 'Adolf') player2.big_blind = True player3 = bot(2, 'Franklin') player4 = bot(3, 'Joseph') player5 = bot(4, 'Benito') self.status = "dude" self.is_starting = True self.table = Table([player1, player2, player3, player4, player5]) self.is_dead = False
def build_this_table(self, table_name: str, table_metadata: dict): self.env.msg.info(f"Building table '{table_name}' from data in group '{table_metadata['group']}'") table = Table(self.env, table_name, table_metadata) self.env.msg.debug(table.ddl_filepath) self.env.msg.debug(table.data_filepath) if os.path.isfile(table.data_filepath): table.create_table() table.populate_table() else: self.env.msg.warning([ f"'{table_name}.csv' not found in '{table_metadata['group']}'", 'No changes have been made to the existing table structure or data.' ])
def __init__(self): super(Root, self).__init__() self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.my_table = Table() self.my_table.cols = 2 self.my_table.label_panel.labels[ 0].text = "Description" # heading text self.my_table.label_panel.labels[1].text = "Category" # heading text self.add_widget(self.my_table) self.load_table()
def test_get_with_non_matching_search(self): field = mock.Mock(spec=Field) field.primary_key = True table = Table('users', [field]) table.values = [{ 'id': 1, 'name': 'Pascal' }, { 'id': 2, 'name': 'Martine' }] self.assertEqual(table.get_with_values(name='José'), [])
def __init__(self): super().__init__() # tables self.invoice = Table('Factor1', _('Invoice')) self.invoice_map = Table('InvoiceMap', _('InvoiceMap')) self.customer = Table('AshkhasList', _('Customer')) self.customer_map = Table('CustomerMap', _('CustomerMap')) self.product = Table('KalaList', _('Product')) self.product_map = Table('ProductMap', _('ProductMap')) self.line_item = Table('Faktor2', _('LineItem')) # woocommerce self.woocommerce = wc.get(wc_api.get(), 'orders')
def test_table_next_state_correct_in_case_2(self): # given # X X X X X X X X # X O O X => X O O X # X O O X X O O X # X X X X X X X X table = Table(4, 4) state = [[False, False, False, False], [False, True, True, False], [False, True, True, False], [False, False, False, False]] table.set_state(state) # when table.next() # then self.assertEqual(table.get_state(), state)
def test_table_next_state_correct_in_case_1(self): # given # X O X X X X # X O X => O O O # X O X X X X table = Table(3, 3) state = [[False, True, False], [False, True, False], [False, True, False]] table.set_state(state) # when table.next() # then self.assertEqual( table.get_state(), [[False, False, False], [True, True, True], [False, False, False]])
def setUp(self): table = Table(100) rng_wheel = NonRandom() wheel = Wheel(rng_wheel) rng_player = NonRandom() self.initial_player_stake = 1000 self.table = table self.game = Game(wheel, table) self.player = RandomPlayer(table, rng_player) self.player.stake = self.initial_player_stake self.player.rounds_to_go = 10 possible_outcomes = [] for bin in wheel.bin_iterator(): for outcome in bin: possible_outcomes.append(outcome) self.player.set_possible_outcomes(possible_outcomes)
def __init__(self): super().__init__() # tables self.product = Table('KalaList', _('Product')) self.product_map = Table('ProductMap', _('ProductMap')) self.category_map = Table('CategoryMap', _('CategoryMap')) self.price_level = Table('PriceLevel', _('PriceLevel')) self.product_price = Table('KalaPrice', _('ProductPrice')) self.product_repository = Table('MojodiList', _('ProductRepository')) # woocommerce api self.woocommerce = wc.get(wc_api.get(), 'products')
def test_export(self): fields = [ Field('id', 'int', primary_key=True), Field('name', 'str'), Field('age', 'int', nullable=True) ] table = Table('users', fields) table.insert(id=5, name='Pierre') table.insert(id=6, name='Roger') self.assertEqual(table.export(), [{ 'id': 5, 'name': 'Pierre' }, { 'id': 6, 'name': 'Roger' }])