netdevops / hier_config

Hierarchical Configuration
MIT License
126 stars 24 forks source link

test_load_from_file Fails with PermissionError on temp file #75

Closed robobeaver6 closed 3 years ago

robobeaver6 commented 4 years ago

Python 3.7 On Windows 10 Fresh git Fork and Clone of netdevops / hier_config

When I run the Unit Tests I get one failure

Testing started at 22:19 ...
C:\Users\Rich\.virtualenvs\hier_config-UnGuqua-\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\helpers\pycharm\_jb_unittest_runner.py" --path C:/Users/Rich/PycharmProjects/hier_config/tests
Launching unittests with arguments python -m unittest discover -s C:/Users/Rich/PycharmProjects/hier_config/tests -t C:\Users\Rich\PycharmProjects\hier_config\tests in C:\Users\Rich\PycharmProjects\hier_config\tests

C:\Users\Rich\.virtualenvs\hier_config-UnGuqua-\lib\site-packages\pep8.py:110: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')

Error
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python37-32\Lib\unittest\case.py", line 59, in testPartExecutor
    yield
  File "C:\Program Files (x86)\Python37-32\Lib\unittest\case.py", line 615, in run
    testMethod()
  File "C:\Users\Rich\PycharmProjects\hier_config\tests\test_hier_config.py", line 69, in test_load_from_file
    hier.load_from_file(myfile.name)
  File "C:\Users\Rich\PycharmProjects\hier_config\hier_config\hconfig.py", line 141, in load_from_file
    with open(file_path) as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Rich\\AppData\\Local\\Temp\\tmpv_hmd0_7'

C:\Users\Rich\PycharmProjects\hier_config\tests\test_host.py:32: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  cls.hconfig_tags = yaml.load(open(cls.tags_file))
C:\Users\Rich\PycharmProjects\hier_config\tests\test_host.py:32: ResourceWarning: unclosed file <_io.TextIOWrapper name='C:\\Users\\Rich\\PycharmProjects\\hier_config\\tests\\files\\test_tags_ios.yml' mode='r' encoding='cp1252'>
  cls.hconfig_tags = yaml.load(open(cls.tags_file))
C:\Users\Rich\PycharmProjects\hier_config\tests\test_host.py:33: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  cls.hconfig_options = yaml.load(open(cls.options_file))
C:\Users\Rich\PycharmProjects\hier_config\tests\test_host.py:33: ResourceWarning: unclosed file <_io.TextIOWrapper name='C:\\Users\\Rich\\PycharmProjects\\hier_config\\tests\\files\\test_options_ios.yml' mode='r' encoding='cp1252'>
  cls.hconfig_options = yaml.load(open(cls.options_file))

Ran 60 tests in 0.073s

FAILED (errors=1)

Process finished with exit code 1

The temp File is created and the contents are written to it, I am unable to open it manually, The security permissions show as full access for my user. If I copy the file, I can open the copy and inspect the contents. It appears to be a lock issue, unique to Windows. It is discussed here: https://bugs.python.org/issue14243

The Fix would be to close the file before calling load_from_file, then manually clean up