"""
@brief      test tree node (time=5s)
"""


import sys
import os
import unittest
import re
import shutil
import warnings

try:
    import src
except ImportError:
    path = os.path.normpath(
        os.path.abspath(
            os.path.join(
                os.path.split(__file__)[0],
                "..",
                "..")))
    if path not in sys.path:
        sys.path.append(path)
    import src

from src.pyquickhelper import fLOG, get_temp_folder, __blog__
from src.pyquickhelper.pycode.code_helper import remove_extra_spaces_and_pep8, remove_extra_spaces_folder
from src.pyquickhelper.pycode.clean_helper import clean_exts


class TestClean(unittest.TestCase):

    def test_pep8(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        this = os.path.abspath(__file__.replace(".pyc", ".py"))
        diff = remove_extra_spaces_and_pep8(this)
        assert diff < 10

    def test_extra_space(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        this = os.path.abspath(os.path.dirname(__file__))
        diff = remove_extra_spaces_folder(this)
        assert isinstance(diff, list)

    def test_clean_exts(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if "Anaconda" in sys.executable:
            # we disable it for Anaconda
            return
        this = os.path.abspath(os.path.dirname(__file__))
        diff = clean_exts(this)
        assert isinstance(diff, list)


if __name__ == "__main__":
    unittest.main()

@@ -1393,32 +1393,180 @@
 == %22__main__%22)%0A%0A
+        this = os.path.abspath(os.path.dirname(__file__))%0A        try:%0A            diff = clean_exts(this)%0A        except PermissionError as e:%0A    
         if %22Anac
@@ -1602,16 +1602,20 @@
         
+    
 # we dis
@@ -1647,16 +1647,20 @@
         
+ 
+   
 return%0A 
@@ -1670,89 +1670,118 @@
     
-this = os.path.abspath(os.path.dirname(__file__))%0A        diff = clean_exts(this)
+    raise Exception(%22unable to clean %22 + this +%0A                            %22%5Cnexe: %22 + sys.executable) from e
 %0A   

update unit tests for Anaconda