##// END OF EJS Templates
Merge pull request #11600 from ppmfloss/fix-11559-weird-regexp-writefile...
Matthias Bussonnier -
r24931:37117b2f merge
parent child Browse files
Show More
@@ -825,7 +825,7 b' class OSMagics(Magics):'
825 The file will be overwritten unless the -a (--append) flag is specified.
825 The file will be overwritten unless the -a (--append) flag is specified.
826 """
826 """
827 args = magic_arguments.parse_argstring(self.writefile, line)
827 args = magic_arguments.parse_argstring(self.writefile, line)
828 if re.match(r'[\'*\']|["*"]', args.filename):
828 if re.match(r'^(\'.*\')|(".*")$', args.filename):
829 filename = os.path.expanduser(args.filename[1:-1])
829 filename = os.path.expanduser(args.filename[1:-1])
830 else:
830 else:
831 filename = os.path.expanduser(args.filename)
831 filename = os.path.expanduser(args.filename)
@@ -769,6 +769,36 b' def test_file():'
769 nt.assert_in('line1\n', s)
769 nt.assert_in('line1\n', s)
770 nt.assert_in('line2', s)
770 nt.assert_in('line2', s)
771
771
772 @dec.skip_win32
773 def test_file_single_quote():
774 """Basic %%writefile with embedded single quotes"""
775 ip = get_ipython()
776 with TemporaryDirectory() as td:
777 fname = os.path.join(td, '\'file1\'')
778 ip.run_cell_magic("writefile", fname, u'\n'.join([
779 'line1',
780 'line2',
781 ]))
782 with open(fname) as f:
783 s = f.read()
784 nt.assert_in('line1\n', s)
785 nt.assert_in('line2', s)
786
787 @dec.skip_win32
788 def test_file_double_quote():
789 """Basic %%writefile with embedded double quotes"""
790 ip = get_ipython()
791 with TemporaryDirectory() as td:
792 fname = os.path.join(td, '"file1"')
793 ip.run_cell_magic("writefile", fname, u'\n'.join([
794 'line1',
795 'line2',
796 ]))
797 with open(fname) as f:
798 s = f.read()
799 nt.assert_in('line1\n', s)
800 nt.assert_in('line2', s)
801
772 def test_file_var_expand():
802 def test_file_var_expand():
773 """%%writefile $filename"""
803 """%%writefile $filename"""
774 ip = get_ipython()
804 ip = get_ipython()
General Comments 0
You need to be logged in to leave comments. Login now