##// END OF EJS Templates
[testing][tests][tools] Remove nose
Samuel Gaist -
Show More
@@ -1,135 +1,133 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 Tests for testing.tools
3 Tests for testing.tools
4 """
4 """
5
5
6 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
7 # Copyright (C) 2008-2011 The IPython Development Team
7 # Copyright (C) 2008-2011 The IPython Development Team
8 #
8 #
9 # Distributed under the terms of the BSD License. The full license is in
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 import os
17 import os
18 import unittest
18 import unittest
19
19
20 import nose.tools as nt
21
22 from IPython.testing import decorators as dec
20 from IPython.testing import decorators as dec
23 from IPython.testing import tools as tt
21 from IPython.testing import tools as tt
24
22
25 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
26 # Tests
24 # Tests
27 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
28
26
29 @dec.skip_win32
27 @dec.skip_win32
30 def test_full_path_posix():
28 def test_full_path_posix():
31 spath = '/foo/bar.py'
29 spath = "/foo/bar.py"
32 result = tt.full_path(spath,['a.txt','b.txt'])
30 result = tt.full_path(spath, ["a.txt", "b.txt"])
33 nt.assert_equal(result, ['/foo/a.txt', '/foo/b.txt'])
31 assert result, ["/foo/a.txt" == "/foo/b.txt"]
34 spath = '/foo'
32 spath = "/foo"
35 result = tt.full_path(spath,['a.txt','b.txt'])
33 result = tt.full_path(spath, ["a.txt", "b.txt"])
36 nt.assert_equal(result, ['/a.txt', '/b.txt'])
34 assert result, ["/a.txt" == "/b.txt"]
37 result = tt.full_path(spath,'a.txt')
35 result = tt.full_path(spath, "a.txt")
38 nt.assert_equal(result, ['/a.txt'])
36 assert result == ["/a.txt"]
39
37
40
38
41 @dec.skip_if_not_win32
39 @dec.skip_if_not_win32
42 def test_full_path_win32():
40 def test_full_path_win32():
43 spath = 'c:\\foo\\bar.py'
41 spath = "c:\\foo\\bar.py"
44 result = tt.full_path(spath,['a.txt','b.txt'])
42 result = tt.full_path(spath, ["a.txt", "b.txt"])
45 nt.assert_equal(result, ['c:\\foo\\a.txt', 'c:\\foo\\b.txt'])
43 assert result, ["c:\\foo\\a.txt" == "c:\\foo\\b.txt"]
46 spath = 'c:\\foo'
44 spath = "c:\\foo"
47 result = tt.full_path(spath,['a.txt','b.txt'])
45 result = tt.full_path(spath, ["a.txt", "b.txt"])
48 nt.assert_equal(result, ['c:\\a.txt', 'c:\\b.txt'])
46 assert result, ["c:\\a.txt" == "c:\\b.txt"]
49 result = tt.full_path(spath,'a.txt')
47 result = tt.full_path(spath, "a.txt")
50 nt.assert_equal(result, ['c:\\a.txt'])
48 assert result == ["c:\\a.txt"]
51
49
52
50
53 def test_parser():
51 def test_parser():
54 err = ("FAILED (errors=1)", 1, 0)
52 err = ("FAILED (errors=1)", 1, 0)
55 fail = ("FAILED (failures=1)", 0, 1)
53 fail = ("FAILED (failures=1)", 0, 1)
56 both = ("FAILED (errors=1, failures=1)", 1, 1)
54 both = ("FAILED (errors=1, failures=1)", 1, 1)
57 for txt, nerr, nfail in [err, fail, both]:
55 for txt, nerr, nfail in [err, fail, both]:
58 nerr1, nfail1 = tt.parse_test_output(txt)
56 nerr1, nfail1 = tt.parse_test_output(txt)
59 nt.assert_equal(nerr, nerr1)
57 assert nerr == nerr1
60 nt.assert_equal(nfail, nfail1)
58 assert nfail == nfail1
61
59
62
60
63 def test_temp_pyfile():
61 def test_temp_pyfile():
64 src = 'pass\n'
62 src = 'pass\n'
65 fname = tt.temp_pyfile(src)
63 fname = tt.temp_pyfile(src)
66 assert os.path.isfile(fname)
64 assert os.path.isfile(fname)
67 with open(fname) as fh2:
65 with open(fname) as fh2:
68 src2 = fh2.read()
66 src2 = fh2.read()
69 nt.assert_equal(src2, src)
67 assert src2 == src
70
68
71 class TestAssertPrints(unittest.TestCase):
69 class TestAssertPrints(unittest.TestCase):
72 def test_passing(self):
70 def test_passing(self):
73 with tt.AssertPrints("abc"):
71 with tt.AssertPrints("abc"):
74 print("abcd")
72 print("abcd")
75 print("def")
73 print("def")
76 print(b"ghi")
74 print(b"ghi")
77
75
78 def test_failing(self):
76 def test_failing(self):
79 def func():
77 def func():
80 with tt.AssertPrints("abc"):
78 with tt.AssertPrints("abc"):
81 print("acd")
79 print("acd")
82 print("def")
80 print("def")
83 print(b"ghi")
81 print(b"ghi")
84
82
85 self.assertRaises(AssertionError, func)
83 self.assertRaises(AssertionError, func)
86
84
87
85
88 class Test_ipexec_validate(tt.TempFileMixin):
86 class Test_ipexec_validate(tt.TempFileMixin):
89 def test_main_path(self):
87 def test_main_path(self):
90 """Test with only stdout results.
88 """Test with only stdout results.
91 """
89 """
92 self.mktmp("print('A')\n"
90 self.mktmp("print('A')\n"
93 "print('B')\n"
91 "print('B')\n"
94 )
92 )
95 out = "A\nB"
93 out = "A\nB"
96 tt.ipexec_validate(self.fname, out)
94 tt.ipexec_validate(self.fname, out)
97
95
98 def test_main_path2(self):
96 def test_main_path2(self):
99 """Test with only stdout results, expecting windows line endings.
97 """Test with only stdout results, expecting windows line endings.
100 """
98 """
101 self.mktmp("print('A')\n"
99 self.mktmp("print('A')\n"
102 "print('B')\n"
100 "print('B')\n"
103 )
101 )
104 out = "A\r\nB"
102 out = "A\r\nB"
105 tt.ipexec_validate(self.fname, out)
103 tt.ipexec_validate(self.fname, out)
106
104
107 def test_exception_path(self):
105 def test_exception_path(self):
108 """Test exception path in exception_validate.
106 """Test exception path in exception_validate.
109 """
107 """
110 self.mktmp("import sys\n"
108 self.mktmp("import sys\n"
111 "print('A')\n"
109 "print('A')\n"
112 "print('B')\n"
110 "print('B')\n"
113 "print('C', file=sys.stderr)\n"
111 "print('C', file=sys.stderr)\n"
114 "print('D', file=sys.stderr)\n"
112 "print('D', file=sys.stderr)\n"
115 )
113 )
116 out = "A\nB"
114 out = "A\nB"
117 tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\nD")
115 tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\nD")
118
116
119 def test_exception_path2(self):
117 def test_exception_path2(self):
120 """Test exception path in exception_validate, expecting windows line endings.
118 """Test exception path in exception_validate, expecting windows line endings.
121 """
119 """
122 self.mktmp("import sys\n"
120 self.mktmp("import sys\n"
123 "print('A')\n"
121 "print('A')\n"
124 "print('B')\n"
122 "print('B')\n"
125 "print('C', file=sys.stderr)\n"
123 "print('C', file=sys.stderr)\n"
126 "print('D', file=sys.stderr)\n"
124 "print('D', file=sys.stderr)\n"
127 )
125 )
128 out = "A\r\nB"
126 out = "A\r\nB"
129 tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\r\nD")
127 tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\r\nD")
130
128
131
129
132 def tearDown(self):
130 def tearDown(self):
133 # tear down correctly the mixin,
131 # tear down correctly the mixin,
134 # unittest.TestCase.tearDown does nothing
132 # unittest.TestCase.tearDown does nothing
135 tt.TempFileMixin.tearDown(self)
133 tt.TempFileMixin.tearDown(self)
General Comments 0
You need to be logged in to leave comments. Login now