Projet

Général

Profil

0002-tests-use-tabulate-to-compare-tables-38067.patch

Benjamin Dauvergne, 03 décembre 2019 13:53

Télécharger (1,87 ko)

Voir les différences:

Subject: [PATCH 02/13] tests: use tabulate to compare tables (#38067)

Comparing strings with assert gives better diffs thant comparing list of
lists when using the pytest's `-vv` option.
 tests/test_schema2.py | 15 ++++++++++++++-
 tox.ini               |  1 +
 2 files changed, 15 insertions(+), 1 deletion(-)
tests/test_schema2.py
1 1
import json
2 2
import os
3
import re
3 4

  
4 5
import pytest
6
from tabulate import tabulate
5 7

  
6 8
from utils import login, get_table
7 9

  
......
20 22
            metafunc.parametrize(['visualization'], [[x] for x in tables])
21 23

  
22 24

  
25
def assert_equal_tables(table1, table2):
26
    t1 = tabulate(table1)
27
    t2 = tabulate(table2)
28
    t1 = re.sub(' +', ' ', t1)
29
    t2 = re.sub(' +', ' ', t2)
30
    assert t1 == t2
31

  
32

  
23 33
@pytest.fixture(autouse=True)
24 34
def freezetime(freezer):
25 35
    freezer.move_to('2018-12-07 16:53:00')
......
31 41

  
32 42
    visualization_page = response.click(lambda x: x == visualization)
33 43
    assert 'big-msg-info' not in visualization_page
34
    assert schema2['tables'][visualization] == get_table(visualization_page)
44
    table = get_table(visualization_page)
45
    assert_equal_tables(
46
        schema2['tables'][visualization],
47
        table)
tox.ini
24 24
	WebTest
25 25
	django-webtest<1.9.3
26 26
	pyquery
27
	tabulate
27 28
commands =
28 29
        dj111: py.test {posargs: --junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=bijoe tests/}
29 30
[pytest]
30
-