Added approvals version of python test

This commit is contained in:
emily 2025-06-22 17:29:52 +02:00
parent 69245fd714
commit 58a991fe27
8 changed files with 52 additions and 14 deletions

View File

@ -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.

0
python/tests/__init__.py Normal file
View File

View File

@ -0,0 +1,3 @@
{
"subdirectory": "approved_files"
}

0
python/tests/conftest.py Normal file
View File

View File

@ -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()

View File

@ -3,8 +3,9 @@ from __future__ import print_function
from gilded_rose import *
if __name__ == "__main__":
print ("OMGHAI!")
def main():
print("OMGHAI!")
items = [
Item(name="+5 Dexterity Vest", sell_in=10, quality=20),
Item(name="Aged Brie", sell_in=2, quality=0),
@ -16,7 +17,6 @@ if __name__ == "__main__":
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()