From 389e9fe700911138a6622f554ffdf98ff4164c2e Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Thu, 16 Aug 2018 08:02:21 +0100 Subject: [PATCH 1/6] Fix the order of imports. I have also added some comments to ensure we do not reorder these imports. --- axelrod/tests/unit/test_plot.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/axelrod/tests/unit/test_plot.py b/axelrod/tests/unit/test_plot.py index 4e9f114d4..e42dad659 100644 --- a/axelrod/tests/unit/test_plot.py +++ b/axelrod/tests/unit/test_plot.py @@ -1,13 +1,18 @@ +import tempfile import unittest -import axelrod +import matplotlib # isort: skip +matplotlib.use("agg") # This line need to be before `import axelrod` and + # `import matplotlib.pyplot` for CI to work consistently + # See + # /~https://github.com/Axelrod-Python/Axelrod/issues/1187 + +import matplotlib.pyplot as plt from numpy import mean -import tempfile -import matplotlib -matplotlib.use("agg") +import axelrod + -import matplotlib.pyplot as plt class TestPlot(unittest.TestCase): From d75f79515afcdbecd4befb28a96bda7da6ed0195 Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Thu, 16 Aug 2018 08:58:54 +0100 Subject: [PATCH 2/6] Add remaining files. --- axelrod/tests/unit/test_fingerprint.py | 7 +++++++ axelrod/tests/unit/test_moran.py | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/axelrod/tests/unit/test_fingerprint.py b/axelrod/tests/unit/test_fingerprint.py index 7bd31faf7..e67492642 100644 --- a/axelrod/tests/unit/test_fingerprint.py +++ b/axelrod/tests/unit/test_fingerprint.py @@ -4,6 +4,13 @@ from unittest.mock import patch import numpy as np + +import matplotlib # isort: skip +matplotlib.use("agg") # This line need to be before `import axelrod` and + # `import matplotlib.pyplot` for CI to work consistently + # See + # /~https://github.com/Axelrod-Python/Axelrod/issues/1187 + import matplotlib.pyplot from hypothesis import given, settings diff --git a/axelrod/tests/unit/test_moran.py b/axelrod/tests/unit/test_moran.py index 3d0660978..7cb87c5cc 100644 --- a/axelrod/tests/unit/test_moran.py +++ b/axelrod/tests/unit/test_moran.py @@ -4,7 +4,13 @@ import unittest from hypothesis import given, example, settings -import matplotlib + +import matplotlib # isort: skip +matplotlib.use("agg") # This line need to be before `import axelrod` and + # `import matplotlib.pyplot` for CI to work consistently + # See + # /~https://github.com/Axelrod-Python/Axelrod/issues/1187 + import matplotlib.pyplot as plt import axelrod From c1b3f27090fde6361d313ecadabb6655621e7031 Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Thu, 16 Aug 2018 09:45:31 +0100 Subject: [PATCH 3/6] Add a matplotlibrc file to set the backend. --- axelrod/tests/unit/test_fingerprint.py | 6 ------ axelrod/tests/unit/test_moran.py | 6 ------ axelrod/tests/unit/test_plot.py | 9 --------- doctests.py | 3 --- matplotlibrc | 1 + 5 files changed, 1 insertion(+), 24 deletions(-) create mode 100644 matplotlibrc diff --git a/axelrod/tests/unit/test_fingerprint.py b/axelrod/tests/unit/test_fingerprint.py index e67492642..c2c447062 100644 --- a/axelrod/tests/unit/test_fingerprint.py +++ b/axelrod/tests/unit/test_fingerprint.py @@ -5,12 +5,6 @@ import numpy as np -import matplotlib # isort: skip -matplotlib.use("agg") # This line need to be before `import axelrod` and - # `import matplotlib.pyplot` for CI to work consistently - # See - # /~https://github.com/Axelrod-Python/Axelrod/issues/1187 - import matplotlib.pyplot from hypothesis import given, settings diff --git a/axelrod/tests/unit/test_moran.py b/axelrod/tests/unit/test_moran.py index 7cb87c5cc..c50571878 100644 --- a/axelrod/tests/unit/test_moran.py +++ b/axelrod/tests/unit/test_moran.py @@ -5,12 +5,6 @@ from hypothesis import given, example, settings -import matplotlib # isort: skip -matplotlib.use("agg") # This line need to be before `import axelrod` and - # `import matplotlib.pyplot` for CI to work consistently - # See - # /~https://github.com/Axelrod-Python/Axelrod/issues/1187 - import matplotlib.pyplot as plt import axelrod diff --git a/axelrod/tests/unit/test_plot.py b/axelrod/tests/unit/test_plot.py index e42dad659..f55cff21b 100644 --- a/axelrod/tests/unit/test_plot.py +++ b/axelrod/tests/unit/test_plot.py @@ -1,20 +1,11 @@ import tempfile import unittest -import matplotlib # isort: skip -matplotlib.use("agg") # This line need to be before `import axelrod` and - # `import matplotlib.pyplot` for CI to work consistently - # See - # /~https://github.com/Axelrod-Python/Axelrod/issues/1187 - import matplotlib.pyplot as plt from numpy import mean import axelrod - - - class TestPlot(unittest.TestCase): @classmethod diff --git a/doctests.py b/doctests.py index a7dd13169..6a466c1d9 100644 --- a/doctests.py +++ b/doctests.py @@ -3,9 +3,6 @@ import unittest import warnings -import matplotlib -matplotlib.use("agg") - # Note loader and ignore are required arguments for unittest even if unused. def load_tests(loader, tests, ignore): diff --git a/matplotlibrc b/matplotlibrc new file mode 100644 index 000000000..13468274c --- /dev/null +++ b/matplotlibrc @@ -0,0 +1 @@ +backend : Agg From e877c5b671361d1bc1f2f95039c81727b05982a4 Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Thu, 16 Aug 2018 09:51:42 +0100 Subject: [PATCH 4/6] Check that the backend is being set correctly. --- axelrod/tests/unit/test_plot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/axelrod/tests/unit/test_plot.py b/axelrod/tests/unit/test_plot.py index f55cff21b..f91c800a2 100644 --- a/axelrod/tests/unit/test_plot.py +++ b/axelrod/tests/unit/test_plot.py @@ -6,6 +6,11 @@ import axelrod +import matplotlib + +# TODO Remove this +assert matplotlib.get_backend() == "agg" + class TestPlot(unittest.TestCase): @classmethod From 3372922c66a1690afa1144d2145651b3ace5c205 Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Thu, 16 Aug 2018 13:39:49 +0100 Subject: [PATCH 5/6] Remove backend check. --- axelrod/tests/unit/test_plot.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/axelrod/tests/unit/test_plot.py b/axelrod/tests/unit/test_plot.py index f91c800a2..6f9f22263 100644 --- a/axelrod/tests/unit/test_plot.py +++ b/axelrod/tests/unit/test_plot.py @@ -8,9 +8,6 @@ import matplotlib -# TODO Remove this -assert matplotlib.get_backend() == "agg" - class TestPlot(unittest.TestCase): @classmethod From f3f06f304d924b2eee140de1fd6f066618ab710e Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Thu, 16 Aug 2018 15:58:20 +0100 Subject: [PATCH 6/6] isort test_plot.py and add a comment to mplrc --- axelrod/tests/unit/test_plot.py | 2 +- matplotlibrc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/axelrod/tests/unit/test_plot.py b/axelrod/tests/unit/test_plot.py index 6f9f22263..3dc091361 100644 --- a/axelrod/tests/unit/test_plot.py +++ b/axelrod/tests/unit/test_plot.py @@ -1,12 +1,12 @@ import tempfile import unittest +import matplotlib import matplotlib.pyplot as plt from numpy import mean import axelrod -import matplotlib class TestPlot(unittest.TestCase): diff --git a/matplotlibrc b/matplotlibrc index 13468274c..f068e8f37 100644 --- a/matplotlibrc +++ b/matplotlibrc @@ -1 +1,3 @@ +# This is to ensure the matplotlib backend is set appropriately for CI +# See /~https://github.com/Axelrod-Python/Axelrod/issues/1187 backend : Agg