2016-03-09 09:25:50 +00:00
|
|
|
"""Test Home Assistant package util methods."""
|
2016-01-30 19:08:32 +00:00
|
|
|
import os
|
2016-01-30 11:44:22 +00:00
|
|
|
import tempfile
|
2016-01-30 19:08:32 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import homeassistant.bootstrap as bootstrap
|
2016-01-30 11:44:22 +00:00
|
|
|
import homeassistant.util.package as package
|
|
|
|
|
2016-01-30 19:08:32 +00:00
|
|
|
RESOURCE_DIR = os.path.abspath(
|
|
|
|
os.path.join(os.path.dirname(__file__), '..', 'resources'))
|
|
|
|
|
2016-01-30 11:44:22 +00:00
|
|
|
TEST_EXIST_REQ = "pip>=7.0.0"
|
|
|
|
TEST_NEW_REQ = "pyhelloworld3==1.0.0"
|
2016-01-30 19:08:32 +00:00
|
|
|
TEST_ZIP_REQ = 'file://{}#{}' \
|
|
|
|
.format(os.path.join(RESOURCE_DIR, 'pyhelloworld3.zip'), TEST_NEW_REQ)
|
2016-01-30 11:44:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestPackageUtil(unittest.TestCase):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test for homeassistant.util.package module."""
|
2016-01-30 11:44:22 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Create local library for testing."""
|
2016-01-30 19:08:32 +00:00
|
|
|
self.tmp_dir = tempfile.TemporaryDirectory()
|
2016-04-12 03:07:50 +00:00
|
|
|
self.lib_dir = os.path.join(self.tmp_dir.name, 'deps')
|
2016-01-30 11:44:22 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Stop everything that was started."""
|
2016-01-30 19:39:17 +00:00
|
|
|
self.tmp_dir.cleanup()
|
2016-01-30 11:44:22 +00:00
|
|
|
|
|
|
|
def test_install_existing_package(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test an install attempt on an existing package."""
|
2016-01-30 11:44:22 +00:00
|
|
|
self.assertTrue(package.check_package_exists(
|
2016-01-30 19:08:32 +00:00
|
|
|
TEST_EXIST_REQ, self.lib_dir))
|
2016-01-30 11:44:22 +00:00
|
|
|
|
|
|
|
self.assertTrue(package.install_package(TEST_EXIST_REQ))
|
|
|
|
|
|
|
|
def test_install_package_zip(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test an install attempt from a zip path."""
|
2016-01-30 11:44:22 +00:00
|
|
|
self.assertFalse(package.check_package_exists(
|
2016-01-30 19:08:32 +00:00
|
|
|
TEST_ZIP_REQ, self.lib_dir))
|
|
|
|
self.assertFalse(package.check_package_exists(
|
|
|
|
TEST_NEW_REQ, self.lib_dir))
|
2016-01-30 11:44:22 +00:00
|
|
|
|
|
|
|
self.assertTrue(package.install_package(
|
2016-01-30 19:08:32 +00:00
|
|
|
TEST_ZIP_REQ, True, self.lib_dir))
|
|
|
|
|
|
|
|
self.assertTrue(package.check_package_exists(
|
|
|
|
TEST_ZIP_REQ, self.lib_dir))
|
|
|
|
self.assertTrue(package.check_package_exists(
|
|
|
|
TEST_NEW_REQ, self.lib_dir))
|
|
|
|
|
2016-06-27 16:02:45 +00:00
|
|
|
bootstrap._mount_local_lib_path(self.tmp_dir.name)
|
2016-01-30 11:44:22 +00:00
|
|
|
|
2016-01-30 19:08:32 +00:00
|
|
|
try:
|
|
|
|
import pyhelloworld3
|
|
|
|
except ImportError:
|
|
|
|
self.fail('Unable to import pyhelloworld3 after installing it.')
|
2016-01-30 11:44:22 +00:00
|
|
|
|
|
|
|
self.assertEqual(pyhelloworld3.__version__, '1.0.0')
|