requirements/openstack_requirements/tests/test_edit_constraint.py
Davanum Srinivas 3ebedf84f0 Deal with underscores in names in edit-constraints
Problem showed up with django_openstack_auth job that installs from
source. The change to devstack to verify LIBS_FROM_GIT kicked in
(Iffef2007f99a0e932b68c4c897ebbfb748cac2b4) and starting failing the
job. The problem was that the edit_constraint was not fixing the
django-openstack-auth line in upperconstraints.txt as the setup.cfg
had name = django_openstack_auth. Note that when things finally get
installed setup_tools' safe_name kicks in to standardize names and for
example glance_store will show up as glance-store in pip freeze. So we
should be able to treat this situation better and allow constraints to
have the safe names (using dashes).

Co-Authored-By: Robert Collins <rbtcollins@hp.com>
Change-Id: Ibaa22657a2cf2c0ad96dbd0b9bc43cdafe6a1d56
2015-09-17 10:12:11 +12:00

93 lines
3.3 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import io
import os
import textwrap
import fixtures
import testscenarios
import testtools
from openstack_requirements.cmds import edit_constraint as edit
from openstack_requirements import requirement
load_tests = testscenarios.load_tests_apply_scenarios
class SmokeTest(testtools.TestCase):
def test_make_url(self):
stdout = io.StringIO()
tmpdir = self.useFixture(fixtures.TempDir()).path
constraints_path = os.path.join(tmpdir, 'name.txt')
with open(constraints_path, 'wt') as f:
f.write('bar===1\nfoo===1.0.2\nquux==3\n')
rv = edit.main(
[constraints_path, 'foo', '--', '-e /path/to/foo'], stdout)
self.assertEqual(0, rv)
content = open(constraints_path, 'rt').read()
self.assertEqual('-e /path/to/foo\nbar===1\nquux==3\n', content)
def test_edit_paths(self):
stdout = io.StringIO()
tmpdir = self.useFixture(fixtures.TempDir()).path
constraints_path = os.path.join(tmpdir, 'name.txt')
with open(constraints_path, 'wt') as f:
f.write(textwrap.dedent("""\
file:///path/to/foo#egg=foo
-e file:///path/to/bar#egg=bar
"""))
rv = edit.main(
[constraints_path, 'foo', '--', '-e file:///path/to/foo#egg=foo'],
stdout)
self.assertEqual(0, rv)
content = open(constraints_path, 'rt').read()
self.assertEqual(textwrap.dedent("""\
-e file:///path/to/foo#egg=foo
-e file:///path/to/bar#egg=bar
"""), content)
class TestEdit(testtools.TestCase):
def test_add(self):
reqs = {}
res = edit.edit(reqs, 'foo', 'foo==1.2')
self.assertEqual(requirement.Requirements(
[requirement.Requirement('', '', '', '', 'foo==1.2')]), res)
def test_delete(self):
reqs = requirement.parse('foo==1.2\n')
res = edit.edit(reqs, 'foo', '')
self.assertEqual(requirement.Requirements([]), res)
def test_replace(self):
reqs = requirement.parse('foo==1.2\n')
res = edit.edit(reqs, 'foo', 'foo==1.3')
self.assertEqual(requirement.Requirements(
[requirement.Requirement('', '', '', '', 'foo==1.3')]), res)
def test_replace_many(self):
reqs = requirement.parse('foo==1.2;p\nfoo==1.3;q')
res = edit.edit(reqs, 'foo', 'foo==1.3')
self.assertEqual(requirement.Requirements(
[requirement.Requirement('', '', '', '', 'foo==1.3')]), res)
def test_replace_non_canonical(self):
new_req = '-e file:///path#egg=foo_baz'
reqs = requirement.parse("foo-baz===1.0.2\n")
res = edit.edit(reqs, 'foo_baz', new_req)
self.assertEqual(res, requirement.Requirements(
[requirement.Requirement('', '', '', '', new_req)]))