Skip to content

Conversation

cjgwang
Copy link

@cjgwang cjgwang commented Sep 14, 2025

Was unable to run python rebuild_classifier_table.py due to network issues, but the rest should be correct. I created adaptive_cooperator.py, test_adaptive_cooperator.py, made changes to the doctest, references, and _strategy.py.

@drvinceknight
Copy link
Member

So the build is failing because:

  ____ ERROR collecting axelrod/tests/strategies/test_adaptive_cooperator.py _____
  ImportError while importing test module '/Users/runner/work/Axelrod/Axelrod/axelrod/tests/strategies/test_adaptive_cooperator.py'.
  Hint: make sure your test modules/packages have valid Python names.
  Traceback:
  /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py:126: in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  axelrod/tests/strategies/test_adaptive_cooperator.py:2: in <module>
      from test_player import TestPlayer
  E   ModuleNotFoundError: No module named 'test_player'

I see that what you have written follows the documentation perfectly but that looks to be out of date (this is a documentation bug). If you take a look at a similar test file for example here you'll see that in fact the import needs to be:

from .test_player import TestPlayer

If you fix that and push it hopefully that fixes the error.

@cjgwang
Copy link
Author

cjgwang commented Sep 16, 2025

Just fixed the TestPlayer class and pushed again - checks still failed. I think this has to do with the classifier, since test_adaptive_coordinator.py was unable to initialise.

Copy link
Member

@drvinceknight drvinceknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it looks like you used an incorrect classification key.

@cjgwang
Copy link
Author

cjgwang commented Sep 25, 2025

I tried again and it doesn't seem to work. It looks like the test is failing because of test coverage, but when I added some more tests, it still fails!

@drvinceknight
Copy link
Member

You're right, it's coverage but there are also some tests that are failing.

Coverage

From the log:

  axelrod/strategies/adaptive.py                                      27      0   100%
  axelrod/strategies/adaptive_cooperator.py                 37      1    97%   53
  axelrod/strategies/adaptor.py                                       30      0   100%
  axelrod/strategies/alternator.py                                    12      0   100%

Line 53 is not being hit when running the tests:

       elif self.is_tft:
            if not opponent.history or len(self.history) == 0:
                return C

That implies that we don't have a test which checks this specific set of conditions.

Test failures

There are some remaining tests that are not passing.

One of them is for example:

 ___________ TestAdaptiveCooperator.test_reset_history_and_attributes ___________
  
  self = <axelrod.tests.strategies.test_adaptive_cooperator.TestAdaptiveCooperator testMethod=test_reset_history_and_attributes>
  
      def test_reset_history_and_attributes(self):
          """Make sure resetting works correctly."""
          for opponent in [
              axl.Defector(),
              axl.Random(),
              axl.Alternator(),
              axl.Cooperator(),
          ]:
              player = self.player()
              clone = player.clone()
              match = axl.Match((player, opponent), turns=10, seed=111)
              match.play()
              player.reset()
  >           self.assertEqual(player, clone)
  E           AssertionError: Adaptive Cooperator != Adaptive Cooperator

I believe this is because you have not reset all the attributes in the rest method:

  def reset(self):
        super().__init__()
        self.is_defect = False
        self.is_tft = False

should be:

  def reset(self):
        self.is_tft = False
        self.is_defect = False
        self.current_score = 0
        self.opponent_score = 0

although I think that you could remove the method completely and it will use the parent class reset which will call the init method itself.

There are a few other failures that are in the doctests but also some more in the unit tests that I'd need to look at a bit more closely.

You might find running the tests locally helpful so that you can iterate this a bit more quickly. There is some information on doing that here: https://axelrod.readthedocs.io/en/stable/how-to/contributing/running_tests.html

For example to just run the test file for your strategy you could run:

python -m pytest axelrod/tests/strategies/test_adaptive_cooperator.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants