def test_cat_fail(): c4 = Cat('leopard', 1.6, 'snake', True) c5 = Cat('ocelot', 1.0, 'fish', False) c6 = Cat('lynx', 1.3, 'squirrel', False) assert 'lynx' in c6 assert c4.max_size <= c5.max_size
def test_cat_replace(): # replace() should change passed in fields c_before = Cat('cheetah', 1.5, 'rabbit', True) c_after = c_before._replace(roars=False) c_expected = Cat('cheetah', 1.5, 'rabbit', False) assert c_after == c_expected assert c_after.roars is False assert c_expected.max_size < 2.0
def handle_command(command, channel): """ Executes bot command if the command is known. """ # Default response is help text for the user default_response = "I don't know that. Pester @mmcconway to implement it!" # Finds and executes the given command, filling in the response response = None if command.startswith(EXAMPLE_COMMAND): response = command if command.startswith("weather") or command.startswith("Weather"): weather = Weather() city = command[command.find(" ") + 1:] temp = weather.getWeather(city) response = "It is currently {} in {}.".format(temp, city) if command.startswith("cat") or command.startswith("Cat"): CatGetter = Cat() response = CatGetter.getCat() if command.startswith("whois") or command.startswith("Whois"): who = Who() domain = command[command.find(" ") + 1:command.rfind(" ")] tld = command[command.find(domain) + len(domain) + 1:] response = who.getWhois(domain, tld) if command.startswith("check") or command.startswith("Check"): who = Who() domain = command[command.find(" ") + 1:command.rfind(" ")] tld = command[command.find(domain) + len(domain) + 1:] response = who.getRegistration(domain, tld) # Sends the response back to the channel slack_client.api_call("chat.postMessage", channel=channel, text=response or default_response)
def test_cat_attributes(): c3 = Cat('lion', 2.5, 'elephant', True) assert c3.type == 'lion' assert c3.max_size == 2.5 assert c3.favourite_food == 'elephant' assert c3.roars is True assert 'leopard' not in c3
def test_asdict(): # asdict() should return a dictionary. c_cat = Cat('tiger', 3.9, 'deer', True) c_dict = c_cat._asdict() expected = { 'type': 'tiger', 'max_size': 3.9, 'favourite_food': 'deer', 'roars': True } assert c_dict == expected
def setUp(self): self.animal = Cat("Kitty", run_energy=5)
from cats import Cat cat1 = Cat("Сэм", "мальчик", 2) cat2 = Cat("Барон", "мальчик", 2) cat_list = [cat1, cat2] for cat in cat_list: cat.get_list()
def test_cat_defaults(): c1 = Cat() c2 = Cat('Unknown', 'Unknown', 'Unknown', False) assert c1 == c2
def setUp(self): self.name = "test_cat" self.cat = Cat(self.name)
from cats import Cat cat1 = Cat('Барон', 'мальчик', 2) cat2 = Cat('Сэм', 'мальчик', 2) print('Имя первого кота:', cat1.getName()) print('Пол первого кота:', cat1.getGender()) print('Возраст первого кота:', cat1.getAge()) print('Имя второго кота:', cat2.getName()) print('Пол второго кота:', cat2.getGender()) print('Возраст второго кота:', cat2.getAge())
if self.dogs.size() == 0: return self.dequeue_cats() elif self.cats.size() == 0: return self.dequeue_dogs() if self.dogs.peek().value.is_older_than(self.cats.peek().value): return self.dequeue_dogs() else: return self.dequeue_cats() def dequeue_dogs(self): return self.dogs.remove_head() def dequeue_cats(self): return self.cats.remove_head() x = AnimalQueue() x.enqueue(Dog('Dog1')) x.enqueue(Cat('Cat1')) x.enqueue(Cat('Cat2')) x.enqueue(Dog('Dog2')) x.enqueue(Dog('Dog3')) x.enqueue(Dog('Dog4')) x.enqueue(Cat('Cat3')) x.enqueue(Cat('Cat4')) x.enqueue(Dog('Dog5')) print(x.dequeue_cats().value.name) print(x.dequeue().value.name) print(x.dequeue_dogs().value.name)
from cats import Cat #Cat с большой буквы cat1= Cat("Баронэсса", "кот", "девочка", "японская кошка", "1.5 года", "С222222", "дом найден") cat2= Cat("Шаляпин", "кот","мальчик","Неизвестно","1 год", "D323232", "Дом не найден") print("Имя: ",cat1.first_name ) print("Порода кошки: ",cat1.cat_class) print("Пол: ",cat1.gender) print("Вид животного: ",cat1.pet_class) print("Возраст: ",cat1.age) print("Рег. док.: ",cat1.reg_doc) print("Статус: ",cat1.status) print() print("Имя: ",cat2.first_name ) print("Порода кошки: ",cat2.cat_class) print("Пол: ",cat2.gender) print("Вид животного: ",cat2.pet_class) print("Возраст: ",cat2.age) print("Рег. док.: ",cat2.reg_doc) print("Статус: ",cat2.status)