zuul-jobs/roles/tox/library/test_tox_install_sibling_packages.py
Monty Taylor d36ba50765 Fix unittests for python2 and fedora
We need to pin enum34 on python2 because upstream broke it.

Also, we should not install zuul in python2, because it's not targetted
at python2. It's only here so that linters can deal with zuul_return
and other things from its library, so it should be fine to not install
it for python2 unittests.

GitPython was in here as a pin to the versions that support python3
for zuul. Since we're constraining zuul to only python3, we don't need
to mention GitPython at all.

Update the siblings unit test to use requests as the package we expect
to be already installed since we're no longer installing zuul for
python2.

Fedora 29 got archived upstream:

  http://mirror.sjc1.vexxhost.openstack.org/fedora/releases/29/README

So we need to switch to fedora 30.

Change-Id: I69e0b03f624ba45889916f89c0912df667aaf096
2020-02-24 10:50:13 -06:00

64 lines
2.5 KiB
Python

# Copyright (C) 2019 VEXXHOST, Inc.
#
# 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.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import sys
import testtools
from .tox_install_sibling_packages import get_installed_packages
from .tox_install_sibling_packages import write_new_constraints_file
class TestToxInstallSiblingPackages(testtools.TestCase):
def test_get_installed_packages(self):
# NOTE(mnaser): Given that we run our tests inside Tox, we can
# leverage the tox virtual environment we use in
# unit tests instead of mocking up everything.
pkgs = get_installed_packages(sys.executable)
# NOTE(mnaser): requests should be installed in this virtualenv
# but this might fail later if we stop adding requests
# in the unit tests.
self.assertIn("requests", pkgs)
def test_write_new_constraints_file(self):
# NOTE(mnaser): Given that we run our tests inside Tox, we can
# leverage the tox virtual environment we use in
# unit tests instead of mocking up everything.
pkgs = get_installed_packages(sys.executable)
# NOTE(mnaser): requests should be installed in this virtualenv
# but this might fail later if we stop adding requests
# in the unit tests.
test_constraints = os.path.join(os.path.dirname(__file__),
'test-constraints.txt')
constraints = write_new_constraints_file(test_constraints, pkgs)
def cleanup_constraints_file():
if os.path.exists(constraints):
os.unlink(constraints)
self.addCleanup(cleanup_constraints_file)
self.assertTrue(os.path.exists(constraints))
with open(constraints) as f:
s = f.read()
self.assertNotIn("requests", s)
self.assertIn("doesnotexistonpypi", s)