##// END OF EJS Templates
Adding tests expecting windows lineendings.
Jörgen Stenarson -
Show More
@@ -1,114 +1,136
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 from __future__ import with_statement
16 from __future__ import with_statement
17
17
18 import os
18 import os
19 import sys
19 import sys
20 import unittest
20 import unittest
21
21
22 import nose.tools as nt
22 import nose.tools as nt
23
23
24 from IPython.testing import decorators as dec
24 from IPython.testing import decorators as dec
25 from IPython.testing import tools as tt
25 from IPython.testing import tools as tt
26
26
27 #-----------------------------------------------------------------------------
27 #-----------------------------------------------------------------------------
28 # Tests
28 # Tests
29 #-----------------------------------------------------------------------------
29 #-----------------------------------------------------------------------------
30
30
31 @dec.skip_win32
31 @dec.skip_win32
32 def test_full_path_posix():
32 def test_full_path_posix():
33 spath = '/foo/bar.py'
33 spath = '/foo/bar.py'
34 result = tt.full_path(spath,['a.txt','b.txt'])
34 result = tt.full_path(spath,['a.txt','b.txt'])
35 nt.assert_equal(result, ['/foo/a.txt', '/foo/b.txt'])
35 nt.assert_equal(result, ['/foo/a.txt', '/foo/b.txt'])
36 spath = '/foo'
36 spath = '/foo'
37 result = tt.full_path(spath,['a.txt','b.txt'])
37 result = tt.full_path(spath,['a.txt','b.txt'])
38 nt.assert_equal(result, ['/a.txt', '/b.txt'])
38 nt.assert_equal(result, ['/a.txt', '/b.txt'])
39 result = tt.full_path(spath,'a.txt')
39 result = tt.full_path(spath,'a.txt')
40 nt.assert_equal(result, ['/a.txt'])
40 nt.assert_equal(result, ['/a.txt'])
41
41
42
42
43 @dec.skip_if_not_win32
43 @dec.skip_if_not_win32
44 def test_full_path_win32():
44 def test_full_path_win32():
45 spath = 'c:\\foo\\bar.py'
45 spath = 'c:\\foo\\bar.py'
46 result = tt.full_path(spath,['a.txt','b.txt'])
46 result = tt.full_path(spath,['a.txt','b.txt'])
47 nt.assert_equal(result, ['c:\\foo\\a.txt', 'c:\\foo\\b.txt'])
47 nt.assert_equal(result, ['c:\\foo\\a.txt', 'c:\\foo\\b.txt'])
48 spath = 'c:\\foo'
48 spath = 'c:\\foo'
49 result = tt.full_path(spath,['a.txt','b.txt'])
49 result = tt.full_path(spath,['a.txt','b.txt'])
50 nt.assert_equal(result, ['c:\\a.txt', 'c:\\b.txt'])
50 nt.assert_equal(result, ['c:\\a.txt', 'c:\\b.txt'])
51 result = tt.full_path(spath,'a.txt')
51 result = tt.full_path(spath,'a.txt')
52 nt.assert_equal(result, ['c:\\a.txt'])
52 nt.assert_equal(result, ['c:\\a.txt'])
53
53
54
54
55 @dec.parametric
55 @dec.parametric
56 def test_parser():
56 def test_parser():
57 err = ("FAILED (errors=1)", 1, 0)
57 err = ("FAILED (errors=1)", 1, 0)
58 fail = ("FAILED (failures=1)", 0, 1)
58 fail = ("FAILED (failures=1)", 0, 1)
59 both = ("FAILED (errors=1, failures=1)", 1, 1)
59 both = ("FAILED (errors=1, failures=1)", 1, 1)
60 for txt, nerr, nfail in [err, fail, both]:
60 for txt, nerr, nfail in [err, fail, both]:
61 nerr1, nfail1 = tt.parse_test_output(txt)
61 nerr1, nfail1 = tt.parse_test_output(txt)
62 yield nt.assert_equal(nerr, nerr1)
62 yield nt.assert_equal(nerr, nerr1)
63 yield nt.assert_equal(nfail, nfail1)
63 yield nt.assert_equal(nfail, nfail1)
64
64
65
65
66 @dec.parametric
66 @dec.parametric
67 def test_temp_pyfile():
67 def test_temp_pyfile():
68 src = 'pass\n'
68 src = 'pass\n'
69 fname, fh = tt.temp_pyfile(src)
69 fname, fh = tt.temp_pyfile(src)
70 yield nt.assert_true(os.path.isfile(fname))
70 yield nt.assert_true(os.path.isfile(fname))
71 fh.close()
71 fh.close()
72 with open(fname) as fh2:
72 with open(fname) as fh2:
73 src2 = fh2.read()
73 src2 = fh2.read()
74 yield nt.assert_equal(src2, src)
74 yield nt.assert_equal(src2, src)
75
75
76 class TestAssertPrints(unittest.TestCase):
76 class TestAssertPrints(unittest.TestCase):
77 def test_passing(self):
77 def test_passing(self):
78 with tt.AssertPrints("abc"):
78 with tt.AssertPrints("abc"):
79 print "abcd"
79 print "abcd"
80 print "def"
80 print "def"
81 print b"ghi"
81 print b"ghi"
82
82
83 def test_failing(self):
83 def test_failing(self):
84 def func():
84 def func():
85 with tt.AssertPrints("abc"):
85 with tt.AssertPrints("abc"):
86 print "acd"
86 print "acd"
87 print "def"
87 print "def"
88 print b"ghi"
88 print b"ghi"
89
89
90 self.assertRaises(AssertionError, func)
90 self.assertRaises(AssertionError, func)
91
91
92
92
93 class Test_ipexec_validate(unittest.TestCase, tt.TempFileMixin):
93 class Test_ipexec_validate(unittest.TestCase, tt.TempFileMixin):
94 def test_main_path(self):
94 def test_main_path(self):
95 """Test with only stdout results.
95 """Test with only stdout results.
96 """
96 """
97 self.mktmp("print('A')\n"
97 self.mktmp("print('A')\n"
98 "print('B')\n"
98 "print('B')\n"
99 )
99 )
100 out = "A\nB"
100 out = "A\nB"
101 tt.ipexec_validate(self.fname, out)
101 tt.ipexec_validate(self.fname, out)
102
102
103 def test_main_path2(self):
104 """Test with only stdout results, expecting windows line endings.
105 """
106 self.mktmp("print('A')\n"
107 "print('B')\n"
108 )
109 out = "A\r\nB"
110 tt.ipexec_validate(self.fname, out)
111
103 def test_exception_path(self):
112 def test_exception_path(self):
104 """Test exception path in exception_validate.
113 """Test exception path in exception_validate.
105 """
114 """
106 self.mktmp("from __future__ import print_function\n"
115 self.mktmp("from __future__ import print_function\n"
107 "import sys\n"
116 "import sys\n"
108 "print('A')\n"
117 "print('A')\n"
109 "print('B')\n"
118 "print('B')\n"
110 "print('C', file=sys.stderr)\n"
119 "print('C', file=sys.stderr)\n"
111 "print('D', file=sys.stderr)\n"
120 "print('D', file=sys.stderr)\n"
112 )
121 )
113 out = "A\nB"
122 out = "A\nB"
114 tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\nD")
123 tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\nD")
124
125 def test_exception_path(self):
126 """Test exception path in exception_validate, expecting windows line endings.
127 """
128 self.mktmp("from __future__ import print_function\n"
129 "import sys\n"
130 "print('A')\n"
131 "print('B')\n"
132 "print('C', file=sys.stderr)\n"
133 "print('D', file=sys.stderr)\n"
134 )
135 out = "A\r\nB"
136 tt.ipexec_validate(self.fname, expected_out=out, expected_err="C\r\nD")
General Comments 0
You need to be logged in to leave comments. Login now