Skip to content

Commit bbf82ef

Browse files
Address PR comments: fix Stats import, extract dialogue to UserInterface, improve tests
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
1 parent d0ce3a0 commit bbf82ef

10 files changed

Lines changed: 64 additions & 37 deletions

File tree

src/location/bank.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from pstats import Stats
21
from location.enum.locationType import LocationType
32
from player.player import Player
43
from prompt.prompt import Prompt
54
from world.timeService import TimeService
5+
from stats.stats import Stats
66
from ui.userInterface import UserInterface
77
from npc.npc import NPC
88

@@ -113,9 +113,4 @@ def withdraw(self):
113113
break
114114

115115
def talkToNPC(self):
116-
self.userInterface.lotsOfSpace()
117-
self.userInterface.divider()
118-
print(self.npc.introduce())
119-
self.userInterface.divider()
120-
input(" [ CONTINUE ]")
121-
self.currentPrompt.text = "What would you like to do?"
116+
self.userInterface.showDialogue(self.npc.introduce())

src/location/docks.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,4 @@ def fish(self):
111111
)
112112

113113
def talkToNPC(self):
114-
self.userInterface.lotsOfSpace()
115-
self.userInterface.divider()
116-
print(self.npc.introduce())
117-
self.userInterface.divider()
118-
input(" [ CONTINUE ]")
119-
self.currentPrompt.text = "What would you like to do?"
114+
self.userInterface.showDialogue(self.npc.introduce())

src/location/shop.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,4 @@ def buyBetterBait(self):
7474
self.currentPrompt.text = "You bought some better bait!"
7575

7676
def talkToNPC(self):
77-
self.userInterface.lotsOfSpace()
78-
self.userInterface.divider()
79-
print(self.npc.introduce())
80-
self.userInterface.divider()
81-
input(" [ CONTINUE ]")
82-
self.currentPrompt.text = "What would you like to do?"
77+
self.userInterface.showDialogue(self.npc.introduce())

src/location/tavern.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,4 @@ def changeBet(self, prompt):
151151
)
152152

153153
def talkToNPC(self):
154-
self.userInterface.lotsOfSpace()
155-
self.userInterface.divider()
156-
print(self.npc.introduce())
157-
self.userInterface.divider()
158-
input(" [ CONTINUE ]")
159-
self.currentPrompt.text = "What would you like to do?"
154+
self.userInterface.showDialogue(self.npc.introduce())

src/ui/userInterface.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ def showOptions(
7878
return choice
7979

8080
self.currentPrompt.text = "Try again!"
81+
82+
def showDialogue(self, text):
83+
self.lotsOfSpace()
84+
self.divider()
85+
print(text)
86+
self.divider()
87+
input(" [ CONTINUE ]")
88+
self.currentPrompt.text = "What would you like to do?"

tests/location/test_bank.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,16 @@ def test_run_talk_to_npc_action():
120120
def test_talkToNPC():
121121
# prepare
122122
bankInstance = createBank()
123+
bankInstance.userInterface.showDialogue = MagicMock()
124+
125+
# call
126+
bankInstance.talkToNPC()
123127

124128
# check
125-
assert bankInstance.npc.name == "Margaret the Teller"
126-
assert len(bankInstance.npc.backstory) > 0
129+
bankInstance.userInterface.showDialogue.assert_called_once()
130+
call_args = bankInstance.userInterface.showDialogue.call_args[0][0]
131+
assert "Margaret the Teller" in call_args
132+
assert len(call_args) > 0
127133

128134

129135
def test_deposit_success():

tests/location/test_docks.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ def test_run_talk_to_npc_action():
7474
def test_talkToNPC():
7575
# prepare
7676
docksInstance = createDocks()
77+
docksInstance.userInterface.showDialogue = MagicMock()
78+
79+
# call
80+
docksInstance.talkToNPC()
7781

7882
# check
79-
assert docksInstance.npc.name == "Sam the Dock Worker"
80-
assert len(docksInstance.npc.backstory) > 0
83+
docksInstance.userInterface.showDialogue.assert_called_once()
84+
call_args = docksInstance.userInterface.showDialogue.call_args[0][0]
85+
assert "Sam the Dock Worker" in call_args
86+
assert len(call_args) > 0
8187

8288

8389
def test_run_go_to_shop_action():

tests/location/test_shop.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@ def test_run_talk_to_npc_action():
8888
def test_talkToNPC():
8989
# prepare
9090
shopInstance = createShop()
91-
shopInstance.userInterface.lotsOfSpace = MagicMock()
92-
shopInstance.userInterface.divider = MagicMock()
91+
shopInstance.userInterface.showDialogue = MagicMock()
9392

9493
# call
95-
# We can't fully test the input() part, but we can test the method exists
96-
# and the NPC has the right data
97-
assert shopInstance.npc.name == "Gilbert the Shopkeeper"
98-
assert len(shopInstance.npc.backstory) > 0
94+
shopInstance.talkToNPC()
95+
96+
# check
97+
shopInstance.userInterface.showDialogue.assert_called_once()
98+
call_args = shopInstance.userInterface.showDialogue.call_args[0][0]
99+
assert "Gilbert the Shopkeeper" in call_args
100+
assert len(call_args) > 0
99101

100102

101103
def test_sellFish():

tests/location/test_tavern.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ def test_run_talk_to_npc_action():
105105
def test_talkToNPC():
106106
# prepare
107107
tavernInstance = createTavern()
108+
tavernInstance.userInterface.showDialogue = MagicMock()
109+
110+
# call
111+
tavernInstance.talkToNPC()
108112

109113
# check
110-
assert tavernInstance.npc.name == "Old Tom the Barkeep"
111-
assert len(tavernInstance.npc.backstory) > 0
114+
tavernInstance.userInterface.showDialogue.assert_called_once()
115+
call_args = tavernInstance.userInterface.showDialogue.call_args[0][0]
116+
assert "Old Tom the Barkeep" in call_args
117+
assert len(call_args) > 0
112118

113119

114120
def test_getDrunk():

tests/ui/test_userInterface.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,22 @@ def test_showOptions():
6767
userInterfaceInstance.lotsOfSpace.assert_called()
6868
assert userInterfaceInstance.divider.call_count == 3
6969
userInterface.input.assert_called_with("\n> ")
70+
71+
72+
def test_showDialogue():
73+
# setup
74+
userInterfaceInstance = createUserInterface()
75+
userInterface.print = MagicMock()
76+
userInterface.input = MagicMock(return_value="")
77+
userInterfaceInstance.lotsOfSpace = MagicMock()
78+
userInterfaceInstance.divider = MagicMock()
79+
80+
# call
81+
userInterfaceInstance.showDialogue("Test dialogue text")
82+
83+
# check
84+
userInterfaceInstance.lotsOfSpace.assert_called_once()
85+
assert userInterfaceInstance.divider.call_count == 2
86+
userInterface.print.assert_called_with("Test dialogue text")
87+
userInterface.input.assert_called_with(" [ CONTINUE ]")
88+
assert userInterfaceInstance.currentPrompt.text == "What would you like to do?"

0 commit comments

Comments
 (0)