Show More
@@ -816,8 +816,11 b' class OSMagics(Magics):' | |||||
816 | The file will be overwritten unless the -a (--append) flag is specified. |
|
816 | The file will be overwritten unless the -a (--append) flag is specified. | |
817 | """ |
|
817 | """ | |
818 | args = magic_arguments.parse_argstring(self.writefile, line) |
|
818 | args = magic_arguments.parse_argstring(self.writefile, line) | |
819 | filename = os.path.expanduser(args.filename) |
|
819 | if re.match(r'[\'*\']|["*"]', args.filename): | |
820 |
|
820 | filename = os.path.expanduser(args.filename[1:-1]) | ||
|
821 | else: | |||
|
822 | filename = os.path.expanduser(args.filename) | |||
|
823 | ||||
821 | if os.path.exists(filename): |
|
824 | if os.path.exists(filename): | |
822 | if args.append: |
|
825 | if args.append: | |
823 | print("Appending to %s" % filename) |
|
826 | print("Appending to %s" % filename) |
@@ -27,7 +27,8 b' from IPython.core.magics import execution, script, code, logging' | |||||
27 | from IPython.testing import decorators as dec |
|
27 | from IPython.testing import decorators as dec | |
28 | from IPython.testing import tools as tt |
|
28 | from IPython.testing import tools as tt | |
29 | from IPython.utils.io import capture_output |
|
29 | from IPython.utils.io import capture_output | |
30 | from IPython.utils.tempdir import TemporaryDirectory |
|
30 | from IPython.utils.tempdir import (TemporaryDirectory, | |
|
31 | TemporaryWorkingDirectory) | |||
31 | from IPython.utils.process import find_cmd |
|
32 | from IPython.utils.process import find_cmd | |
32 |
|
33 | |||
33 |
|
34 | |||
@@ -797,7 +798,20 b' def test_file_amend():' | |||||
797 | s = f.read() |
|
798 | s = f.read() | |
798 | nt.assert_in('line1\n', s) |
|
799 | nt.assert_in('line1\n', s) | |
799 | nt.assert_in('line3\n', s) |
|
800 | nt.assert_in('line3\n', s) | |
800 |
|
801 | |||
|
802 | def test_file_spaces(): | |||
|
803 | """%%file with spaces in filename""" | |||
|
804 | ip = get_ipython() | |||
|
805 | with TemporaryWorkingDirectory() as td: | |||
|
806 | fname = "file name" | |||
|
807 | ip.run_cell_magic("file", '"%s"'%fname, u'\n'.join([ | |||
|
808 | 'line1', | |||
|
809 | 'line2', | |||
|
810 | ])) | |||
|
811 | with open(fname) as f: | |||
|
812 | s = f.read() | |||
|
813 | nt.assert_in('line1\n', s) | |||
|
814 | nt.assert_in('line2', s) | |||
801 |
|
815 | |||
802 | def test_script_config(): |
|
816 | def test_script_config(): | |
803 | ip = get_ipython() |
|
817 | ip = get_ipython() |
General Comments 0
You need to be logged in to leave comments.
Login now