Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
call get_temp_folder in a unit test instead of cleaning a temporary f…
Browse files Browse the repository at this point in the history
…older
  • Loading branch information
sdpython committed May 23, 2015
1 parent 29bfbd3 commit 5c3d42c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 3 additions & 6 deletions _unittests/ut_helpgen/test_notebooks.py
Expand Up @@ -23,6 +23,7 @@

from src.pyquickhelper.loghelper.flog import fLOG, run_cmd
from src.pyquickhelper.helpgen.sphinx_main import process_notebooks, add_notebook_page
from src.pyquickhelper import get_temp_folder

if sys.version_info[0] == 2:
from codecs import open
Expand Down Expand Up @@ -50,12 +51,8 @@ def test_notebook(self):
nb = os.path.join(fold, "example_pyquickhelper.ipynb")
assert os.path.exists(nb)

temp = os.path.join(path, "temp_nb")
if not os.path.exists(temp):
os.mkdir(temp)
for file in os.listdir(temp):
os.remove(os.path.join(temp, file))

temp = get_temp_folder(__file__, "temp_nb")

if sys.platform.startswith("win"):
p1 = r"C:\Program Files\MiKTeX 2.9\miktex\bin\x64"
p2 = r"%USERPROFILE%\AppData\Local\Pandoc"
Expand Down
3 changes: 0 additions & 3 deletions src/pyquickhelper/helpgen/process_notebooks.py
Expand Up @@ -167,9 +167,6 @@ def process_notebooks(notebooks,
if not os.path.exists(build_slide):
os.mkdir(build_slide)

# for some reason, sometimes, the folder is not in write mode
change_file_status(build_slide)

if "WinPython" in sys.executable:
# pip, or any program in Scripts cannot find python.exe
# for the distribution WinPython
Expand Down
9 changes: 9 additions & 0 deletions src/pyquickhelper/pycode/utils_tests.py
Expand Up @@ -8,6 +8,7 @@
from __future__ import print_function

import os
import stat
import sys
import glob
import re
Expand Down Expand Up @@ -48,12 +49,20 @@ def get_temp_folder(thisfile, name, clean=True, create=True):
if not os.path.exists(local):
if create:
os.mkdir(local)
mode = os.stat(local).st_mode
nmode = mode | stat.S_IWRITE
if nmode != mode:
os.chmod(local, nmode)
else:
if clean:
remove_folder(local)
time.sleep(0.1)
if create and not os.path.exists(local):
os.mkdir(local)
mode = os.stat(local).st_mode
nmode = mode | stat.S_IWRITE
if nmode != mode:
os.chmod(local, nmode)

return local

Expand Down

0 comments on commit 5c3d42c

Please sign in to comment.