Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit 357af45a114e815aab6deac73ca83902dd0ce1d5
parent 4323a9dda78bae3b59a6033221f9dfd774b6b240
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 27 Nov 2020 16:27:05 -0600

Implementing unit testing partially

Diffstat:
Mrequirements.txt | 1+
Msrc/manager.py | 3++-
Msrc/piece.py | 2+-
Msrc/sound.py | 3++-
Atest/test_sound.py | 29+++++++++++++++++++++++++++++
5 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/requirements.txt b/requirements.txt @@ -1,3 +1,4 @@ pygame==1.9.6 +pyparsing==2.4.7 PyTMX==3.22.0 six==1.15.0 diff --git a/src/manager.py b/src/manager.py @@ -65,7 +65,8 @@ class Manager(subsystem.GameSubsystem): self._effectual = False # Bus records functionality - self.record_self() + if self.bus != None: + self.record_self() def record_self(self): """ diff --git a/src/piece.py b/src/piece.py @@ -547,7 +547,7 @@ class Piece(entity.Entity): self.damage_to_receive = 0 else: self.damage_to_receive = max(0, - round((raw_damage - (self.active_stats["DEF"] * 1.4)) + random.randint(-(self.active_stats["LUK"] // 2), self.active_stats["LUK"])) * affmod) + round(((raw_damage - (self.active_stats["DEF"] * 1.4)) + random.randint(-(self.active_stats["LUK"] // 2), self.active_stats["LUK"])) * affmod)) self.damage_timer = 100 self.being_damaged = True self.render_damage_number() diff --git a/src/sound.py b/src/sound.py @@ -41,7 +41,8 @@ class SoundManager(manager.Manager): Load up sounds from a definition JSON file. """ - j = json.load(open(os.path.join(JSON_PATH, soundjson))) + with open(os.path.join(JSON_PATH, soundjson)) as sj: + j = json.load(sj) for s in j["sounds"]: self.sounds[s["name"]] = pygame.mixer.Sound(os.path.join(SOUND_PATH, s["filename"])) diff --git a/test/test_sound.py b/test/test_sound.py @@ -0,0 +1,29 @@ +import unittest, pygame +from src import sound +from src.constants import * + +###################### +# TESTS FOR sound.py # +###################### + +class TestSoundManager(unittest.TestCase): + """ + Test class for the sound.SoundManager + object. + """ + + @classmethod + def setUpClass(cls): + print("Setting up TestSoundManager class...") + pygame.mixer.pre_init(44100, -16, 4, 1024) + pygame.init() + + def setUp(self): + self.model_sound_manager = sound.SoundManager(None, None, None, "sound_manager") + + def test_load_sounds_from_json(self): + self.model_sound_manager.load_sounds_from_json("sounds.json") + print(self.model_sound_manager.sounds) + +if __name__ == "__main__": + unittest.main()