def test_config_loading(test_configs): from empty import Empty import config app = Empty('myapp') Config = config.EmptyConfig(DEBUG=True) app.configure(Config) assert app.config['DEBUG'] is Config.DEBUG
def move(self): while True: print('Give a position of figure') sx,sy=Condition.s_choice(self.board) print(self.board[sx][sy].name) print('Now choose a destnation') dx,dy=Condition.d_choice(self.board) mark_same=Condition.same_team(sx,sy,dx,dy,self.board) mark_kill=Condition.kill(sx,sy,dx,dy,self.board) mark_Pawnkill=Condition.Pawnkill(sx,sy,dx,dy,self.board) mark_solid=Condition.solid(sx,sy,dx,dy,self.board) mark_move=self.board[sx][sy].req(sx,sy,dx,dy,self.board) if mark_solid==False: print('Figures are not ghosts') elif (mark_Pawnkill == True and abs(dx-sx) == abs(dy-sy) and mark_same == False): self.board[dx][dy] = self.board[sx][sy] self.board[dx][dy].x = dx self.board[dx][dy].y = dy self.board[sx][sy] = Empty(x='',y='',sl='.',team='') return self.board break elif (mark_move == True and mark_Pawnkill == False and (mark_kill == True or mark_same == False)): self.board[dx][dy] = self.board[sx][sy] self.board[dx][dy].x = dx self.board[dx][dy].y = dy self.board[sx][sy] = Empty(x='',y='',sl='.',team='') return self.board break else: print('Figure can not move here, try again') continue
def pow(base,expo): if isinstance(base, Variable): if isinstance(expo, (list,Variable)): return Variable(base.e, coeff = base.coeff, expo = expo) elif isinstance(base.e, Empty): return base.coeff**expo elif isinstance(base.e, float): return base.e**expo else: return Variable(base.e, coeff= base.coeff, expo= base.expo*expo) elif isinstance(base,list): if isinstance(expo, (int,float)): right = deepcopy(base) left = deepcopy(base) print(left) while (expo > 1): expo -= 1 left = calcByTerm('*',left,right) print(left) return Variable(Empty(), coeff=left) else: if isinstance(expo, (list,Variable)): return Variable(Empty(), coeff=base, expo = expo) else: return base**expo
def test_config_load(self): from empty import Empty from test_empty import config app = Empty('myapp') config_instance = config.EmptyConfig(DEBUG=True) app.configure(config_instance) self.assertEqual(app.config['DEBUG'], config_instance.DEBUG)
def test_config_from_environment_has_precedence(self): from empty import Empty from test_empty import config os.environ['FLASK_CONFIG'] = os.path\ .abspath('test_empty/config_set/debug_config.py') app = Empty('myapp') app.configure(config.EmptyConfig(DEBUG=False)) self.assertTrue(app.config['DEBUG'])
def test_config_from_environment_has_precedence(test_configs): from empty import Empty import config, env_config os.environ['APP_CONFIG'] = os.path.abspath('tests/test_configs/env_config.py') app = Empty('myapp') Config = config.EmptyConfig(DEBUG=not env_config.DEBUG) app.configure(Config) assert app.config['DEBUG'] is env_config.DEBUG
def test_config_load_blueprint(self): from empty import Empty from empty import EmptyConfig my_config = EmptyConfig(BLUEPRINTS=['app1']) my_app = Empty('myapp') my_app.configure(my_config) self.assertEqual(len(my_config.BLUEPRINTS), 1) self.assertEqual(len(my_app.blueprints), 1)
def test_config_load_extension(self): from empty import Empty from empty import EmptyConfig config = EmptyConfig(EXTENSIONS=[ 'extensions.ext' ]) app = Empty('myapp') app.configure(config) app.setup() ext = app.extensions['ext'] self.assertTrue('test' in ext.options)
def top(self): """Return (not remove) the element at the top of the stack. Raise Empty exception if the stack is empty. """ if self.is_empty(): raise Empty('Stack is empty!') return self._head.element
def display(self): if self._is_empty(): raise Empty('Empty list') else: temp = self.head while temp: print(temp.element, "--->")
def event(self, name, target): if name == "player-selected": self.setContent( ActionBar(self._controller, target.ship().actions, self._fontObj)) if name == "all-unselected": self.setContent(Empty())
def remove_min(self): if self.is_empty(): raise Empty('Priority queue is empty') self._swap(0, len(self._data) - 1) item = self._data.pop() self._downheap(0) return (item._key, item._value)
def pop(self): if self.is_empty(): raise Empty('Stack is empty') answer = self._head._element self._head = self._head._next self._size -= 1 return answer
def dequeue(self): if self.is_empty(): raise Empty('Queue is empty') oldhead = self._tail self._tail = oldhead._next self._size -= 1 return oldhead._element
def event(self, name, data): if name == "all-selected": self.setContent( Confirm(self._controller, self._fontObj, data.attacker(), data.weapon(), data.target())) if name == "all-unselected": self.setContent(Empty())
def first(self): """Return (not remove) the element at the front of the queue. Raise Empty exception if the queue is empty. """ if self.is_empty(): raise Empty('Queue is empty!') return self._data[self._front]
def delete_first(self): """Remove and return the element from the front of the deque. Raise Empty exception if the deque is empty. """ if self.is_empty(): raise Empty('Deque is empty!') return self._delete_node(self._header.next_node)
def delete_last(self): """Remove and return the element from the back of the deque. Raise Empty exception if the deque is empty. """ if self.is_empty(): raise Empty('Deque is empty!') return self._delete_node(self._trailer.prev_node)
def min(self): """Return but do not remove (k, v) tuple with minium key.""" if self.is_empty(): raise Empty("Priority queue is empty.") p = self._data.first() item = p.element() return (item._key, item._value)
def pop(self): """returns: the element removed from the top of the stack""" if self.is_empty(): raise Empty('The stack is empty') removed = self._head._element self._head = self._head._next self._size -= 1 return removed
def top(self): """Return (but do not remove) last item in stack Raise Empty exception if the stack is empty """ if self.is_empty(): raise Empty('stack is empty') return self._data[-1]
def delete_last(self): """ Removes and returns the last element in the dequeue raises: an Empty exception if the dequeue is empty """ if self._size == 0: raise Empty('Dequeue is empty') return self._delete_node(self._tail._prev)
def first(self): """Return (but do not remove) front item in queue Raise Empty exception if queue is empty """ if self.is_empty(): raise Empty('queue is empty') return self._data[self._front]
def pop(self): """ returns: the element remove from the top of the stack raises: an Empty exception if the stack is empty """ if self.isEmpty(): raise Empty('Stack is empty') return self._data.pop()
def last(self): """ returns: the last element in the dequeue without removing it raises: an Empty exception if the dequeue is empty """ if self._size == 0: raise Empty('Dequeue is empty') return self._tail._prev._element
def deque(self): if self.size == 0: raise Empty("que is empty") else: value = self.data[self.front] self.front += 1 self.size -= 1 return value
def delete_first(self): """ Removes and returns the first element in the dequeue raises: an Empty exception if the dequeue is empty """ if self._size == 0: raise Empty('Dequeue is empty') return self._delete_node(self._head._next)
def first(self): """ returns: the first element in the Queue without removing it """ if self.is_empty(): raise Empty('Queue is empty') head = self._tail._next return head._element
def first(self): """ returns: the first element in the dequeue without removing it raises: an Empty exception if the dequeue is empty """ if self._size == 0: raise Empty('Dequeue is empty') return self._head._next._element
def min(self): """Return but do not remove (k,v) tuple with minimum key. Raise Empty exception if empty.""" if self.is_empty(): raise Empty("Priority queue is empty") item = self._data[0] return (item._key, item._value)
def pop(self): """Return and return the top element of the stack (LIFO) Raise Empty exception id the stack is empty """ if self.is_empty(): raise Empty('stack is empty') return self._data.pop()
def __init__(self): self.empty = Empty(self) self.not_empty = NotEmpty(self) self.check_out = AtCheckOut(self) self.paid_for = PaidFor(self) self.items = 0 self.state = self.empty
def top(self): """ returns: the element at the top of the stack without removing it raises: an Empty exception if the stack is empty """ if self.isEmpty(): raise Empty('Stack is empty') return self._data[-1]
def create_app(self): from empty import Empty app = Empty('myapp') app.setup() return app