|
38 | 38 | sage: from sage.misc.temporary_file import tmp_dir
|
39 | 39 | sage: shell = get_test_shell()
|
40 | 40 | sage: TMP = tmp_dir()
|
| 41 | + sage: TMP = os.path.join(TMP, "12345", "temp") |
| 42 | + sage: os.makedirs(TMP) |
41 | 43 |
|
42 | 44 | The temporary directory should have a name of the form
|
43 | 45 | ``.../12345/...``, to demonstrate that file names are not
|
44 | 46 | preparsed when calling ``%runfile`` ::
|
45 | 47 |
|
46 |
| - sage: bool(re.search('/[0-9]+/', TMP)) |
| 48 | + sage: bool(re.search('/12345/', TMP)) |
47 | 49 | True
|
48 | 50 | sage: tmp = os.path.join(TMP, 'run_cell.py')
|
49 | 51 | sage: with open(tmp, 'w') as f:
|
@@ -130,30 +132,30 @@ def attach(self, s):
|
130 | 132 |
|
131 | 133 | EXAMPLES::
|
132 | 134 |
|
133 |
| - sage: import os |
134 | 135 | sage: from sage.repl.interpreter import get_test_shell
|
135 | 136 | sage: shell = get_test_shell()
|
136 |
| - sage: tmp = os.path.normpath(os.path.join(SAGE_TMP, 'run_cell.py')) |
137 |
| - sage: with open(tmp, 'w') as f: _ = f.write('a = 2\n') |
138 |
| - sage: shell.run_cell('%attach ' + tmp) |
| 137 | + sage: from tempfile import NamedTemporaryFile as NTF |
| 138 | + sage: with NTF(mode="w+t", suffix=".py", delete=False) as f: |
| 139 | + ....: _ = f.write('a = 2\n') |
| 140 | + sage: shell.run_cell('%attach ' + f.name) |
139 | 141 | sage: shell.run_cell('a')
|
140 | 142 | 2
|
141 | 143 | sage: sleep(1) # filesystem timestamp granularity
|
142 |
| - sage: with open(tmp, 'w') as f: _ = f.write('a = 3\n') |
| 144 | + sage: with open(f.name, 'w') as f: _ = f.write('a = 3\n') |
143 | 145 |
|
144 | 146 | Note that the doctests are never really at the command prompt, so
|
145 | 147 | we call the input hook manually::
|
146 | 148 |
|
147 | 149 | sage: shell.run_cell('from sage.repl.attach import reload_attached_files_if_modified')
|
148 | 150 | sage: shell.run_cell('reload_attached_files_if_modified()')
|
149 |
| - ### reloading attached file run_cell.py modified at ... ### |
| 151 | + ### reloading attached file ... modified at ... ### |
150 | 152 |
|
151 | 153 | sage: shell.run_cell('a')
|
152 | 154 | 3
|
153 |
| - sage: shell.run_cell('detach(%r)'%tmp) |
| 155 | + sage: shell.run_cell('detach(%r)' % f.name) |
154 | 156 | sage: shell.run_cell('attached_files()')
|
155 | 157 | []
|
156 |
| - sage: os.remove(tmp) |
| 158 | + sage: os.remove(f.name) |
157 | 159 | sage: shell.quit()
|
158 | 160 | """
|
159 | 161 | return self.shell.ex(load_wrap(s, attach=True))
|
|
0 commit comments