ok, ok. It's time to start testing this thing;git push
This commit is contained in:
parent
6c0254f664
commit
217c4e32f8
@ -2,15 +2,31 @@ import random
|
||||
from app.functions.get_character_age import get_age
|
||||
|
||||
|
||||
def get_sex():
|
||||
return random.choice(['male', 'female'])
|
||||
|
||||
|
||||
def get_hair():
|
||||
return random.choice(['black', 'brown', 'auburn', 'blonde', 'copper', 'brass', 'blue', 'bald'])
|
||||
|
||||
|
||||
def get_eyes():
|
||||
return random.choice(['blue', 'brown', 'green', 'hazel', 'gray'])
|
||||
|
||||
|
||||
def get_skin_tone():
|
||||
return random.choice(['dark', 'olive', 'medium', 'light', 'pale'])
|
||||
|
||||
|
||||
def generate_profile(chartype):
|
||||
profile = {
|
||||
'name': "Anon",
|
||||
'sex': random.choice(['male', 'female', 'male', 'female', 'male', 'female']),
|
||||
'sex': get_sex(),
|
||||
'age': get_age(chartype)
|
||||
}
|
||||
if chartype == 'human':
|
||||
profile['hair'] = random.choice(['black', 'brown', 'auburn', 'blonde', 'copper', 'brass', 'blue', 'bald'])
|
||||
profile['eyes'] = random.choice(['blue', 'brown', 'green', 'hazel', 'gray'])
|
||||
profile['skintone'] = random.choice(['dark', 'olive', 'medium', 'light', 'pale'])
|
||||
profile['hair'] = get_hair()
|
||||
profile['eyes'] = get_eyes()
|
||||
profile['skintone'] = get_skin_tone()
|
||||
|
||||
return profile
|
||||
|
@ -4,3 +4,5 @@ marshmallow~=3.21.3
|
||||
pandas~=2.2.2
|
||||
flask-cors~=4.0.1
|
||||
numpy~=2.0.0
|
||||
pytest~=8.2.2
|
||||
coverage~=7.5.4
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
30
tests/test_generate_profile.py
Normal file
30
tests/test_generate_profile.py
Normal file
@ -0,0 +1,30 @@
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
from app.functions.generate_profile import generate_profile
|
||||
|
||||
|
||||
@patch('app.functions.generate_profile.get_sex', return_value='male')
|
||||
@patch('app.functions.generate_profile.get_age', return_value=30)
|
||||
@patch('app.functions.generate_profile.get_hair', return_value='black')
|
||||
@patch('app.functions.generate_profile.get_eyes', return_value='blue')
|
||||
@patch('app.functions.generate_profile.get_skin_tone', return_value='dark')
|
||||
@pytest.mark.parametrize("chartype", ["human", "humanoid", "mutant", "cyborg"])
|
||||
def test_generate_profile(
|
||||
mock_get_skin_tone, mock_get_eyes, mock_get_hair, mock_get_age, mock_get_sex, chartype):
|
||||
profile = generate_profile(chartype)
|
||||
|
||||
# Assertions common to all character types
|
||||
assert profile["name"] == 'Anon'
|
||||
assert profile["sex"] == 'male'
|
||||
assert profile["age"] == 30
|
||||
|
||||
# Additional assertions for 'human' character type
|
||||
if chartype == 'human':
|
||||
assert profile["hair"] == 'black'
|
||||
assert profile["eyes"] == 'blue'
|
||||
assert profile["skintone"] == 'dark'
|
||||
else:
|
||||
# 'hair', 'eyes' and 'skintone' should not exist for non-human types
|
||||
assert "hair" not in profile
|
||||
assert "eyes" not in profile
|
||||
assert "skintone" not in profile
|
24
tests/test_get_score_list.py
Normal file
24
tests/test_get_score_list.py
Normal file
@ -0,0 +1,24 @@
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
from app.functions.get_score_list import get_score_list
|
||||
|
||||
|
||||
@patch('app.functions.get_score_list.roll_dices')
|
||||
def test_get_score_list(mock_roll_dices):
|
||||
# Setup the mock to return a specific value
|
||||
mock_roll_dices.return_value = {'result': 50}
|
||||
|
||||
# Test that the modifier is applied correctly when the roll value is less than 100 after applying modifier
|
||||
scores = get_score_list(4, 10)
|
||||
assert scores == [60, 60, 60, 60]
|
||||
|
||||
# Test that the score is capped at 100
|
||||
scores = get_score_list(4, 60)
|
||||
assert scores == [100, 100, 100, 100]
|
||||
|
||||
# Test that the duplicates are handled You may need to setup some specific behavior on your mock object. Here we
|
||||
# are making it return 50 on the first call, and 60 on any subsequent calls. This simulates a scenario where
|
||||
# get_score_list may returns duplicate value
|
||||
mock_roll_dices.side_effect = [{'result': 50}, {'result': 60}]
|
||||
scores = get_score_list(2, 10)
|
||||
assert scores == [60, 70]
|
38
tests/test_roll_dices.py
Normal file
38
tests/test_roll_dices.py
Normal file
@ -0,0 +1,38 @@
|
||||
import pytest
|
||||
from app.functions.roll_dices import roll_dices
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
@patch('random.randint')
|
||||
def test_roll_dices_no_discard(mock_randint):
|
||||
# mocks
|
||||
mock_randint.return_value = 4
|
||||
|
||||
# Test with discard_lowest = False
|
||||
result = roll_dices(4, 6, False)
|
||||
assert 'dice-set' in result
|
||||
assert 'rolls' in result
|
||||
assert 'result' in result
|
||||
assert len(result['rolls']) == 4
|
||||
assert 'discarded' not in result
|
||||
|
||||
mnemonic = result['dice-set']['mnemonic']
|
||||
assert mnemonic == '4d6'
|
||||
|
||||
|
||||
@patch('random.randint')
|
||||
def test_roll_dices_with_discard(mock_randint):
|
||||
# mocks
|
||||
mock_randint.return_value = 4
|
||||
|
||||
# Test with discard_lowest = True
|
||||
result = roll_dices(4, 6, True)
|
||||
assert 'dice-set' in result
|
||||
assert 'rolls' in result
|
||||
assert 'result' in result
|
||||
assert len(result['rolls']) == 3
|
||||
assert 'discarded' in result
|
||||
assert len(result['discarded']) == 1
|
||||
|
||||
mnemonic = result['dice-set']['mnemonic']
|
||||
assert mnemonic == '4(-1)d6'
|
Loading…
Reference in New Issue
Block a user