##// END OF EJS Templates
Use pathlib
Joyce Er -
Show More
@@ -14,6 +14,7 b' from unittest import TestCase'
14 from unittest import mock
14 from unittest import mock
15 from importlib import invalidate_caches
15 from importlib import invalidate_caches
16 from io import StringIO
16 from io import StringIO
17 from pathlib import Path
17
18
18 import nose.tools as nt
19 import nose.tools as nt
19
20
@@ -831,8 +832,7 b' def test_file():'
831 'line1',
832 'line1',
832 'line2',
833 'line2',
833 ]))
834 ]))
834 with open(fname) as f:
835 s = Path(fname).read_text()
835 s = f.read()
836 nt.assert_in('line1\n', s)
836 nt.assert_in('line1\n', s)
837 nt.assert_in('line2', s)
837 nt.assert_in('line2', s)
838
838
@@ -846,8 +846,7 b' def test_file_single_quote():'
846 'line1',
846 'line1',
847 'line2',
847 'line2',
848 ]))
848 ]))
849 with open(fname) as f:
849 s = Path(fname).read_text()
850 s = f.read()
851 nt.assert_in('line1\n', s)
850 nt.assert_in('line1\n', s)
852 nt.assert_in('line2', s)
851 nt.assert_in('line2', s)
853
852
@@ -861,8 +860,7 b' def test_file_double_quote():'
861 'line1',
860 'line1',
862 'line2',
861 'line2',
863 ]))
862 ]))
864 with open(fname) as f:
863 s = Path(fname).read_text()
865 s = f.read()
866 nt.assert_in('line1\n', s)
864 nt.assert_in('line1\n', s)
867 nt.assert_in('line2', s)
865 nt.assert_in('line2', s)
868
866
@@ -876,8 +874,7 b' def test_file_var_expand():'
876 'line1',
874 'line1',
877 'line2',
875 'line2',
878 ]))
876 ]))
879 with open(fname) as f:
877 s = Path(fname).read_text()
880 s = f.read()
881 nt.assert_in('line1\n', s)
878 nt.assert_in('line1\n', s)
882 nt.assert_in('line2', s)
879 nt.assert_in('line2', s)
883
880
@@ -908,8 +905,7 b' def test_file_amend():'
908 'line3',
905 'line3',
909 'line4',
906 'line4',
910 ]))
907 ]))
911 with open(fname) as f:
908 s = Path(fname).read_text()
912 s = f.read()
913 nt.assert_in('line1\n', s)
909 nt.assert_in('line1\n', s)
914 nt.assert_in('line3\n', s)
910 nt.assert_in('line3\n', s)
915
911
@@ -922,8 +918,7 b' def test_file_spaces():'
922 'line1',
918 'line1',
923 'line2',
919 'line2',
924 ]))
920 ]))
925 with open(fname) as f:
921 s = Path(fname).read_text()
926 s = f.read()
927 nt.assert_in('line1\n', s)
922 nt.assert_in('line1\n', s)
928 nt.assert_in('line2', s)
923 nt.assert_in('line2', s)
929
924
@@ -1063,15 +1058,13 b' def test_save():'
1063 with TemporaryDirectory() as tmpdir:
1058 with TemporaryDirectory() as tmpdir:
1064 file = os.path.join(tmpdir, "testsave.py")
1059 file = os.path.join(tmpdir, "testsave.py")
1065 ip.run_line_magic("save", "%s 1-10" % file)
1060 ip.run_line_magic("save", "%s 1-10" % file)
1066 with open(file) as f:
1061 content = Path(file).read_text()
1067 content = f.read()
1062 nt.assert_equal(content.count(cmds[0]), 1)
1068 nt.assert_equal(content.count(cmds[0]), 1)
1063 nt.assert_in('coding: utf-8', content)
1069 nt.assert_in('coding: utf-8', content)
1070 ip.run_line_magic("save", "-a %s 1-10" % file)
1064 ip.run_line_magic("save", "-a %s 1-10" % file)
1071 with open(file) as f:
1065 content = Path(file).read_text()
1072 content = f.read()
1066 nt.assert_equal(content.count(cmds[0]), 2)
1073 nt.assert_equal(content.count(cmds[0]), 2)
1067 nt.assert_in('coding: utf-8', content)
1074 nt.assert_in('coding: utf-8', content)
1075
1068
1076
1069
1077 def test_store():
1070 def test_store():
@@ -1231,8 +1224,7 b' def test_run_module_from_import_hook():'
1231 "Test that a module can be loaded via an import hook"
1224 "Test that a module can be loaded via an import hook"
1232 with TemporaryDirectory() as tmpdir:
1225 with TemporaryDirectory() as tmpdir:
1233 fullpath = os.path.join(tmpdir, 'my_tmp.py')
1226 fullpath = os.path.join(tmpdir, 'my_tmp.py')
1234 with open(fullpath, 'w') as f:
1227 Path(fullpath).write_text(TEST_MODULE)
1235 f.write(TEST_MODULE)
1236
1228
1237 class MyTempImporter(object):
1229 class MyTempImporter(object):
1238 def __init__(self):
1230 def __init__(self):
@@ -1248,8 +1240,7 b' def test_run_module_from_import_hook():'
1248 return imp.load_source('my_tmp', fullpath)
1240 return imp.load_source('my_tmp', fullpath)
1249
1241
1250 def get_code(self, fullname):
1242 def get_code(self, fullname):
1251 with open(fullpath, 'r') as f:
1243 return compile(Path(fullpath).read_text(), 'foo', 'exec')
1252 return compile(f.read(), 'foo', 'exec')
1253
1244
1254 def is_package(self, __):
1245 def is_package(self, __):
1255 return False
1246 return False
@@ -2,7 +2,7 b''
2
2
3 from os.path import join, dirname, abspath
3 from os.path import join, dirname, abspath
4 import inspect
4 import inspect
5
5 from pathlib import Path
6 from IPython.terminal.ipapp import TerminalIPythonApp
6 from IPython.terminal.ipapp import TerminalIPythonApp
7 from ipykernel.kernelapp import IPKernelApp
7 from ipykernel.kernelapp import IPKernelApp
8 from traitlets import Undefined
8 from traitlets import Undefined
@@ -118,8 +118,7 b' def write_doc(name, title, app, preamble=None):'
118
118
119 if __name__ == '__main__':
119 if __name__ == '__main__':
120 # Touch this file for the make target
120 # Touch this file for the make target
121 with open(generated, 'w'):
121 Path(generated).write_text('')
122 pass
123
122
124 write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp())
123 write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp())
125 write_doc('kernel', 'IPython kernel options', IPKernelApp(),
124 write_doc('kernel', 'IPython kernel options', IPKernelApp(),
@@ -1,5 +1,5 b''
1 import os
1 import os
2
2 from pathlib import Path
3 from IPython.core.alias import Alias
3 from IPython.core.alias import Alias
4 from IPython.core.interactiveshell import InteractiveShell
4 from IPython.core.interactiveshell import InteractiveShell
5 from IPython.core.magic import MagicAlias
5 from IPython.core.magic import MagicAlias
@@ -63,6 +63,5 b" for name, func in sorted(magics['cell'].items(), key=sortkey):"
63 ""])
63 ""])
64
64
65 here = os.path.dirname(__file__)
65 here = os.path.dirname(__file__)
66 dest = os.path.join(here, 'source', 'interactive', 'magics-generated.txt')
66 dest = Path(os.path.join(here, 'source', 'interactive', 'magics-generated.txt'))
67 with open(dest, "w") as f:
67 dest.write_text("\n".join(output))
68 f.write("\n".join(output))
General Comments 0
You need to be logged in to leave comments. Login now