77import yaml
88
99import axelrod as axl
10- from axelrod .classifier import Classifier , Classifiers , rebuild_classifier_table
10+ from axelrod .classifier import (
11+ Classifier ,
12+ Classifiers ,
13+ _Classifiers ,
14+ memory_depth ,
15+ rebuild_classifier_table ,
16+ )
17+ from axelrod .player import Player
18+
19+
20+ class TestTitForTat (Player ):
21+ """
22+ Same name as TitForTat, but with empty classifier.
23+ """
24+
25+ # Classifiers are looked up by name, so only the name matters.
26+ name = "Tit For Tat"
27+ classifier = {}
1128
1229
1330class TestClassification (unittest .TestCase ):
@@ -33,11 +50,23 @@ def test_classifier_build(self):
3350 )
3451
3552 def test_singletonity_of_classifiers_class (self ):
36- classifiers_1 = Classifiers
37- classifiers_2 = Classifiers
53+ classifiers_1 = _Classifiers ()
54+ classifiers_2 = _Classifiers ()
3855
3956 self .assertIs (classifiers_1 , classifiers_2 )
4057
58+ def test_get_name_from_classifier (self ):
59+ # Should be able to take a string or a Classifier instance.
60+ self .assertEqual (Classifiers ["memory_depth" ](axl .TitForTat ), 1 )
61+ self .assertEqual (Classifiers [memory_depth ](axl .TitForTat ), 1 )
62+
63+ def test_key_error_on_uknown_classifier (self ):
64+ with self .assertRaises (KeyError ):
65+ Classifiers ["invalid_key" ](axl .TitForTat )
66+
67+ def test_will_lookup_key_in_dict (self ):
68+ self .assertEqual (Classifiers ["memory_depth" ](TestTitForTat ), 1 )
69+
4170 def test_known_classifiers (self ):
4271 # A set of dimensions that are known to have been fully applied
4372 known_keys = [
0 commit comments