Commit b73891f8 authored by idle sign's avatar idle sign Committed by Jason R. Coombs

config tests refactored.

parent 56dea7f0
......@@ -9,6 +9,13 @@ class ErrConfigHandler(ConfigHandler):
"""Erroneous handler. Fails to implement required methods."""
def make_package_dir(name, base_dir):
dir_package = base_dir.mkdir(name)
init_file = dir_package.join('__init__.py')
init_file.write('')
return dir_package, init_file
def fake_env(tmpdir, setup_cfg, setup_py=None):
if setup_py is None:
......@@ -18,11 +25,12 @@ def fake_env(tmpdir, setup_cfg, setup_py=None):
)
tmpdir.join('setup.py').write(setup_py)
tmpdir.join('setup.cfg').write(setup_cfg)
config = tmpdir.join('setup.cfg')
config.write(setup_cfg)
package_dir, init_file = make_package_dir('fake_package', tmpdir)
package_name = 'fake_package'
dir_package = tmpdir.mkdir(package_name)
dir_package.join('__init__.py').write(
init_file.write(
'VERSION = (1, 2, 3)\n'
'\n'
'VERSION_MAJOR = 1'
......@@ -31,6 +39,7 @@ def fake_env(tmpdir, setup_cfg, setup_py=None):
' return [3, 4, 5, "dev"]\n'
'\n'
)
return package_dir, config
@contextlib.contextmanager
......@@ -55,7 +64,7 @@ def test_parsers_implemented():
class TestConfigurationReader:
def test_basic(self, tmpdir):
fake_env(
_, config = fake_env(
tmpdir,
'[metadata]\n'
'version = 10.1.1\n'
......@@ -64,7 +73,7 @@ class TestConfigurationReader:
'[options]\n'
'scripts = bin/a.py, bin/b.py\n'
)
config_dict = read_configuration('%s' % tmpdir.join('setup.cfg'))
config_dict = read_configuration('%s' % config)
assert config_dict['metadata']['version'] == '10.1.1'
assert config_dict['metadata']['keywords'] == ['one', 'two']
assert config_dict['options']['scripts'] == ['bin/a.py', 'bin/b.py']
......@@ -74,17 +83,17 @@ class TestConfigurationReader:
read_configuration('%s' % tmpdir.join('setup.cfg'))
def test_ignore_errors(self, tmpdir):
fake_env(
_, config = fake_env(
tmpdir,
'[metadata]\n'
'version = attr: none.VERSION\n'
'keywords = one, two\n'
)
with pytest.raises(ImportError):
read_configuration('%s' % tmpdir.join('setup.cfg'))
read_configuration('%s' % config)
config_dict = read_configuration(
'%s' % tmpdir.join('setup.cfg'), ignore_option_errors=True)
'%s' % config, ignore_option_errors=True)
assert config_dict['metadata']['keywords'] == ['one', 'two']
assert 'version' not in config_dict['metadata']
......@@ -188,7 +197,7 @@ class TestMetadata:
def test_version(self, tmpdir):
fake_env(
_, config = fake_env(
tmpdir,
'[metadata]\n'
'version = attr: fake_package.VERSION\n'
......@@ -196,14 +205,14 @@ class TestMetadata:
with get_dist(tmpdir) as dist:
assert dist.metadata.version == '1.2.3'
tmpdir.join('setup.cfg').write(
config.write(
'[metadata]\n'
'version = attr: fake_package.get_version\n'
)
with get_dist(tmpdir) as dist:
assert dist.metadata.version == '3.4.5.dev'
tmpdir.join('setup.cfg').write(
config.write(
'[metadata]\n'
'version = attr: fake_package.VERSION_MAJOR\n'
)
......@@ -214,7 +223,7 @@ class TestMetadata:
subpack.join('__init__.py').write('')
subpack.join('submodule.py').write('VERSION = (2016, 11, 26)')
tmpdir.join('setup.cfg').write(
config.write(
'[metadata]\n'
'version = attr: fake_package.subpackage.submodule.VERSION\n'
)
......@@ -250,7 +259,7 @@ class TestMetadata:
])
# From file.
fake_env(
_, config = fake_env(
tmpdir,
'[metadata]\n'
'classifiers = file: classifiers\n'
......@@ -265,7 +274,7 @@ class TestMetadata:
assert set(dist.metadata.classifiers) == expected
# From section.
tmpdir.join('setup.cfg').write(
config.write(
'[metadata.classifiers]\n'
'Framework :: Django\n'
'Programming Language :: Python :: 3.5\n'
......@@ -454,7 +463,7 @@ class TestOptions:
}
def test_entry_points(self, tmpdir):
fake_env(
_, config = fake_env(
tmpdir,
'[options.entry_points]\n'
'group1 = point1 = pack.module:func, '
......@@ -479,7 +488,7 @@ class TestOptions:
tmpdir.join('entry_points').write(expected)
# From file.
tmpdir.join('setup.cfg').write(
config.write(
'[options]\n'
'entry_points = file: entry_points\n'
)
......
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