From 3e45276d2fe9e0aa8cf723e1d6e564fc2bdf2326 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:13:41 +0000 Subject: [PATCH 1/4] Initial plan From 8d9fd6363c9e1da110c1e9e46119303e90580e79 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:18:42 +0000 Subject: [PATCH 2/4] Add NPC system with names and backstories for all locations Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com> --- src/location/bank.py | 21 ++++++++++++++++++++- src/location/docks.py | 28 ++++++++++++++++++++++++---- src/location/shop.py | 19 +++++++++++++++++++ src/location/tavern.py | 21 ++++++++++++++++++++- src/npc/__init__.py | 0 src/npc/npc.py | 9 +++++++++ tests/location/test_bank.py | 27 ++++++++++++++++++++++++++- tests/location/test_docks.py | 33 +++++++++++++++++++++++++++++---- tests/location/test_shop.py | 31 ++++++++++++++++++++++++++++++- tests/location/test_tavern.py | 27 ++++++++++++++++++++++++++- tests/npc/test_npc.py | 21 +++++++++++++++++++++ 11 files changed, 224 insertions(+), 13 deletions(-) create mode 100644 src/npc/__init__.py create mode 100644 src/npc/npc.py create mode 100644 tests/npc/test_npc.py diff --git a/src/location/bank.py b/src/location/bank.py index 6854091..bf87dfe 100644 --- a/src/location/bank.py +++ b/src/location/bank.py @@ -4,6 +4,7 @@ from prompt.prompt import Prompt from world.timeService import TimeService from ui.userInterface import UserInterface +from npc.npc import NPC # @author Daniel McCoy Stephenson @@ -21,9 +22,15 @@ def __init__( self.player = player self.stats = stats self.timeService = timeService + self.npc = NPC( + "Margaret the Teller", + "I've worked at this bank for fifteen years and I take pride in keeping everyone's money safe. " + "My grandmother taught me the value of saving, and I've helped many fishermen in this village " + "secure their futures. A penny saved is a penny earned, as they say!", + ) def run(self): - li = ["Make a Deposit", "Make a Withdrawal", "Go to docks"] + li = ["Make a Deposit", "Make a Withdrawal", "Talk to %s" % self.npc.name, "Go to docks"] input = self.userInterface.showOptions( "You're at the front of the line and the teller asks you what you want to do.", li, @@ -52,6 +59,10 @@ def run(self): return LocationType.BANK elif input == "3": + self.talkToNPC() + return LocationType.BANK + + elif input == "4": self.currentPrompt.text = "What would you like to do?" return LocationType.DOCKS @@ -100,3 +111,11 @@ def withdraw(self): else: self.currentPrompt.text = "You don't have that much money in the bank!" break + + def talkToNPC(self): + self.userInterface.lotsOfSpace() + self.userInterface.divider() + print(self.npc.introduce()) + self.userInterface.divider() + input(" [ CONTINUE ]") + self.currentPrompt.text = "What would you like to do?" diff --git a/src/location/docks.py b/src/location/docks.py index fbc5dbd..943c0a9 100644 --- a/src/location/docks.py +++ b/src/location/docks.py @@ -8,6 +8,7 @@ from world.timeService import TimeService from stats.stats import Stats from ui.userInterface import UserInterface +from npc.npc import NPC # @author Daniel McCoy Stephenson @@ -25,9 +26,16 @@ def __init__( self.player = player self.stats = stats self.timeService = timeService + self.npc = NPC( + "Sam the Dock Worker", + "Been working these docks since I was knee-high to a grasshopper. " + "My pa was a fisherman, and his pa before him. I help maintain the boats and docks, " + "and I've learned a thing or two about fishing over the years. " + "The sea provides for those who respect her!", + ) def run(self): - li = ["Fish", "Go Home", "Go to Shop", "Go to Tavern", "Go to Bank"] + li = ["Fish", "Talk to %s" % self.npc.name, "Go Home", "Go to Shop", "Go to Tavern", "Go to Bank"] input = self.userInterface.showOptions( "You breathe in the fresh air. Salty.", li ) @@ -41,18 +49,22 @@ def run(self): return LocationType.DOCKS elif input == "2": + self.talkToNPC() + return LocationType.DOCKS + + elif input == "3": self.currentPrompt.text = "What would you like to do?" return LocationType.HOME - elif input == "3": + elif input == "4": self.currentPrompt.text = "What would you like to do?" return LocationType.SHOP - elif input == "4": + elif input == "5": self.currentPrompt.text = "What would you like to do?" return LocationType.TAVERN - elif input == "5": + elif input == "6": self.currentPrompt.text = ( "What would you like to do? Money in Bank: $%.2f" % self.player.moneyInBank @@ -97,3 +109,11 @@ def fish(self): fishToAdd, hours, ) + + def talkToNPC(self): + self.userInterface.lotsOfSpace() + self.userInterface.divider() + print(self.npc.introduce()) + self.userInterface.divider() + input(" [ CONTINUE ]") + self.currentPrompt.text = "What would you like to do?" diff --git a/src/location/shop.py b/src/location/shop.py index f45d589..611d6f5 100644 --- a/src/location/shop.py +++ b/src/location/shop.py @@ -5,6 +5,7 @@ from world.timeService import TimeService from stats.stats import Stats from ui.userInterface import UserInterface +from npc.npc import NPC # @author Daniel McCoy Stephenson @@ -22,11 +23,18 @@ def __init__( self.player = player self.stats = stats self.timeService = timeService + self.npc = NPC( + "Gilbert the Shopkeeper", + "I've been running this shop for thirty years, ever since I inherited it from my father. " + "I've seen many fishermen come and go, but the best ones always come back for quality bait. " + "I may not fish much anymore, but I know good gear when I see it!", + ) def run(self): li = [ "Sell Fish", "Buy Better Bait ( $%d )" % self.player.priceForBait, + "Talk to %s" % self.npc.name, "Go to Docks", ] input = self.userInterface.showOptions( @@ -41,6 +49,9 @@ def run(self): self.buyBetterBait() return LocationType.SHOP elif input == "3": + self.talkToNPC() + return LocationType.SHOP + elif input == "4": self.currentPrompt.text = "What would you like to do?" return LocationType.DOCKS @@ -61,3 +72,11 @@ def buyBetterBait(self): self.player.priceForBait = self.player.priceForBait * 1.25 self.currentPrompt.text = "You bought some better bait!" + + def talkToNPC(self): + self.userInterface.lotsOfSpace() + self.userInterface.divider() + print(self.npc.introduce()) + self.userInterface.divider() + input(" [ CONTINUE ]") + self.currentPrompt.text = "What would you like to do?" diff --git a/src/location/tavern.py b/src/location/tavern.py index 0fa7bf1..9756f40 100644 --- a/src/location/tavern.py +++ b/src/location/tavern.py @@ -9,6 +9,7 @@ from world.timeService import TimeService from stats.stats import Stats from ui.userInterface import UserInterface +from npc.npc import NPC # @author Daniel McCoy Stephenson @@ -28,9 +29,15 @@ def __init__( self.timeService = timeService self.currentBet = 0 + self.npc = NPC( + "Old Tom the Barkeep", + "I sailed the seven seas for forty years before settling down here. " + "Lost my leg to a shark near the Caribbean, but I got plenty of stories to make up for it. " + "These days I pour drinks and listen to folks' troubles. Best job I ever had!", + ) def run(self): - li = ["Get drunk ( $10 )", "Gamble", "Go to Docks"] + li = ["Get drunk ( $10 )", "Gamble", "Talk to %s" % self.npc.name, "Go to Docks"] input = self.userInterface.showOptions( "You sit at the bar, watching the barkeep clean a mug with a dirty rag.", li ) @@ -51,6 +58,10 @@ def run(self): return LocationType.TAVERN elif input == "3": + self.talkToNPC() + return LocationType.TAVERN + + elif input == "4": self.currentPrompt.text = "What would you like to do?" return LocationType.DOCKS @@ -138,3 +149,11 @@ def changeBet(self, prompt): self.currentPrompt.text = ( "You don't have that much money on you! Money: $%d" % self.player.money ) + + def talkToNPC(self): + self.userInterface.lotsOfSpace() + self.userInterface.divider() + print(self.npc.introduce()) + self.userInterface.divider() + input(" [ CONTINUE ]") + self.currentPrompt.text = "What would you like to do?" diff --git a/src/npc/__init__.py b/src/npc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/npc/npc.py b/src/npc/npc.py new file mode 100644 index 0000000..714307a --- /dev/null +++ b/src/npc/npc.py @@ -0,0 +1,9 @@ +# @author Daniel McCoy Stephenson +class NPC: + def __init__(self, name: str, backstory: str): + self.name = name + self.backstory = backstory + + def introduce(self): + """Returns the NPC's introduction text""" + return f"{self.name}: {self.backstory}" diff --git a/tests/location/test_bank.py b/tests/location/test_bank.py index 471cbdc..466dd18 100644 --- a/tests/location/test_bank.py +++ b/tests/location/test_bank.py @@ -27,6 +27,8 @@ def test_initialization(): assert bankInstance.player != None assert bankInstance.stats != None assert bankInstance.timeService != None + assert bankInstance.npc != None + assert bankInstance.npc.name == "Margaret the Teller" def test_run_make_deposit_success(): @@ -92,7 +94,7 @@ def test_run_make_withdrawal_failure_no_money(): def test_run_go_to_docks_action(): # prepare bankInstance = createBank() - bankInstance.userInterface.showOptions = MagicMock(return_value="3") + bankInstance.userInterface.showOptions = MagicMock(return_value="4") # call nextLocation = bankInstance.run() @@ -101,6 +103,29 @@ def test_run_go_to_docks_action(): assert nextLocation == LocationType.DOCKS +def test_run_talk_to_npc_action(): + # prepare + bankInstance = createBank() + bankInstance.userInterface.showOptions = MagicMock(return_value="3") + bankInstance.talkToNPC = MagicMock() + + # call + nextLocation = bankInstance.run() + + # check + assert nextLocation == LocationType.BANK + bankInstance.talkToNPC.assert_called_once() + + +def test_talkToNPC(): + # prepare + bankInstance = createBank() + + # check + assert bankInstance.npc.name == "Margaret the Teller" + assert len(bankInstance.npc.backstory) > 0 + + def test_deposit_success(): # prepare bankInstance = createBank() diff --git a/tests/location/test_docks.py b/tests/location/test_docks.py index 0ef87d4..4917d7c 100644 --- a/tests/location/test_docks.py +++ b/tests/location/test_docks.py @@ -27,6 +27,8 @@ def test_initialization(): assert docksInstance.player != None assert docksInstance.stats != None assert docksInstance.timeService != None + assert docksInstance.npc != None + assert docksInstance.npc.name == "Sam the Dock Worker" def test_run_fish_action(): @@ -46,7 +48,7 @@ def test_run_fish_action(): def test_run_go_home_action(): # prepare docksInstance = createDocks() - docksInstance.userInterface.showOptions = MagicMock(return_value="2") + docksInstance.userInterface.showOptions = MagicMock(return_value="3") # call nextLocation = docksInstance.run() @@ -55,10 +57,33 @@ def test_run_go_home_action(): assert nextLocation == LocationType.HOME +def test_run_talk_to_npc_action(): + # prepare + docksInstance = createDocks() + docksInstance.userInterface.showOptions = MagicMock(return_value="2") + docksInstance.talkToNPC = MagicMock() + + # call + nextLocation = docksInstance.run() + + # check + assert nextLocation == LocationType.DOCKS + docksInstance.talkToNPC.assert_called_once() + + +def test_talkToNPC(): + # prepare + docksInstance = createDocks() + + # check + assert docksInstance.npc.name == "Sam the Dock Worker" + assert len(docksInstance.npc.backstory) > 0 + + def test_run_go_to_shop_action(): # prepare docksInstance = createDocks() - docksInstance.userInterface.showOptions = MagicMock(return_value="3") + docksInstance.userInterface.showOptions = MagicMock(return_value="4") # call nextLocation = docksInstance.run() @@ -70,7 +95,7 @@ def test_run_go_to_shop_action(): def test_run_go_to_tavern_action(): # prepare docksInstance = createDocks() - docksInstance.userInterface.showOptions = MagicMock(return_value="4") + docksInstance.userInterface.showOptions = MagicMock(return_value="5") # call nextLocation = docksInstance.run() @@ -82,7 +107,7 @@ def test_run_go_to_tavern_action(): def test_run_go_to_bank_action(): # prepare docksInstance = createDocks() - docksInstance.userInterface.showOptions = MagicMock(return_value="5") + docksInstance.userInterface.showOptions = MagicMock(return_value="6") # call nextLocation = docksInstance.run() diff --git a/tests/location/test_shop.py b/tests/location/test_shop.py index ffd30a3..12458d9 100644 --- a/tests/location/test_shop.py +++ b/tests/location/test_shop.py @@ -27,6 +27,8 @@ def test_initialization(): assert shopInstance.player != None assert shopInstance.stats != None assert shopInstance.timeService != None + assert shopInstance.npc != None + assert shopInstance.npc.name == "Gilbert the Shopkeeper" def test_run_sell_fish_action(): @@ -60,7 +62,7 @@ def test_run_buy_better_bait_action(): def test_run_go_to_docks_action(): # prepare shopInstance = createShop() - shopInstance.userInterface.showOptions = MagicMock(return_value="3") + shopInstance.userInterface.showOptions = MagicMock(return_value="4") # call nextLocation = shopInstance.run() @@ -69,6 +71,33 @@ def test_run_go_to_docks_action(): assert nextLocation == LocationType.DOCKS +def test_run_talk_to_npc_action(): + # prepare + shopInstance = createShop() + shopInstance.userInterface.showOptions = MagicMock(return_value="3") + shopInstance.talkToNPC = MagicMock() + + # call + nextLocation = shopInstance.run() + + # check + assert nextLocation == LocationType.SHOP + shopInstance.talkToNPC.assert_called_once() + + +def test_talkToNPC(): + # prepare + shopInstance = createShop() + shopInstance.userInterface.lotsOfSpace = MagicMock() + shopInstance.userInterface.divider = MagicMock() + + # call + # We can't fully test the input() part, but we can test the method exists + # and the NPC has the right data + assert shopInstance.npc.name == "Gilbert the Shopkeeper" + assert len(shopInstance.npc.backstory) > 0 + + def test_sellFish(): # prepare shopInstance = createShop() diff --git a/tests/location/test_tavern.py b/tests/location/test_tavern.py index b7adc1d..b4cda04 100644 --- a/tests/location/test_tavern.py +++ b/tests/location/test_tavern.py @@ -27,6 +27,8 @@ def test_initialization(): assert tavernInstance.player != None assert tavernInstance.stats != None assert tavernInstance.timeService != None + assert tavernInstance.npc != None + assert tavernInstance.npc.name == "Old Tom the Barkeep" def test_run_get_drunk_action_success(): @@ -77,7 +79,7 @@ def test_run_gamble_action_success(): def test_run_go_to_docks_action(): # prepare tavernInstance = createTavern() - tavernInstance.userInterface.showOptions = MagicMock(return_value="3") + tavernInstance.userInterface.showOptions = MagicMock(return_value="4") # call nextLocation = tavernInstance.run() @@ -86,6 +88,29 @@ def test_run_go_to_docks_action(): assert nextLocation == LocationType.DOCKS +def test_run_talk_to_npc_action(): + # prepare + tavernInstance = createTavern() + tavernInstance.userInterface.showOptions = MagicMock(return_value="3") + tavernInstance.talkToNPC = MagicMock() + + # call + nextLocation = tavernInstance.run() + + # check + assert nextLocation == LocationType.TAVERN + tavernInstance.talkToNPC.assert_called_once() + + +def test_talkToNPC(): + # prepare + tavernInstance = createTavern() + + # check + assert tavernInstance.npc.name == "Old Tom the Barkeep" + assert len(tavernInstance.npc.backstory) > 0 + + def test_getDrunk(): # prepare tavernInstance = createTavern() diff --git a/tests/npc/test_npc.py b/tests/npc/test_npc.py new file mode 100644 index 0000000..fddaed6 --- /dev/null +++ b/tests/npc/test_npc.py @@ -0,0 +1,21 @@ +from src.npc.npc import NPC + + +def test_initialization(): + # call + npc = NPC("Shopkeeper", "A friendly merchant who loves fishing gear.") + + # check + assert npc.name == "Shopkeeper" + assert npc.backstory == "A friendly merchant who loves fishing gear." + + +def test_introduce(): + # prepare + npc = NPC("Barkeep", "An old sailor with many tales to tell.") + + # call + introduction = npc.introduce() + + # check + assert introduction == "Barkeep: An old sailor with many tales to tell." From d0ce3a0cdef33770d12b316d0d0f305437624313 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:24:48 +0000 Subject: [PATCH 3/4] Fix trailing whitespace in test files Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com> --- tests/location/test_bank.py | 2 +- tests/location/test_docks.py | 2 +- tests/location/test_tavern.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/location/test_bank.py b/tests/location/test_bank.py index 466dd18..80db34f 100644 --- a/tests/location/test_bank.py +++ b/tests/location/test_bank.py @@ -120,7 +120,7 @@ def test_run_talk_to_npc_action(): def test_talkToNPC(): # prepare bankInstance = createBank() - + # check assert bankInstance.npc.name == "Margaret the Teller" assert len(bankInstance.npc.backstory) > 0 diff --git a/tests/location/test_docks.py b/tests/location/test_docks.py index 4917d7c..6c6bfee 100644 --- a/tests/location/test_docks.py +++ b/tests/location/test_docks.py @@ -74,7 +74,7 @@ def test_run_talk_to_npc_action(): def test_talkToNPC(): # prepare docksInstance = createDocks() - + # check assert docksInstance.npc.name == "Sam the Dock Worker" assert len(docksInstance.npc.backstory) > 0 diff --git a/tests/location/test_tavern.py b/tests/location/test_tavern.py index b4cda04..19d3c7e 100644 --- a/tests/location/test_tavern.py +++ b/tests/location/test_tavern.py @@ -105,7 +105,7 @@ def test_run_talk_to_npc_action(): def test_talkToNPC(): # prepare tavernInstance = createTavern() - + # check assert tavernInstance.npc.name == "Old Tom the Barkeep" assert len(tavernInstance.npc.backstory) > 0 From bbf82efb2abf300929de9fa615d04b314b48a24b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 22:46:11 +0000 Subject: [PATCH 4/4] Address PR comments: fix Stats import, extract dialogue to UserInterface, improve tests Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com> --- src/location/bank.py | 9 ++------- src/location/docks.py | 7 +------ src/location/shop.py | 7 +------ src/location/tavern.py | 7 +------ src/ui/userInterface.py | 8 ++++++++ tests/location/test_bank.py | 10 ++++++++-- tests/location/test_docks.py | 10 ++++++++-- tests/location/test_shop.py | 14 ++++++++------ tests/location/test_tavern.py | 10 ++++++++-- tests/ui/test_userInterface.py | 19 +++++++++++++++++++ 10 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/location/bank.py b/src/location/bank.py index bf87dfe..f139fa8 100644 --- a/src/location/bank.py +++ b/src/location/bank.py @@ -1,8 +1,8 @@ -from pstats import Stats from location.enum.locationType import LocationType from player.player import Player from prompt.prompt import Prompt from world.timeService import TimeService +from stats.stats import Stats from ui.userInterface import UserInterface from npc.npc import NPC @@ -113,9 +113,4 @@ def withdraw(self): break def talkToNPC(self): - self.userInterface.lotsOfSpace() - self.userInterface.divider() - print(self.npc.introduce()) - self.userInterface.divider() - input(" [ CONTINUE ]") - self.currentPrompt.text = "What would you like to do?" + self.userInterface.showDialogue(self.npc.introduce()) diff --git a/src/location/docks.py b/src/location/docks.py index 943c0a9..5c26e56 100644 --- a/src/location/docks.py +++ b/src/location/docks.py @@ -111,9 +111,4 @@ def fish(self): ) def talkToNPC(self): - self.userInterface.lotsOfSpace() - self.userInterface.divider() - print(self.npc.introduce()) - self.userInterface.divider() - input(" [ CONTINUE ]") - self.currentPrompt.text = "What would you like to do?" + self.userInterface.showDialogue(self.npc.introduce()) diff --git a/src/location/shop.py b/src/location/shop.py index 611d6f5..9366eec 100644 --- a/src/location/shop.py +++ b/src/location/shop.py @@ -74,9 +74,4 @@ def buyBetterBait(self): self.currentPrompt.text = "You bought some better bait!" def talkToNPC(self): - self.userInterface.lotsOfSpace() - self.userInterface.divider() - print(self.npc.introduce()) - self.userInterface.divider() - input(" [ CONTINUE ]") - self.currentPrompt.text = "What would you like to do?" + self.userInterface.showDialogue(self.npc.introduce()) diff --git a/src/location/tavern.py b/src/location/tavern.py index 9756f40..620240d 100644 --- a/src/location/tavern.py +++ b/src/location/tavern.py @@ -151,9 +151,4 @@ def changeBet(self, prompt): ) def talkToNPC(self): - self.userInterface.lotsOfSpace() - self.userInterface.divider() - print(self.npc.introduce()) - self.userInterface.divider() - input(" [ CONTINUE ]") - self.currentPrompt.text = "What would you like to do?" + self.userInterface.showDialogue(self.npc.introduce()) diff --git a/src/ui/userInterface.py b/src/ui/userInterface.py index 48e16f9..221bfb1 100644 --- a/src/ui/userInterface.py +++ b/src/ui/userInterface.py @@ -78,3 +78,11 @@ def showOptions( return choice self.currentPrompt.text = "Try again!" + + def showDialogue(self, text): + self.lotsOfSpace() + self.divider() + print(text) + self.divider() + input(" [ CONTINUE ]") + self.currentPrompt.text = "What would you like to do?" diff --git a/tests/location/test_bank.py b/tests/location/test_bank.py index 80db34f..c620339 100644 --- a/tests/location/test_bank.py +++ b/tests/location/test_bank.py @@ -120,10 +120,16 @@ def test_run_talk_to_npc_action(): def test_talkToNPC(): # prepare bankInstance = createBank() + bankInstance.userInterface.showDialogue = MagicMock() + + # call + bankInstance.talkToNPC() # check - assert bankInstance.npc.name == "Margaret the Teller" - assert len(bankInstance.npc.backstory) > 0 + bankInstance.userInterface.showDialogue.assert_called_once() + call_args = bankInstance.userInterface.showDialogue.call_args[0][0] + assert "Margaret the Teller" in call_args + assert len(call_args) > 0 def test_deposit_success(): diff --git a/tests/location/test_docks.py b/tests/location/test_docks.py index 6c6bfee..5bbdb07 100644 --- a/tests/location/test_docks.py +++ b/tests/location/test_docks.py @@ -74,10 +74,16 @@ def test_run_talk_to_npc_action(): def test_talkToNPC(): # prepare docksInstance = createDocks() + docksInstance.userInterface.showDialogue = MagicMock() + + # call + docksInstance.talkToNPC() # check - assert docksInstance.npc.name == "Sam the Dock Worker" - assert len(docksInstance.npc.backstory) > 0 + docksInstance.userInterface.showDialogue.assert_called_once() + call_args = docksInstance.userInterface.showDialogue.call_args[0][0] + assert "Sam the Dock Worker" in call_args + assert len(call_args) > 0 def test_run_go_to_shop_action(): diff --git a/tests/location/test_shop.py b/tests/location/test_shop.py index 12458d9..b8cddc0 100644 --- a/tests/location/test_shop.py +++ b/tests/location/test_shop.py @@ -88,14 +88,16 @@ def test_run_talk_to_npc_action(): def test_talkToNPC(): # prepare shopInstance = createShop() - shopInstance.userInterface.lotsOfSpace = MagicMock() - shopInstance.userInterface.divider = MagicMock() + shopInstance.userInterface.showDialogue = MagicMock() # call - # We can't fully test the input() part, but we can test the method exists - # and the NPC has the right data - assert shopInstance.npc.name == "Gilbert the Shopkeeper" - assert len(shopInstance.npc.backstory) > 0 + shopInstance.talkToNPC() + + # check + shopInstance.userInterface.showDialogue.assert_called_once() + call_args = shopInstance.userInterface.showDialogue.call_args[0][0] + assert "Gilbert the Shopkeeper" in call_args + assert len(call_args) > 0 def test_sellFish(): diff --git a/tests/location/test_tavern.py b/tests/location/test_tavern.py index 19d3c7e..d020937 100644 --- a/tests/location/test_tavern.py +++ b/tests/location/test_tavern.py @@ -105,10 +105,16 @@ def test_run_talk_to_npc_action(): def test_talkToNPC(): # prepare tavernInstance = createTavern() + tavernInstance.userInterface.showDialogue = MagicMock() + + # call + tavernInstance.talkToNPC() # check - assert tavernInstance.npc.name == "Old Tom the Barkeep" - assert len(tavernInstance.npc.backstory) > 0 + tavernInstance.userInterface.showDialogue.assert_called_once() + call_args = tavernInstance.userInterface.showDialogue.call_args[0][0] + assert "Old Tom the Barkeep" in call_args + assert len(call_args) > 0 def test_getDrunk(): diff --git a/tests/ui/test_userInterface.py b/tests/ui/test_userInterface.py index 65aaa6b..479c256 100644 --- a/tests/ui/test_userInterface.py +++ b/tests/ui/test_userInterface.py @@ -67,3 +67,22 @@ def test_showOptions(): userInterfaceInstance.lotsOfSpace.assert_called() assert userInterfaceInstance.divider.call_count == 3 userInterface.input.assert_called_with("\n> ") + + +def test_showDialogue(): + # setup + userInterfaceInstance = createUserInterface() + userInterface.print = MagicMock() + userInterface.input = MagicMock(return_value="") + userInterfaceInstance.lotsOfSpace = MagicMock() + userInterfaceInstance.divider = MagicMock() + + # call + userInterfaceInstance.showDialogue("Test dialogue text") + + # check + userInterfaceInstance.lotsOfSpace.assert_called_once() + assert userInterfaceInstance.divider.call_count == 2 + userInterface.print.assert_called_with("Test dialogue text") + userInterface.input.assert_called_with(" [ CONTINUE ]") + assert userInterfaceInstance.currentPrompt.text == "What would you like to do?"