Commit a9350f32 authored by idle sign's avatar idle sign

`read_configuration` now chdirs and tests for file.

parent 43af23dc
......@@ -5,7 +5,7 @@ import sys
from collections import defaultdict
from functools import partial
from distutils.errors import DistutilsOptionError
from distutils.errors import DistutilsOptionError, DistutilsFileError
from setuptools.py26compat import import_module
from setuptools.extern.six import string_types
......@@ -23,6 +23,15 @@ def read_configuration(filepath, find_others=False):
"""
from setuptools.dist import Distribution, _Distribution
filepath = os.path.abspath(filepath)
if not os.path.isfile(filepath):
raise DistutilsFileError(
'Configuration file %s does not exist.' % filepath)
current_directory = os.getcwd()
os.chdir(os.path.dirname(filepath))
dist = Distribution()
filenames = dist.find_config_files() if find_others else []
......@@ -33,6 +42,8 @@ def read_configuration(filepath, find_others=False):
handlers = parse_configuration(dist, dist.command_options)
os.chdir(current_directory)
return configuration_to_dict(handlers)
......
import contextlib
import pytest
from distutils.errors import DistutilsOptionError
from distutils.errors import DistutilsOptionError, DistutilsFileError
from setuptools.dist import Distribution
from setuptools.config import ConfigHandler, read_configuration
......@@ -69,6 +69,10 @@ class TestConfigurationReader:
assert config_dict['metadata']['keywords'] == ['one', 'two']
assert config_dict['options']['scripts'] == ['bin/a.py', 'bin/b.py']
def test_no_config(self, tmpdir):
with pytest.raises(DistutilsFileError):
read_configuration('%s' % tmpdir.join('setup.cfg'))
class TestMetadata:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment