Show More
@@ -825,7 +825,7 b' class OSMagics(Magics):' | |||
|
825 | 825 | The file will be overwritten unless the -a (--append) flag is specified. |
|
826 | 826 | """ |
|
827 | 827 | args = magic_arguments.parse_argstring(self.writefile, line) |
|
828 |
if re.match(r' |
|
|
828 | if re.match(r'^(\'.*\')|(".*")$', args.filename): | |
|
829 | 829 | filename = os.path.expanduser(args.filename[1:-1]) |
|
830 | 830 | else: |
|
831 | 831 | filename = os.path.expanduser(args.filename) |
@@ -769,6 +769,36 b' def test_file():' | |||
|
769 | 769 | nt.assert_in('line1\n', s) |
|
770 | 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 | 802 | def test_file_var_expand(): |
|
773 | 803 | """%%writefile $filename""" |
|
774 | 804 | ip = get_ipython() |
General Comments 0
You need to be logged in to leave comments.
Login now