Ejemplo n.º 1
0
 def test_level20_magic(self):
     hero = Hero("Dummy", 20)
     expected = [
         "fireball", "heal", "midheal", "rage", "snort_coke", "firewhirl"
     ]
     magic = [x for x in dir(hero.magic) if not x.startswith("_")]
     self.assertEqual(sorted(magic), sorted(expected))
Ejemplo n.º 2
0
 def test_lv20_buy(self):
     hero = Hero('Big20', 20)
     new_store = store.StoreMenu(hero)
     with patch('builtins.input', lambda _: '1') as o:
         buy_menu = new_store.handle_options()
         with patch('builtins.input', lambda _: '8') as p:
             item_choice = buy_menu.handle_options()
             self.assertEqual(item_choice.name, 'Vodka Shots')
Ejemplo n.º 3
0
def generate_hero():
    """ Create Hero object or load hero data from save file."""
    loaded_data = load_hero()
    if loaded_data:
        return loaded_data
    else:
        name = get_name()
        hero = Hero(name, 1)
        return hero
Ejemplo n.º 4
0
import os
import sys
import unittest
from unittest.mock import patch

from HonestQuest.characters.hero import Hero
from HonestQuest.items import items
from HonestQuest.sequences.store_sequence import StoreSequence

sys.stdout = open(os.devnull, "w")

hero = Hero("Dummy", 1)
hero.gold += 1000

STORE = StoreSequence(hero)


class TestStoreBuyingSelling(unittest.TestCase):
    def test_buying_transfer(self):
        STORE.purchase(items.Potion())
        inv_list = [x.name for x in hero.inventory]
        self.assertTrue("Potion" in inv_list)

    def test_buying_cost(self):
        old_gold = hero.gold
        STORE.purchase(items.Potion())
        difference = old_gold - hero.gold
        self.assertEqual(difference, items.Potion().cost)

    def test_selling_transfer(self):
        old_inv_len = len(hero.inventory)
Ejemplo n.º 5
0
import os

sys.stdout = open(os.devnull, 'w')

# Create a menu for testing
option = {'1': 'A', '2': 'B'}
choices = '1. A\n2. B'
M = Menu(option, choices)

# Create a submenu for tesing
options = {'1': 'C', '2': 'D'}
choices = '1. C\n2. D'
SM = Menu(options, choices, M)

# Create a hero to test the StoreMenu
hero = Hero('Dummy', 1)
hero.inventory.add_items(Potion(), Potion())
STORE = store.StoreMenu(hero)

# Create an enemy to test the BattleMenu
factory = EnemyFactory()
enemy = factory.generate_enemy('Goblin', 1)
BATTLE = battle_menus.TopMenu(hero, enemy)


class TestMenu(unittest.TestCase):
    @patch('builtins.input', lambda _: '1')
    def test_menu_option_1(self):
        choice = M.handle_options()
        self.assertEqual(choice, 'A')
Ejemplo n.º 6
0
 def test_level_up_magic(self):
     hero = Hero("Dummy", 1)
     old_magic = [x for x in dir(hero.magic) if not x.startswith("_")]
     hero.exp = 200
     magic = [x for x in dir(hero.magic) if not x.startswith("_")]
     self.assertEqual(old_magic + ["rage"], magic)
Ejemplo n.º 7
0
 def test_level_up(self):
     hero = Hero("Dummy", 1)
     old_lv = hero.lv
     hero.exp = 200
     self.assertFalse(old_lv == hero.lv)
Ejemplo n.º 8
0
 def test_death(self):
     hero = Hero("Dummy", 1)
     with self.assertRaises(SystemExit):
         hero.alter_stat("hp", 700, "-")
Ejemplo n.º 9
0
""" python3 ./test_modules.py -b """
import logging
import os
import sys
import unittest

from HonestQuest.characters.enemy import EnemyFactory
from HonestQuest.characters.hero import Hero

sys.stdout = open(os.devnull, "w")

log = logging.getLogger()
log.disabled = True

HERE = os.path.dirname(os.path.realpath(__file__))
HERO = Hero("Dummy", 10)
factory = EnemyFactory()


class TestEnemyFactory(unittest.TestCase):
    def test_goblin_stats(self):
        goblin = factory.generate_enemy("Goblin", 1)
        stats = [
            goblin.hp,
            goblin.mp,
            goblin.ag,
            goblin.st,
            goblin.exp,
            goblin.gold,
            goblin.lv,
            goblin.random,
Ejemplo n.º 10
0
import logging
import os
import sys
import unittest

from HonestQuest.characters.enemy import EnemyFactory
from HonestQuest.characters.hero import Hero
from HonestQuest.items import inventory, items

sys.stdout = open(os.devnull, "w")

log = logging.getLogger()
log.disabled = True

HERO = Hero("Dummy", 99)
factory = EnemyFactory()
ENEMY = factory.generate_enemy("Goblin", 99)


class InventoryUsage(unittest.TestCase):
    def test_add_items(self):
        HERO.inventory.add_items(
            items.Potion(),
            items.Ether(),
            items.ProteinShake(),
            items.RedBull(),
            items.Molotov(),
            items.ManaCleaner(),
            items.VodkaShots(),
            items.MegaPhone(),
        )