Remove bad parameter for cfg.get
when loading from cfg file, cfg.get takes just 2 parameters not three. Added some basic tests and test for the specific change as well Change-Id: I633d665f63271b6ada9196a0f08028d404b33110
This commit is contained in:
parent
1e0afa3168
commit
ed1e27faa1
@ -169,9 +169,9 @@ class VersionInfo(object):
|
||||
if project_name.startswith('python-'):
|
||||
project_name = project_name[7:]
|
||||
|
||||
self._vendor = cfg.get(project_name, "vendor", self._vendor)
|
||||
self._product = cfg.get(project_name, "product", self._product)
|
||||
self._suffix = cfg.get(project_name, "package", self._suffix)
|
||||
self._vendor = cfg.get(project_name, "vendor")
|
||||
self._product = cfg.get(project_name, "product")
|
||||
self._suffix = cfg.get(project_name, "package")
|
||||
|
||||
def _load_vendor_strings(self):
|
||||
"""Load default and override vendor strings.
|
||||
|
@ -2,6 +2,7 @@ coverage>=3.6
|
||||
discover
|
||||
fixtures>=0.3.12
|
||||
flake8==2.0
|
||||
mock>=1.0
|
||||
python-subunit
|
||||
oslo.sphinx
|
||||
sphinx>=1.1.2
|
||||
|
@ -22,6 +22,7 @@ __all__ = [
|
||||
]
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import fixtures
|
||||
import testresources
|
||||
@ -53,3 +54,24 @@ class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase):
|
||||
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
||||
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
|
||||
@staticmethod
|
||||
def write_to_tempfile(content, suffix='', prefix='tmp'):
|
||||
"""Create temporary file or use existing file.
|
||||
|
||||
This util is needed for creating temporary file with
|
||||
specified content, suffix and prefix.
|
||||
|
||||
:param content: content for temporary file.
|
||||
:param suffix: same as parameter 'suffix' for mkstemp
|
||||
:param prefix: same as parameter 'prefix' for mkstemp
|
||||
|
||||
For example: it can be used in database tests for creating
|
||||
configuration files.
|
||||
"""
|
||||
(fd, path) = tempfile.mkstemp(suffix=suffix, prefix=prefix)
|
||||
try:
|
||||
os.write(fd, content.encode('utf-8'))
|
||||
finally:
|
||||
os.close(fd)
|
||||
return path
|
||||
|
@ -18,6 +18,7 @@
|
||||
import os
|
||||
|
||||
import fixtures
|
||||
import mock
|
||||
|
||||
from oslo.version import version
|
||||
import tests
|
||||
@ -46,3 +47,40 @@ class FindConfigFilesTestCase(tests.BaseTestCase):
|
||||
self.assertEqual(config_files,
|
||||
version._find_config_files(project='blaa',
|
||||
extension='.json'))
|
||||
|
||||
|
||||
class BasicVersionTestCase(tests.BaseTestCase):
|
||||
|
||||
def test_version(self):
|
||||
with mock.patch.object(version.VersionInfo,
|
||||
'_get_version_from_pkg_resources',
|
||||
return_value='5.5.5.5'):
|
||||
v = version.VersionInfo(None)
|
||||
self.assertEqual(v.version, '5.5.5.5')
|
||||
|
||||
def test_version_and_release(self):
|
||||
with mock.patch.object(version.VersionInfo,
|
||||
'_get_version_from_pkg_resources',
|
||||
return_value='0.5.21.28.gae25b56'):
|
||||
v = version.VersionInfo(None)
|
||||
self.assertEqual(v.release, '0.5.21.28.gae25b56')
|
||||
self.assertEqual(v.version, '0.5.21.28')
|
||||
|
||||
def test_vendor(self):
|
||||
with mock.patch.multiple(version.VersionInfo,
|
||||
_get_provider=mock.DEFAULT,
|
||||
_load_from_pkg_info=mock.DEFAULT,
|
||||
_load_from_setup_cfg=mock.DEFAULT):
|
||||
path = self.write_to_tempfile("""[myfoo]
|
||||
vendor=bigco
|
||||
product=product123
|
||||
package=mysuffix
|
||||
""")
|
||||
with mock.patch.object(version,
|
||||
'_find_config_files',
|
||||
return_value=path):
|
||||
v = version.VersionInfo('myfoo')
|
||||
self.assertEqual('myfoo', v.package)
|
||||
self.assertEqual('bigco', v.vendor)
|
||||
self.assertEqual('product123', v.product)
|
||||
self.assertEqual('mysuffix', v.suffix)
|
||||
|
Loading…
Reference in New Issue
Block a user