Show More
@@ -2230,7 +2230,7 Currently the magic system has the following functions:\n""" | |||
|
2230 | 2230 | except (TypeError, ValueError) as e: |
|
2231 | 2231 | print e.args[0] |
|
2232 | 2232 | return |
|
2233 |
with |
|
|
2233 | with io.open(fname,'w', encoding="utf-8") as f: | |
|
2234 | 2234 | f.write(u"# coding: utf-8\n") |
|
2235 | 2235 | f.write(py3compat.cast_unicode(cmds)) |
|
2236 | 2236 | print 'The following commands were written to file `%s`:' % fname |
@@ -3683,7 +3683,7 Defaulting color scheme to 'NoColor'""" | |||
|
3683 | 3683 | cells.append(current.new_code_cell(prompt_number=prompt_number, input=input)) |
|
3684 | 3684 | worksheet = current.new_worksheet(cells=cells) |
|
3685 | 3685 | nb = current.new_notebook(name=name,worksheets=[worksheet]) |
|
3686 | with io.open(fname, 'w') as f: | |
|
3686 | with io.open(fname, 'w', encoding='utf-8') as f: | |
|
3687 | 3687 | current.write(nb, f, format); |
|
3688 | 3688 | elif args.format is not None: |
|
3689 | 3689 | old_fname, old_name, old_format = current.parse_filename(args.filename) |
@@ -3697,9 +3697,9 Defaulting color scheme to 'NoColor'""" | |||
|
3697 | 3697 | new_fname = old_name + u'.py' |
|
3698 | 3698 | else: |
|
3699 | 3699 | raise ValueError('Invalid notebook format: %s' % new_format) |
|
3700 | with io.open(old_fname, 'r') as f: | |
|
3700 | with io.open(old_fname, 'r', encoding='utf-8') as f: | |
|
3701 | 3701 | nb = current.read(f, old_format) |
|
3702 | with io.open(new_fname, 'w') as f: | |
|
3702 | with io.open(new_fname, 'w', encoding='utf-8') as f: | |
|
3703 | 3703 | current.write(nb, f, new_format) |
|
3704 | 3704 | |
|
3705 | 3705 | def magic_config(self, s): |
@@ -17,6 +17,9 from ..nbpy import reads, writes, read, write | |||
|
17 | 17 | from .nbexamples import nb0, nb0_py |
|
18 | 18 | |
|
19 | 19 | |
|
20 | def open_utf8(fname, mode): | |
|
21 | return io.open(fname, mode=mode, encoding='utf-8') | |
|
22 | ||
|
20 | 23 | class NBFormatTestCase(TestCase): |
|
21 | 24 | |
|
22 | 25 | # override with appropriate values in subclasses |
@@ -47,14 +50,14 class NBFormatTestCase(TestCase): | |||
|
47 | 50 | self.assertNBEquals(self.mod.reads(s),nb0) |
|
48 | 51 | |
|
49 | 52 | def test_write_file(self): |
|
50 |
with |
|
|
53 | with open_utf8(pjoin(self.wd, "nb0.%s" % self.ext), 'w') as f: | |
|
51 | 54 | self.mod.write(nb0, f) |
|
52 | 55 | |
|
53 | 56 | def test_read_file(self): |
|
54 |
with |
|
|
57 | with open_utf8(pjoin(self.wd, "nb0.%s" % self.ext), 'w') as f: | |
|
55 | 58 | self.mod.write(nb0, f) |
|
56 | 59 | |
|
57 |
with |
|
|
60 | with open_utf8(pjoin(self.wd, "nb0.%s" % self.ext), 'r') as f: | |
|
58 | 61 | nb = self.mod.read(f) |
|
59 | 62 | |
|
60 | 63 |
General Comments 0
You need to be logged in to leave comments.
Login now