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