##// END OF EJS Templates
Adding tests expecting windows lineendings.
Jörgen Stenarson -
Show More
@@ -1,114 +1,136
1 1 # encoding: utf-8
2 2 """
3 3 Tests for testing.tools
4 4 """
5 5
6 6 #-----------------------------------------------------------------------------
7 7 # Copyright (C) 2008-2011 The IPython Development Team
8 8 #
9 9 # Distributed under the terms of the BSD License. The full license is in
10 10 # the file COPYING, distributed as part of this software.
11 11 #-----------------------------------------------------------------------------
12 12
13 13 #-----------------------------------------------------------------------------
14 14 # Imports
15 15 #-----------------------------------------------------------------------------
16 16 from __future__ import with_statement
17 17
18 18 import os
19 19 import sys
20 20 import unittest
21 21
22 22 import nose.tools as nt
23 23
24 24 from IPython.testing import decorators as dec
25 25 from IPython.testing import tools as tt
26 26
27 27 #-----------------------------------------------------------------------------
28 28 # Tests
29 29 #-----------------------------------------------------------------------------
30 30
31 31 @dec.skip_win32
32 32 def test_full_path_posix():
33 33 spath = '/foo/bar.py'
34 34 result = tt.full_path(spath,['a.txt','b.txt'])
35 35 nt.assert_equal(result, ['/foo/a.txt', '/foo/b.txt'])
36 36 spath = '/foo'
37 37 result = tt.full_path(spath,['a.txt','b.txt'])
38 38 nt.assert_equal(result, ['/a.txt', '/b.txt'])
39 39 result = tt.full_path(spath,'a.txt')
40 40 nt.assert_equal(result, ['/a.txt'])
41 41
42 42
43 43 @dec.skip_if_not_win32
44 44 def test_full_path_win32():
45 45 spath = 'c:\\foo\\bar.py'
46 46 result = tt.full_path(spath,['a.txt','b.txt'])
47 47 nt.assert_equal(result, ['c:\\foo\\a.txt', 'c:\\foo\\b.txt'])
48 48 spath = 'c:\\foo'
49 49 result = tt.full_path(spath,['a.txt','b.txt'])
50 50 nt.assert_equal(result, ['c:\\a.txt', 'c:\\b.txt'])
51 51 result = tt.full_path(spath,'a.txt')
52 52 nt.assert_equal(result, ['c:\\a.txt'])
53 53
54 54
55 55 @dec.parametric
56 56 def test_parser():
57 57 err = ("FAILED (errors=1)", 1, 0)
58 58 fail = ("FAILED (failures=1)", 0, 1)
59 59 both = ("FAILED (errors=1, failures=1)", 1, 1)
60 60 for txt, nerr, nfail in [err, fail, both]:
61 61 nerr1, nfail1 = tt.parse_test_output(txt)
62 62 yield nt.assert_equal(nerr, nerr1)
63 63 yield nt.assert_equal(nfail, nfail1)
64 64
65 65
66 66 @dec.parametric
67 67 def test_temp_pyfile():
68 68 src = 'pass\n'
69 69 fname, fh = tt.temp_pyfile(src)
70 70 yield nt.assert_true(os.path.isfile(fname))
71 71 fh.close()
72 72 with open(fname) as fh2:
73 73 src2 = fh2.read()
74 74 yield nt.assert_equal(src2, src)
75 75
76 76 class TestAssertPrints(unittest.TestCase):
77 77 def test_passing(self):
78 78 with tt.AssertPrints("abc"):
79 79 print "abcd"
80 80 print "def"
81 81 print b"ghi"
82 82
83 83 def test_failing(self):
84 84 def func():
85 85 with tt.AssertPrints("abc"):
86 86 print "acd"
87 87 print "def"
88 88 print b"ghi"
89 89
90 90 self.assertRaises(AssertionError, func)
91 91
92 92
93 93 class Test_ipexec_validate(unittest.TestCase, tt.TempFileMixin):
94 94 def test_main_path(self):
95 95 """Test with only stdout results.
96 96 """
97 97 self.mktmp("print('A')\n"
98 98 "print('B')\n"
99 99 )
100 100 out = "A\nB"
101 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 112 def test_exception_path(self):
104 113 """Test exception path in exception_validate.
105 114 """
106 115 self.mktmp("from __future__ import print_function\n"
107 116 "import sys\n"
108 117 "print('A')\n"
109 118 "print('B')\n"
110 119 "print('C', file=sys.stderr)\n"
111 120 "print('D', file=sys.stderr)\n"
112 121 )
113 122 out = "A\nB"
114 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