Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from e19_passwd_to_dict import passwd_to_dict 

2import pytest 

3from io import StringIO 

4 

5 

6@pytest.fixture 

7def empty_passwd(tmp_path): 

8 f = tmp_path / 'passwd' 

9 f.write_text('') 

10 return f 

11 

12 

13@pytest.fixture 

14def simple_passwd(tmp_path): 

15 f = tmp_path / 'passwd' 

16 f.write_text('''root:x:0:0:root:/root:/bin/bash 

17daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin 

18bin:x:2:2:bin:/bin:/usr/sbin/nologin 

19sys:x:3:3:sys:/dev:/usr/sbin/nologin 

20sync:x:4:65534:sync:/bin:/bin/sync 

21games:x:5:60:games:/usr/games:/usr/sbin/nologin 

22man:x:6:12:man:/var/cache/man:/usr/sbin/nologin 

23lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin 

24mail:x:8:8:mail:/var/mail:/usr/sbin/nologin 

25''') 

26 return f 

27 

28 

29@pytest.fixture 

30def complex_passwd(tmp_path): 

31 f = tmp_path / 'passwd' 

32 f.write_text('''root:x:0:0:root:/root:/bin/bash 

33daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin 

34bin:x:2:2:bin:/bin:/usr/sbin/nologin 

35sys:x:3:3:sys:/dev:/usr/sbin/nologin 

36# this is a comment line 

37# and then we have some blank lines 

38 

39sync:x:4:65534:sync:/bin:/bin/sync 

40games:x:5:60:games:/usr/games:/usr/sbin/nologin 

41man:x:6:12:man:/var/cache/man:/usr/sbin/nologin 

42lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin 

43mail:x:8:8:mail:/var/mail:/usr/sbin/nologin 

44''') 

45 return f 

46 

47 

48def test_empty(empty_passwd): 

49 assert passwd_to_dict(empty_passwd) == {} 

50 

51 

52def test_simple(simple_passwd): 

53 d = passwd_to_dict(simple_passwd) 

54 assert len(d) == 9 

55 assert d['root'] == 0 

56 assert d['sys'] == 3 

57 assert d['mail'] == 8 

58 

59 

60def test_complex(complex_passwd): 

61 d = passwd_to_dict(complex_passwd) 

62 assert len(d) == 9 

63 assert d['root'] == 0 

64 assert d['sys'] == 3 

65 assert d['mail'] == 8