File: test_grp.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (38 lines) | stat: -rw-r--r-- 1,017 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
import pytest

grp = pytest.importorskip('grp')


def test_basic():
    with pytest.raises(KeyError) as e:
        grp.getgrnam("dEkLofcG")
    assert e.value.args[0] == 'getgrnam(): name not found: dEkLofcG'
    for name in ["root", "wheel"]:
        try:
            g = grp.getgrnam(name)
        except KeyError:
            continue
        assert g.gr_gid == 0
        assert 'root' in g.gr_mem or g.gr_mem == []
        assert g.gr_name == name
        assert isinstance(g.gr_passwd, str)    # usually just 'x', don't hope :-)
        g2 = grp.getgrnam(unicode(name))
        assert g2 == g
        break
    else:
        raise

def test_extra():
    with pytest.raises(KeyError):
        grp.getgrnam(False)
    with pytest.raises(KeyError):
        grp.getgrnam(None)

def test_struct_group():
    g = grp.struct_group((10, 20, 30, 40))
    assert len(g) == 4
    assert list(g) == [10, 20, 30, 40]
    assert g.gr_name == 10
    assert g.gr_passwd == 20
    assert g.gr_gid == 30
    assert g.gr_mem == 40