zuul-jobs/roles/tox/library/test_tox_install_sibling_packages.py
Clark Boylan f418a8d533 Fix python3 compat in tox siblings handling
This fixes a byte vs str problem on python3 in the tox role's sibling
library.

As part of this fix add unit testing of the function that was failing
under python3 and functional testing of the role that covers siblings.

Change-Id: I2df4ddce91dfd53f5c4177a19288e97120bc3e3b
2019-12-10 15:27:41 -08: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): Zuul should be installed in this virtualenv
# but this might fail later if we stop adding Zuul
# in the unit tests.
self.assertIn("zuul", 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): Zuul should be installed in this virtualenv
# but this might fail later if we stop adding Zuul
# 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("zuul", s)
self.assertIn("doesnotexistonpypi", s)