Ejemplo n.º 1
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)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
 def setUp(self):
     self.animal = Cat("Kitty", run_energy=5)
Ejemplo n.º 7
0
from cats import Cat

cat1 = Cat("Сэм", "мальчик", 2)
cat2 = Cat("Барон", "мальчик", 2)

cat_list = [cat1, cat2]

for cat in cat_list:
    cat.get_list()
Ejemplo n.º 8
0
def test_cat_defaults():
    c1 = Cat()
    c2 = Cat('Unknown', 'Unknown', 'Unknown', False)
    assert c1 == c2
Ejemplo n.º 9
0
 def setUp(self):
     self.name = "test_cat"
     self.cat = Cat(self.name)
Ejemplo n.º 10
0
class TestCat(unittest.TestCase):
    def setUp(self):
        self.name = "test_cat"
        self.cat = Cat(self.name)

    def test_cat_actions(self):
        self.cat.fly()
        self.cat.swim()
        self.assertEqual(100, self.cat.get_energy(),
                         "Cat energy after fly/swim should not change")
        self.cat.run()
        self.assertEqual(95, self.cat.get_energy(),
                         "Cat energy after 1 run should be 95")
        for _ in range(19):
            self.cat.run()
        self.assertEqual(0, self.cat.get_energy(),
                         "Cat energy after 20 run should be 0")
        for _ in range(20):
            self.cat.run()
        self.assertEqual(-100, self.cat.get_energy(),
                         "Cat energy after 40 run should be -100")
Ejemplo n.º 11
0
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)
Ejemplo n.º 13
0
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)