Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Release 1.19.1

See merge request Scientific-IT-Systems/python-gr!208
  • Loading branch information
IngoMeyer441 committed Mar 4, 2022
2 parents 3ba2a3a + 9951bbd commit b0e110e
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 140 deletions.
1 change: 1 addition & 0 deletions gr/matplotlib/backend_gr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class RendererGR(RendererBase):
texd = maxdict(50) # a cache of tex image rasters

def __init__(self, dpi, width, height):
super(RendererGR, self).__init__()
self.dpi = dpi
if __version__[0] >= '2':
self.nominal_fontsize = 0.001625
Expand Down
116 changes: 0 additions & 116 deletions tests/gr/__init__.py

This file was deleted.

49 changes: 28 additions & 21 deletions tests/gr/compare_test.py → tests/gr/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,61 @@
import shutil
import platform

from nose import with_setup
import pytest

from gr_test import CompareResult
from gr_test import python_image as image_data
from gr_test import python_video as video_data
from gr_test.entry_points import safe_mkdir
base_path = os.path.abspath(os.path.dirname(os.path.realpath(__name__)) + '/../../test_result/')

if 'GR_TEST_BASE_PATH' in os.environ:
base_path = os.path.abspath(os.environ['GR_TEST_BASE_PATH'])

results_path = os.path.abspath(base_path + '/' + platform.python_version())
@pytest.fixture(scope='session')
def base_dir():
base_path = os.path.abspath(os.path.dirname(os.path.realpath(__name__)) + '/../../test_result/')

if 'GR_TEST_BASE_PATH' in os.environ:
base_path = os.path.abspath(os.environ['GR_TEST_BASE_PATH'])

def setup_func():
try:
os.mkdir(base_path)
except OSError:
pass
return base_path


@pytest.fixture(scope='session')
def results_dir(base_dir):
results_path = os.path.abspath(base_dir + '/' + platform.python_version())

try:
os.mkdir(results_path)
except OSError:
pass
return results_path

@with_setup(setup_func)
def test_images():

def test_images(results_dir):
image_data.create_files('TEST')
consistency, pairs = image_data.get_test_data()
for x in consistency:
yield succeed_if_none, x
for dir, ext, ref_name, test_name, base_name in pairs:
yield compare, dir, ext, ref_name, test_name, base_name
assert x is None
for dir, _, ref_name, test_name, base_name in pairs:
compare(dir, ref_name, test_name, base_name, results_dir)


@with_setup(setup_func)
def test_video():
def test_video(results_dir):
video_data.create_files('TEST')
consistency, pairs = video_data.get_test_data()
for x in consistency:
yield succeed_if_none, x
for dir, ext, ref_name, test_name, base_name in pairs:
yield compare, dir, ext, ref_name, test_name, base_name
assert x is None
for dir, _, ref_name, test_name, base_name in pairs:
compare(dir, ref_name, test_name, base_name, results_dir)

def succeed_if_none(x):
assert x is None

def compare(dir, ext, ref_name, test_name, base_name):
this_path = os.path.join(results_path, dir)
file_name = os.path.basename(test_name) # f.e. REFERENCE.pdf.png or frame-1.mov.png
def compare(dir, ref_name, test_name, base_name, results_dir):
this_path = os.path.join(results_dir, dir)
# e.g. REFERENCE.pdf.png or frame-1.mov.png
file_name = os.path.basename(test_name)

result = CompareResult(ref_name, test_name)

Expand Down
117 changes: 117 additions & 0 deletions tests/gr/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# -*- coding: utf-8 -*-

# standard library

# third party

# local library
import gr
from gr.pygr import Coords2DList, Coords2D, Coords3DList, Coords3D


def test_char():
gr.char("t")
gr.char(u"t")


def test_coords2DList_minmax():
a = Coords2D([10, 20, 30], [10, 20, 30])
coords = Coords2DList([a])
assert coords.xmin == 10
assert coords.xmax == 30
assert coords.ymin == 10
assert coords.ymax == 30

coords.append(Coords2D([5, 10], [20, 40]))
assert coords.xmin == 5
assert coords.xmax == 30
assert coords.ymin == 10
assert coords.ymax == 40

b = Coords2D([1, 2, 3], [1, 2, 3])
coords += [b]
assert coords.xmin == 1
assert coords.xmax == 30
assert coords.ymin == 1
assert coords.ymax == 40

tmp = coords.pop(coords.index(b))
assert tmp == b
assert coords.xmin == 5
assert coords.xmax == 30
assert coords.ymin == 10
assert coords.ymax == 40

coords.extend([b])
assert coords.xmin == 1
assert coords.xmax == 30
assert coords.ymin == 1
assert coords.ymax == 40

coords.remove(b)
assert coords.xmin == 5
assert coords.xmax == 30
assert coords.ymin == 10
assert coords.ymax == 40

coords.append(Coords2D([10, 10], [0, 0]))
assert coords.xmin == 5
assert coords.xmax == 30
assert coords.ymin == 0
assert coords.ymax == 40

coords.append(Coords2D([10, 10], [200, 400]))
assert coords.xmin == 5
assert coords.xmax == 30
assert coords.ymin == 0
assert coords.ymax == 400


def test_coords2DList_empty():
a = Coords2D([10, 20, 30], [10, 20, 30])
coords = Coords2DList([a])
coords.remove(a)
assert coords.xmin is None
assert coords.xmax is None
assert coords.ymin is None
assert coords.ymax is None


def test_coords2DList_update():
a = Coords2D([10, 20, 30], [10, 20, 30])
b = Coords2D([5], [40])
coords = Coords2DList([a, b])
assert coords.xmin == 5
assert coords.xmax == 30
assert coords.ymin == 10
assert coords.ymax == 40

b.x = [15]
b.y = [25]
coords.updateMinMax(b)
assert coords.xmin == 5
assert coords.xmax == 30
assert coords.ymin == 10
assert coords.ymax == 40

coords.updateMinMax(*coords, reset=True)
assert coords.xmin == 10
assert coords.xmax == 30
assert coords.ymin == 10
assert coords.ymax == 30

coords.updateMinMax(b, reset=True)
assert coords.xmin == 15
assert coords.xmax == 15
assert coords.ymin == 25
assert coords.ymax == 25


def test_coords3DList_minmax():
coords = Coords3DList([Coords3D([1, 2], [1, 2], [-42, 42])])
assert coords.xmin == 1
assert coords.xmax == 2
assert coords.ymin == 1
assert coords.ymax == 2
assert coords.zmin == -42
assert coords.zmax == 42
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tox]
envlist = py27,py36,py37,py38,py39
envlist = py27,py37,py38,py39,py310
skipsdist = True
[testenv]
passenv = GR_TEST_BASE_PATH
deps =
nose
pytest
/gr-test/
commands = python -c "import subprocess, glob; subprocess.check_call(['pip', 'install', glob.glob('dist/gr-*.tar.gz')[0]])"
nosetests tests/gr
pytest tests

0 comments on commit b0e110e

Please sign in to comment.