File: test_strings.py

package info (click to toggle)
python-typechecks 0.1.0%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 112 kB
  • sloc: python: 133; makefile: 7
file content (25 lines) | stat: -rw-r--r-- 744 bytes parent folder | download
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
 # coding=utf-8
import pytest
from typechecks import is_string, require_string

def test_is_string():
    assert is_string("hello")
    assert is_string("")
    assert is_string(u"Ѽ")
    assert is_string(u"ﮚ")
    assert not is_string(1)
    assert not is_string(1.0)
    assert not is_string([])
    assert not is_string(object())
    assert not is_string(None)

def test_require_string():
    require_string("", nonempty=False)
    with pytest.raises(TypeError):
        require_string(0, nonempty=False)
    with pytest.raises(TypeError):
        require_string(0, nonempty=True)
    with pytest.raises(ValueError):
        require_string("", nonempty=True)
    require_string("1", nonempty=False)
    require_string("1", nonempty=True)