Revised package util tests

The package util tests were revised to pull the external library
pyhelloworld3 from an internal source rather than external. This speeds
up tests, makes tests more reliable, and removes dependency on internet
connection.
This commit is contained in:
Ryan Kraus 2016-01-30 14:08:32 -05:00
parent de61bcb80e
commit 4a8f55e630
2 changed files with 28 additions and 25 deletions

Binary file not shown.

View File

@ -1,16 +1,20 @@
""" """
Tests Home Assistant package util methods. Tests Home Assistant package util methods.
""" """
import unittest import os
import sys
import tempfile import tempfile
import unittest
import homeassistant.bootstrap as bootstrap
import homeassistant.util.package as package import homeassistant.util.package as package
RESOURCE_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'resources'))
TEST_EXIST_REQ = "pip>=7.0.0" TEST_EXIST_REQ = "pip>=7.0.0"
TEST_NEW_REQ = "pyhelloworld3==1.0.0" TEST_NEW_REQ = "pyhelloworld3==1.0.0"
TEST_ZIP_REQ = \ TEST_ZIP_REQ = 'file://{}#{}' \
"https://github.com/rmkraus/pyhelloworld3/archive/" \ .format(os.path.join(RESOURCE_DIR, 'pyhelloworld3.zip'), TEST_NEW_REQ)
"5ba878316d68ea164e2cf5bd085d0cf1fd76bd15.zip#pyhelloworld3==1.0.0"
class TestPackageUtil(unittest.TestCase): class TestPackageUtil(unittest.TestCase):
@ -18,41 +22,40 @@ class TestPackageUtil(unittest.TestCase):
def setUp(self): def setUp(self):
""" Create local library for testing """ """ Create local library for testing """
self.lib_dir = tempfile.TemporaryDirectory() self.tmp_dir = tempfile.TemporaryDirectory()
self.lib_dir = os.path.join(self.tmp_dir.name, 'lib')
def tearDown(self): def tearDown(self):
""" Remove local library """ """ Remove local library """
del self.lib_dir del self.tmp_dir
def test_install_existing_package(self): def test_install_existing_package(self):
""" Test an install attempt on an existing package """ """ Test an install attempt on an existing package """
self.assertTrue(package.check_package_exists( self.assertTrue(package.check_package_exists(
TEST_EXIST_REQ, self.lib_dir.name)) TEST_EXIST_REQ, self.lib_dir))
self.assertTrue(package.install_package(TEST_EXIST_REQ)) self.assertTrue(package.install_package(TEST_EXIST_REQ))
def test_install_package_locally(self):
""" Test an install attempt to the local library """
self.assertFalse(package.check_package_exists(
TEST_NEW_REQ, self.lib_dir.name))
self.assertTrue(package.install_package(
TEST_NEW_REQ, True, self.lib_dir.name))
sys.path.insert(0, self.lib_dir.name)
import pyhelloworld3
self.assertEqual(pyhelloworld3.__version__, '1.0.0')
def test_install_package_zip(self): def test_install_package_zip(self):
""" Test an install attempt from a zip path """ """ Test an install attempt from a zip path """
self.assertFalse(package.check_package_exists( self.assertFalse(package.check_package_exists(
TEST_ZIP_REQ, self.lib_dir.name)) TEST_ZIP_REQ, self.lib_dir))
self.assertFalse(package.check_package_exists(
TEST_NEW_REQ, self.lib_dir))
self.assertTrue(package.install_package( self.assertTrue(package.install_package(
TEST_ZIP_REQ, True, self.lib_dir.name)) TEST_ZIP_REQ, True, self.lib_dir))
sys.path.insert(0, self.lib_dir.name) self.assertTrue(package.check_package_exists(
import pyhelloworld3 TEST_ZIP_REQ, self.lib_dir))
self.assertTrue(package.check_package_exists(
TEST_NEW_REQ, self.lib_dir))
bootstrap.mount_local_lib_path(self.tmp_dir.name)
try:
import pyhelloworld3
except ImportError:
self.fail('Unable to import pyhelloworld3 after installing it.')
self.assertEqual(pyhelloworld3.__version__, '1.0.0') self.assertEqual(pyhelloworld3.__version__, '1.0.0')