Permalink
Browse files

try to fix an issue with python 3.6 (tkinter + pygame issue)

  • Loading branch information...
sdpython committed Jun 15, 2017
1 parent d095b6b commit 3c4d22acdd2072bb72bafad16568b5427179ff19
Showing with 94 additions and 45 deletions.
  1. +6 −45 _unittests/ut_algorithm/test_classroom.py
  2. +88 −0 _unittests/ut_algorithm/test_classroom36.py
@@ -40,7 +40,7 @@
from pyquickhelper.loghelper import fLOG, CustomLog
from pyquickhelper.pycode import get_temp_folder, fix_tkinter_issues_virtualenv
from src.code_beatrix.algorithm.data import load_prenoms_w
from src.code_beatrix.algorithm.classroom import random_positions, plot_positions, optimize_positions, find_best_positions_greedy, measure_positions
from src.code_beatrix.algorithm.classroom import random_positions, plot_positions, find_best_positions_greedy, measure_positions
class TestClassRoom(unittest.TestCase):
@@ -79,11 +79,11 @@ def test_random_position(self):
clog("plotting positions")
fLOG("plotting positions")
plot_positions(positions, ax=ax)
assert ax is not None
self.assertTrue(ax is not None)
clog("savefig")
img = os.path.join(temp, "img.png")
fig.savefig(img)
assert os.path.exists(img)
self.assertTrue(os.path.exists(img))
clog("noshow")
if __name__ == "__main__":
fig.show()
@@ -129,7 +129,7 @@ def test_find_greedy(self):
res = find_best_positions_greedy(positions, edges_dict, names[0])
d0 = measure_positions(positions, edges)
d0_ = measure_positions(positions, edges_dict)
assert abs(d0 - d0_) < 1e-5
self.assertTrue(abs(d0 - d0_) < 1e-5)
delta, pos = res[0]
rev = {v: k for k, v in positions.items()}
@@ -143,47 +143,8 @@ def test_find_greedy(self):
d1 = measure_positions(positions, edges)
fLOG("d1", d1)
assert c != positions
assert abs(d1 - d0 - delta) < 1e-5
def test_optimize_position(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
positions = random_positions(24)
names = list(name for name, x, y in positions)
names.sort()
edges = [(names[0], names[1]), (names[0], names[2]), (names[0], names[3]),
(names[3], names[4]), (names[3], names[5]), (names[0], names[6])]
if __name__ == "__main__":
temp = get_temp_folder(__file__, "temp_optimization")
new_positions, iter = optimize_positions(
positions, edges, fLOG=fLOG, max_iter=20, plot_folder=temp)
for i in iter:
fLOG(i)
positions = [(k, ) + v for k, v in new_positions.items()]
fix_tkinter_issues_virtualenv()
import matplotlib.pyplot as plt
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8, 8))
plot_positions(positions, edges=edges, ax=ax)
assert ax is not None
img = os.path.join(temp, "img.png")
fig.savefig(img)
assert os.path.exists(img)
if __name__ == "__main__":
fig.show()
plt.close('all')
fLOG("end")
else:
new_positions, iter = optimize_positions(
positions, edges, fLOG=fLOG, max_iter=20)
for i in iter:
fLOG(i)
assert iter
assert new_positions
self.assertTrue(c != positions)
self.assertTrue(abs(d1 - d0 - delta) < 1e-5)
if __name__ == "__main__":
@@ -0,0 +1,88 @@
#-*- coding: utf-8 -*-
"""
@brief test log(time=7s)
"""
import sys
import os
import unittest
try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src
try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, fix_tkinter_issues_virtualenv
from src.code_beatrix.algorithm.classroom import random_positions, plot_positions, optimize_positions
class TestClassRoom36(unittest.TestCase):
def test_optimize_position(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
positions = random_positions(24)
names = list(name for name, x, y in positions)
names.sort()
edges = [(names[0], names[1]), (names[0], names[2]), (names[0], names[3]),
(names[3], names[4]), (names[3], names[5]), (names[0], names[6])]
if __name__ == "__main__":
temp = get_temp_folder(__file__, "temp_optimization")
new_positions, iter = optimize_positions(
positions, edges, fLOG=fLOG, max_iter=20, plot_folder=temp)
for i in iter:
fLOG(i)
positions = [(k, ) + v for k, v in new_positions.items()]
fix_tkinter_issues_virtualenv()
import matplotlib.pyplot as plt
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8, 8))
plot_positions(positions, edges=edges, ax=ax)
self.assertTrue(ax is not None)
img = os.path.join(temp, "img.png")
fig.savefig(img)
self.assertTrue(os.path.exists(img))
if __name__ == "__main__":
fig.show()
plt.close('all')
fLOG("end")
else:
new_positions, iter = optimize_positions(
positions, edges, fLOG=fLOG, max_iter=20)
for i in iter:
fLOG(i)
self.assertTrue(iter is not None)
self.assertTrue(new_positions is not None)
if __name__ == "__main__":
unittest.main()

0 comments on commit 3c4d22a

Please sign in to comment.