File: test_constants.py

package info (click to toggle)
python-xmlsec 1.3.14-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 656 kB
  • sloc: ansic: 4,118; python: 2,045; xml: 461; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 1,497 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
37
38
39
40
41
42
"""Test constants from :mod:`xmlsec.constants` module."""

import pytest

import xmlsec


def _constants(typename):
    return list(
        sorted(
            (
                getattr(xmlsec.constants, name)
                for name in dir(xmlsec.constants)
                if type(getattr(xmlsec.constants, name)).__name__ == typename
            ),
            key=lambda t: t.name.lower(),
        )
    )


@pytest.mark.parametrize('transform', _constants('__Transform'), ids=repr)
def test_transform_str(transform):
    """Test string representation of ``xmlsec.constants.__Transform``."""
    assert str(transform) == '{}, {}'.format(transform.name, transform.href)


@pytest.mark.parametrize('transform', _constants('__Transform'), ids=repr)
def test_transform_repr(transform):
    """Test raw string representation of ``xmlsec.constants.__Transform``."""
    assert repr(transform) == '__Transform({!r}, {!r}, {})'.format(transform.name, transform.href, transform.usage)


@pytest.mark.parametrize('keydata', _constants('__KeyData'), ids=repr)
def test_keydata_str(keydata):
    """Test string representation of ``xmlsec.constants.__KeyData``."""
    assert str(keydata) == '{}, {}'.format(keydata.name, keydata.href)


@pytest.mark.parametrize('keydata', _constants('__KeyData'), ids=repr)
def test_keydata_repr(keydata):
    """Test raw string representation of ``xmlsec.constants.__KeyData``."""
    assert repr(keydata) == '__KeyData({!r}, {!r})'.format(keydata.name, keydata.href)