4d3a6e793ac8c48ac2ee6f59ee5a05432fcbfdba
3 ### Test ui functionality
5 ### (c) 2019 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to mLib.
12 ### mLib/Python is free software: you can redistribute it and/or modify it
13 ### under the terms of the GNU General Public License as published by the
14 ### Free Software Foundation; either version 2 of the License, or (at your
15 ### option) any later version.
17 ### mLib/Python is distributed in the hope that it will be useful, but
18 ### WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ### General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with mLib/Python. If not, write to the Free Software
24 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
33 ###--------------------------------------------------------------------------
34 class TestUI (U
.TestCase
):
38 M
.ego(OS
.path
.join("test", "thing")); me
.assertEqual(M
.quis
, "thing")
39 buf
= T
.StringIO(); M
.pquis("a simple $ test", file = buf
)
40 me
.assertEqual(buf
.getvalue(), "a simple thing test")
41 M
.ego(OS
.path
.join("other-thing")); me
.assertEqual(M
.quis
, "other-thing")
44 def _capture_stderr(me
):
45 pin
, pout
= OS
.pipe(); OS
.dup2(pout
, 2); OS
.close(pout
)
50 pin
= me
._capture_stderr()
51 ref
= T
.bin("%s: all ok really\n" % M
.quis
)
52 M
.moan("all ok really")
53 stuff
= OS
.read(pin
, 32)
58 pin
= me
._capture_stderr()
59 ref
= T
.bin("%s: so this is it\n" % M
.quis
)
60 try: M
.die("so this is it", 123)
62 stuff
= OS
.read(pin
, 32)
64 assert SYS
.exc_info()[1].code
== 123
66 raise AssertionError("die didn't exit")
72 ###----- That's all, folks --------------------------------------------------
74 if __name__
== "__main__": U
.main()