From 58a991fe2788dee54413214c958a8db1ec372888 Mon Sep 17 00:00:00 2001 From: emily Date: Sun, 22 Jun 2025 17:29:52 +0200 Subject: [PATCH] Added approvals version of python test --- python/README.md | 12 +++++++- python/tests/__init__.py | 0 python/tests/approvaltests_config.json | 3 ++ ...ls.test_gilded_rose_approvals.approved.txt | 0 python/tests/conftest.py | 0 python/{ => tests}/test_gilded_rose.py | 0 python/tests/test_gilded_rose_approvals.py | 21 +++++++++++++ python/texttest_fixture.py | 30 +++++++++++-------- 8 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 python/tests/__init__.py create mode 100644 python/tests/approvaltests_config.json create mode 100644 python/tests/approved_files/test_gilded_rose_approvals.test_gilded_rose_approvals.approved.txt create mode 100644 python/tests/conftest.py rename python/{ => tests}/test_gilded_rose.py (100%) create mode 100644 python/tests/test_gilded_rose_approvals.py diff --git a/python/README.md b/python/README.md index 7504b97c..679ff3e1 100644 --- a/python/README.md +++ b/python/README.md @@ -7,7 +7,7 @@ Suggestion: create a python virtual environment for this project. See the [docum ## Run the unit tests from the Command-Line ``` -python test_gilded_rose.py +python tests/test_gilded_rose.py ``` ## Run the TextTest fixture from the Command-Line @@ -27,3 +27,13 @@ There are instructions in the [TextTest Readme](../texttests/README.md) for sett executable:${TEXTTEST_HOME}/python/texttest_fixture.py interpreter:python + +## Run the ApprovalTests.Python test + +This test uses the framework [ApprovalTests.Python](https://github.com/approvals/ApprovalTests.Python). Run it like this: + +``` +python tests/test_gilded_rose_approvals.py +``` + +You will need to approve the output file which appears under "approved_files" by renaming it from xxx.received.txt to xxx.approved.txt. diff --git a/python/tests/__init__.py b/python/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/python/tests/approvaltests_config.json b/python/tests/approvaltests_config.json new file mode 100644 index 00000000..550e6643 --- /dev/null +++ b/python/tests/approvaltests_config.json @@ -0,0 +1,3 @@ +{ + "subdirectory": "approved_files" +} diff --git a/python/tests/approved_files/test_gilded_rose_approvals.test_gilded_rose_approvals.approved.txt b/python/tests/approved_files/test_gilded_rose_approvals.test_gilded_rose_approvals.approved.txt new file mode 100644 index 00000000..e69de29b diff --git a/python/tests/conftest.py b/python/tests/conftest.py new file mode 100644 index 00000000..e69de29b diff --git a/python/test_gilded_rose.py b/python/tests/test_gilded_rose.py similarity index 100% rename from python/test_gilded_rose.py rename to python/tests/test_gilded_rose.py diff --git a/python/tests/test_gilded_rose_approvals.py b/python/tests/test_gilded_rose_approvals.py new file mode 100644 index 00000000..6c8f9db9 --- /dev/null +++ b/python/tests/test_gilded_rose_approvals.py @@ -0,0 +1,21 @@ +import io +import sys + +from approvaltests import verify +from texttest_fixture import main + +def test_gilded_rose_approvals(): + orig_sysout = sys.stdout + try: + fake_stdout = io.StringIO() + sys.stdout = fake_stdout + sys.argv = ["texttest_fixture.py", 30] + main() + answer = fake_stdout.getvalue() + finally: + sys.stdout = orig_sysout + + verify(answer) + +if __name__ == "__main__": + test_gilded_rose_approvals() \ No newline at end of file diff --git a/python/texttest_fixture.py b/python/texttest_fixture.py index 86af5ef7..8f7e4940 100644 --- a/python/texttest_fixture.py +++ b/python/texttest_fixture.py @@ -3,20 +3,20 @@ from __future__ import print_function from gilded_rose import * -if __name__ == "__main__": - print ("OMGHAI!") - items = [ - Item(name="+5 Dexterity Vest", sell_in=10, quality=20), - Item(name="Aged Brie", sell_in=2, quality=0), - Item(name="Elixir of the Mongoose", sell_in=5, quality=7), - Item(name="Sulfuras, Hand of Ragnaros", sell_in=0, quality=80), - Item(name="Sulfuras, Hand of Ragnaros", sell_in=-1, quality=80), - Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20), - Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=10, quality=49), - Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=5, quality=49), - Item(name="Conjured Mana Cake", sell_in=3, quality=6), # <-- :O - ] +def main(): + print("OMGHAI!") + items = [ + Item(name="+5 Dexterity Vest", sell_in=10, quality=20), + Item(name="Aged Brie", sell_in=2, quality=0), + Item(name="Elixir of the Mongoose", sell_in=5, quality=7), + Item(name="Sulfuras, Hand of Ragnaros", sell_in=0, quality=80), + Item(name="Sulfuras, Hand of Ragnaros", sell_in=-1, quality=80), + Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20), + Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=10, quality=49), + Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=5, quality=49), + Item(name="Conjured Mana Cake", sell_in=3, quality=6), # <-- :O + ] days = 2 import sys if len(sys.argv) > 1: @@ -28,3 +28,7 @@ if __name__ == "__main__": print(item) print("") GildedRose(items).update_quality() + + +if __name__ == "__main__": + main()