84 lines
3.1 KiB
Python
Raw Normal View History

# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 IBM Corp.
#
# 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 os
import os.path
import shutil
import subprocess
import sys
import tempfile
import testtools
def _load_req(fname):
with open(fname) as f:
content = map(lambda x: x.rstrip(), f.readlines())
print content
return content
class UpdateTest(testtools.TestCase):
def setUp(self):
super(UpdateTest, self).setUp()
self.dir = tempfile.mkdtemp()
self.project_dir = os.path.join(self.dir, "project")
self.oslo_dir = os.path.join(self.dir, "project_with_oslo")
self.req_file = os.path.join(self.dir, "global-requirements.txt")
self.proj_file = os.path.join(self.project_dir, "requirements.txt")
self.oslo_file = os.path.join(self.oslo_dir, "requirements.txt")
self.proj_test_file = os.path.join(self.project_dir,
"test-requirements.txt")
os.mkdir(self.project_dir)
os.mkdir(self.oslo_dir)
shutil.copy("tests/files/gr-base.txt", self.req_file)
shutil.copy("tests/files/project-with-oslo-tar.txt", self.oslo_file)
shutil.copy("tests/files/project.txt", self.proj_file)
shutil.copy("tests/files/test-project.txt", self.proj_test_file)
shutil.copy("update.py", os.path.join(self.dir, "update.py"))
# now go call update and see what happens
os.chdir(self.dir)
subprocess.call([sys.executable, "update.py", "project"])
subprocess.call([sys.executable, "update.py", "project_with_oslo"])
def test_requirements(self):
reqs = _load_req(self.req_file)
self.assertIn("jsonschema>=1.0.0,!=1.4.0,<2", reqs)
def test_project(self):
reqs = _load_req(self.proj_file)
# ensure various updates take
self.assertIn("jsonschema>=1.0.0,!=1.4.0,<2", reqs)
self.assertIn("python-keystoneclient>=0.3.0", reqs)
self.assertIn("SQLAlchemy>=0.7,<=0.7.99", reqs)
def test_project_with_oslo(self):
reqs = _load_req(self.oslo_file)
oslo_tar = ("-f http://tarballs.openstack.org/oslo.config/"
"oslo.config-1.2.0a3.tar.gz#egg=oslo.config-1.2.0a3")
self.assertIn(oslo_tar, reqs)
self.assertIn("oslo.config>=1.1.0", reqs)
def test_test_project(self):
reqs = _load_req(self.proj_test_file)
self.assertIn("testtools>=0.9.32", reqs)
self.assertIn("testrepository>=0.0.17", reqs)
# make sure we didn't add something we shouldn't
self.assertNotIn("sphinxcontrib-pecanwsme>=0.2", reqs)