コード例 #1
0
    def test_print_character_no_inventory(self, mock_output):
        character = {
            "Name": "Ophelia",
            "Class": "monk",
            "Race": "elf",
            "HP": [8, 8],
            "Strength": 3,
            "Dexterity": 3,
            "Constitution": 3,
            "Intelligence": 3,
            "Wisdom": 3,
            "Charisma": 3,
            "XP": 0
        }
        expected = """
Your character's name is Ophelia.

Class: Monk
Race: Elf
HP: 8/8

--Attributes--
Strength: 3
Dexterity: 3
Constitution: 3
Intelligence: 3
Wisdom: 3
Charisma: 3

EXP: 0
"""
        print_character(character)
        self.assertEqual(expected, mock_output.getvalue())
コード例 #2
0
 def test_print_character_type(self, mock_stdout):
     character = {
         "Name": "Azazi",
         "Class": "bard",
         "HP": 5,
         "Strength": 18,
         "Dexterity": 3,
         "Constitution": 12,
         "Intelligence": 6,
         "Wisdom": 12,
         "Charisma": 12,
         "XP": 0,
         "Inventory": []
     }
     expected_output = "Here is your new character!\n" \
                       "Name: Azazi\n" \
                       "Class: bard\n" \
                       "HP: 5\n" \
                       "Strength: 18\n"\
                       "Dexterity: 3\n" \
                       "Constitution: 12\n"\
                       "Intelligence: 6\n"\
                       "Wisdom: 12\n"\
                       "Charisma: 12\n"\
                       "XP: 0\n"\
                       "Inventory: []\n"
     dungeonsanddragons.print_character(character)
     self.assertIsInstance(mock_stdout.getvalue(), str)
コード例 #3
0
 def test_print_character_error(self, mock_stdout):
     character_details = {
         'Name': 'Kuwe',
         'Class': 'druid',
         'HP': 4,
         'Strength': 14,
         'Dexterity': 18,
         'Constitution': 5,
         'Intelligence': 3,
         'Wisdom': 18,
         'Charisma': 11,
         'XP': 0,
         'Inventory': []
     }
     expected_output = ("Name: Kuwe\n"
                        "Class: druid\n"
                        "HP: 4\n"
                        "Strength: 14\n"
                        "Dexterity: 18\n"
                        "Constitution: 5\n"
                        "Intelligence: 3\n"
                        "Wisdom: 18\n"
                        "Charisma: 11\n"
                        "XP: 0\n"
                        "Inventory: []\n")
     dungeonsanddragons.print_character(character_details)
     self.assertEqual(mock_stdout.getvalue(), expected_output)
コード例 #4
0
 def test_print_character_type(self, mock_stdout):
     character_details = {
         'Name': 'Kuwe',
         'Class': 'druid',
         'HP': 4,
         'Strength': 14,
         'Dexterity': 18,
         'Constitution': 5,
         'Intelligence': 3,
         'Wisdom': 18,
         'Charisma': 11,
         'XP': 0,
         'Inventory': []
     }
     dungeonsanddragons.print_character(character_details)
     self.assertEqual(type(mock_stdout.getvalue()), str)
コード例 #5
0
 def test_print_character(self, mock_stdout):
     character = {
         'name': 'tommy',
         'class': 'druid',
         'HitPoints': 5,
         'strength': 9,
         'dexterity': 13,
         'constitution': 14,
         'intelligence': 9,
         'wisdom': 9,
         'charisma': 7,
         'XP': 0,
         'items': []
     }
     print_character(character)
     expected_output = "name tommy\nclass druid\nHitPoints 5\nstrength 9\ndexterity 13\n" \
                       "constitution 14\nintelligence 9\nwisdom 9\ncharisma 7\nXP 0\nitems []\n"
     output = mock_stdout.getvalue()
     self.assertEqual(expected_output, output)
コード例 #6
0
    def test_print_character(self, mock_stdout):
        expected_output = 'Your character is named Vedyma \nYour race is dwarf \nYour class is bard \n' \
                          'Your starting HP is 7\nYour Strength is 14\nYour Dexterity is 9\nYour Constitution is 6\n' \
                          'Your Intelligence is 11\nYour Wisdom is 13\nYour Charisma is 9\nYour current XP is 0' \
                          '\nYou don\'t have any items right now.\n'

        print_character({
            'Name': 'Vedyma',
            'Race': 'dwarf',
            'Class': 'bard',
            'HP': [7, 7],
            'Strength': 14,
            'Dexterity': 9,
            'Constitution': 6,
            'Intelligence': 11,
            'Wisdom': 13,
            'Charisma': 9,
            'XP': 0,
            'Inventory': []
        })
        self.assertEqual(mock_stdout.getvalue(), expected_output)
コード例 #7
0
 def test_print_character(self, mock_stdout):
     print_character(character)
     self.assertTrue(
         "CHARACTER INFO:\nName A\nClass barbarian\nHP 10\nStrength 10\nDexterity 10\nConstitution 10\n"
         "Intelligence 10\nWisdom 10\nCharisma 10\nXP 0\nItem a\nItem b" in
         mock_stdout.getvalue())
コード例 #8
0
 def test_print_character_with_list(self):
     character = ["Azazi", "bard", 5, 8, 3, 12, 6, 12, 12, 0]
     with self.assertRaises(AttributeError):
         dungeonsanddragons.print_character(character)
コード例 #9
0
 def test_wrong_input(self, mock_stdout):
     character = 15
     with self.assertRaises(AttributeError):
         print_character(character)