File: test_mainwindow.py

package info (click to toggle)
pyacidobasic 3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,388 kB
  • sloc: python: 1,569; xml: 71; makefile: 60; sh: 7
file content (36 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from unittest import TestCase
import numpy as np
import os, PIL.Image

class MonTest(TestCase):

    def test_colors_bleu_bromophenol(self):
        pngFile=os.path.join(
            'pyacidobasic', 'icons', 'bleu-bromophenol.svg.png')
        img=PIL.Image.open(pngFile)
        imgArray=np.frombuffer(img.tobytes(), dtype=np.uint8)
        imgArray=imgArray.reshape((img.size[1], img.size[0], 4))
        # à bas pH, le bleu de bromophenol est jaune
        self.assertTrue(np.array_equal(
            imgArray[44][55][:3], np.array([255, 255, 0])))
        # à pH élevé, le bleu de bromophenol est mauve
        self.assertTrue(np.array_equal(
            imgArray[44][550][:3], np.array([103, 0, 152])))
        return

    def test_ones(self):
        # numpy produit des "uns" facilement
        self.assertTrue(np.array_equal(
            np.ones(2), np.array([1,1])))
        return

    def test_varColor(self):
        r=np.sin(1*np.pi/2)
        v=np.sin(1*np.pi/3)
        b=np.sin(1*np.pi/5)
        self.assertAlmostEqual(r, 1)
        self.assertAlmostEqual(v, 0.86602540378)
        self.assertAlmostEqual(b, 0.58778525229)
        return