@@ -32,3 +32,42 @@ def test_journalhandler_init_exception():
3232def test_journalhandler_init ():
3333 kw = {'X' :3 , 'X3' :4 }
3434 journal .JournalHandler (logging .INFO , ** kw )
35+
36+ def test_reader_init_flags ():
37+ j1 = journal .Reader ()
38+ j2 = journal .Reader (journal .LOCAL_ONLY )
39+ j3 = journal .Reader (journal .RUNTIME_ONLY )
40+ j4 = journal .Reader (journal .SYSTEM_ONLY )
41+ j5 = journal .Reader (journal .LOCAL_ONLY |
42+ journal .RUNTIME_ONLY |
43+ journal .SYSTEM_ONLY )
44+ j6 = journal .Reader (0 )
45+
46+ def test_reader_init_path (tmpdir ):
47+ j = journal .Reader (path = tmpdir .strpath )
48+ with pytest .raises (ValueError ):
49+ journal .Reader (journal .LOCAL_ONLY , path = tmpdir .strpath )
50+
51+ def test_reader_converters (tmpdir ):
52+ converters = {'xxx' : lambda arg : 'yyy' }
53+ j = journal .Reader (path = tmpdir .strpath , converters = converters )
54+
55+ val = j ._convert_field ('xxx' , b'abc' )
56+ assert val == 'yyy'
57+
58+ val = j ._convert_field ('zzz' , b'\200 \200 ' )
59+ assert val == b'\200 \200 '
60+
61+ def test_reader_convert_entry (tmpdir ):
62+ converters = {'x1' : lambda arg : 'yyy' ,
63+ 'x2' : lambda arg : 'YYY' }
64+ j = journal .Reader (path = tmpdir .strpath , converters = converters )
65+
66+ val = j ._convert_entry ({'x1' : b'abc' ,
67+ 'y1' : b'\200 \200 ' ,
68+ 'x2' : [b'abc' , b'def' ],
69+ 'y2' : [b'\200 \200 ' , b'\200 \201 ' ]})
70+ assert val == {'x1' : 'yyy' ,
71+ 'y1' : b'\200 \200 ' ,
72+ 'x2' : ['YYY' , 'YYY' ],
73+ 'y2' : [b'\200 \200 ' , b'\200 \201 ' ]}
0 commit comments