Skip to content

Commit 07c4446

Browse files
Merge pull request #28 from Axelrod-Python/issue-18
Add validation of original name and test
2 parents be6a99f + 75973d6 commit 07c4446

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/axelrod_fortran/player.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ def original_name(self):
4646

4747
@original_name.setter
4848
def original_name(self, value):
49-
# TODO Validate the value against list of known fortran functions
50-
self.__original_name = value
49+
if value in characteristics:
50+
self.__original_name = value
51+
else:
52+
raise ValueError(f'{value} is not a valid Fortran function')
5153

5254
@property
5355
def original_function(self):

tests/test_player.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ctypes import c_int, c_float, POINTER
77

88
import itertools
9+
import pytest
910

1011
C, D = Action.C, Action.D
1112

@@ -20,6 +21,8 @@ def test_init():
2021
POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int),
2122
POINTER(c_float))
2223
assert player.original_function.restype == c_int
24+
with pytest.raises(ValueError):
25+
player = Player('test')
2326

2427

2528
def test_matches():

0 commit comments

Comments
 (0)