Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
update unit test for circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Aug 26, 2017
1 parent 0436eb0 commit 4a6a5d9
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ jobs:
command: |
sudo apt-get install libav-tools
- run:
name: Install pygame
command: |
sudo apt-get install -y python-pygame
- run:
name: install dependencies 1
command: |
Expand Down
11 changes: 4 additions & 7 deletions _unittests/ut_dnotebooks/test_2A_notebook_eco.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
import os
import unittest
import warnings
import shutil

try:
Expand Down Expand Up @@ -54,9 +53,11 @@ def test_notebook_runner_2a_eco(self):
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
if is_travis_or_appveyor() == "appveyor":
# too long for appveyor

if is_travis_or_appveyor():
# Requires authentification.
return

from src.ensae_teaching_cs.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_1a
from src.ensae_teaching_cs.data import simple_database
temp = get_temp_folder(__file__, "temp_notebook2a_eco")
Expand All @@ -75,10 +76,6 @@ def filter(i, n):
return False
return True

if is_travis_or_appveyor() == "travis":
warnings.warn("execution does not stop")
return

execute_notebooks(temp, keepnote,
filter,
fLOG=fLOG,
Expand Down
3 changes: 2 additions & 1 deletion _unittests/ut_faq/test_faq_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def test_faq_cython_compile(self):
fname = os.path.join(temp, name)
fLOG(fname)
if not os.path.exists(fname):
raise FileNotFoundError(fname)
raise FileNotFoundError("Not found: '{0}'. Found:\n{1}".format(
fname, "\n".join(os.listdir(temp))))

sys.path.append(temp)
import primes
Expand Down
14 changes: 9 additions & 5 deletions _unittests/ut_helpers/test_pygame_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os
import unittest
import random
import warnings
from difflib import SequenceMatcher


Expand Down Expand Up @@ -66,9 +65,12 @@ def test_diff(self):
size = 500, 500
white = 255, 255, 255

if is_travis_or_appveyor() == "travis":
warnings.warn("pygame is not available")
if is_travis_or_appveyor() in ("travis",):
# pygame.error: No available video device
return
if is_travis_or_appveyor() == "circleci":
os.environ["SDL_VIDEODRIVER"] = "x11"

pygame, screen, fonts = get_pygame_screen_font(h, size)

from src.ensae_teaching_cs.helpers.pygame_helper import wait_event
Expand Down Expand Up @@ -116,9 +118,11 @@ def test_diff_full(self):
size = 500, 500
white = 255, 255, 255

if is_travis_or_appveyor() == "travis":
warnings.warn("pygame is not available")
if is_travis_or_appveyor() in ("travis",):
# pygame.error: No available video device
return
if is_travis_or_appveyor() == "circleci":
os.environ["SDL_VIDEODRIVER"] = "x11"

pygame, screen, fonts = get_pygame_screen_font(h, size)

Expand Down
13 changes: 7 additions & 6 deletions _unittests/ut_special/test_corde.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import sys
import unittest
import warnings


try:
Expand Down Expand Up @@ -50,23 +49,25 @@ def test_image_video_corde(self):
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_image_video_corde")

if is_travis_or_appveyor() == "travis":
warnings.warn("pygame is not available")
if is_travis_or_appveyor() in ("travis",):
# pygame.error: No available video device
return
if is_travis_or_appveyor() == "circleci":
os.environ["SDL_VIDEODRIVER"] = "x11"

import pygame
pygame_simulation(pygame, fLOG=fLOG,
iter=2000 if __name__ == "__main__" else 100,
folder=temp)
files = os.listdir(temp)
assert len(files) > 9
self.assertTrue(len(files) > 9)
png = [os.path.join(temp, _)
for _ in files if os.path.splitext(_)[-1] == ".png"]
assert len(png) > 0
self.assertTrue(len(png) > 0)
out = os.path.join(temp, "corde.avi")

v = make_video(png, out, size=(400, 300), format="XVID", fps=24)
assert v is not None
self.assertTrue(v is not None)


if __name__ == "__main__":
Expand Down
13 changes: 7 additions & 6 deletions _unittests/ut_special/test_propagation_epidemic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import sys
import unittest
import warnings


try:
Expand Down Expand Up @@ -59,21 +58,23 @@ def test_image_video_epidemic(self):
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_image_video_epidemic")

if is_travis_or_appveyor() == "travis":
warnings.warn("pygame is not available")
if is_travis_or_appveyor() in ("travis",):
# pygame.error: No available video device
return
if is_travis_or_appveyor() == "circleci":
os.environ["SDL_VIDEODRIVER"] = "x11"

import pygame
pygame_simulation(pygame, fLOG=fLOG, iter=10, folder=temp)
files = os.listdir(temp)
assert len(files) > 9
self.assertTrue(len(files) > 9)
png = [os.path.join(temp, _)
for _ in files if os.path.splitext(_)[-1] == ".png"]
assert len(png) > 0
self.assertTrue(len(png) > 0)
out = os.path.join(temp, "epidemic.avi")

v = make_video(png, out, size=(300, 300), format="XVID")
assert v is not None
self.assertTrue(v is not None)


if __name__ == "__main__":
Expand Down
11 changes: 6 additions & 5 deletions _unittests/ut_special/test_puzzle_girafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import os
import sys
import unittest
import warnings


try:
import src
Expand Down Expand Up @@ -52,7 +50,8 @@ def test_image_video_puzzle_girafe_resolution(self):
p = PuzzleGirafe()
p.solution()
res = str(p)
assert "1 : haut orange - bas bleu clair - bas bleu fonce - haut violet - orientation 0 numero 1" in res
self.assertIn(
"1 : haut orange - bas bleu clair - bas bleu fonce - haut violet - orientation 0 numero 1", res)

def test_image_video_puzzle_girafe(self):
fLOG(
Expand All @@ -61,9 +60,11 @@ def test_image_video_puzzle_girafe(self):
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_image_video_girafe")

if is_travis_or_appveyor() == "travis":
warnings.warn("pygame is not available")
if is_travis_or_appveyor() in ("travis",):
# pygame.error: No available video device
return
if is_travis_or_appveyor() == "circleci":
os.environ["SDL_VIDEODRIVER"] = "x11"

import pygame
pygame_simulation(pygame, fLOG=fLOG, folder=temp,
Expand Down
8 changes: 5 additions & 3 deletions _unittests/ut_special/test_tsp_kohonen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import sys
import unittest
import warnings


try:
Expand Down Expand Up @@ -49,9 +48,12 @@ def test_image_video_kohonen(self):
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_image_video_tsp_kohonen")
if is_travis_or_appveyor() == "travis":
warnings.warn("pygame is not available")

if is_travis_or_appveyor() in ("travis",):
# pygame.error: No available video device
return
if is_travis_or_appveyor() == "circleci":
os.environ["SDL_VIDEODRIVER"] = "x11"

import pygame
pygame_simulation(pygame, fLOG=fLOG, folder=temp,
Expand Down
7 changes: 4 additions & 3 deletions _unittests/ut_special/test_tsp_kruskal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import sys
import unittest
import warnings


try:
Expand Down Expand Up @@ -63,9 +62,11 @@ def test_kruskal_pygame_simulation(self):

temp = get_temp_folder(__file__, "temp_kruskal_pygame_simulation")

if is_travis_or_appveyor() == "travis":
warnings.warn("pygame is not available")
if is_travis_or_appveyor() in ("travis",):
# pygame.error: No available video device
return
if is_travis_or_appveyor() == "circleci":
os.environ["SDL_VIDEODRIVER"] = "x11"

import pygame
pygame.init()
Expand Down

0 comments on commit 4a6a5d9

Please sign in to comment.