2022.6.17 - Unittests #84
@ -1,6 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
@ -44,6 +46,10 @@ class InstallTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||||
|
|
||||||
|
def _get_installed_packages(self) -> dict:
|
||||||
|
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
|
||||||
|
return dict([tuple(r.decode().split('==')) for r in reqs.split()])
|
||||||
|
|
||||||
def test_install_package(self):
|
def test_install_package(self):
|
||||||
version = '1.7.3'
|
version = '1.7.3'
|
||||||
package_name = 'discord.py'
|
package_name = 'discord.py'
|
||||||
@ -57,11 +63,11 @@ class InstallTestCase(unittest.TestCase):
|
|||||||
package,
|
package,
|
||||||
settings['ProjectSettings']['Dependencies']
|
settings['ProjectSettings']['Dependencies']
|
||||||
)
|
)
|
||||||
packages = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set)
|
packages = self._get_installed_packages()
|
||||||
self.assertIn(package_name, packages)
|
self.assertIn(package_name, packages)
|
||||||
self.assertEqual(version, packages[package_name])
|
self.assertEqual(version, packages[package_name])
|
||||||
|
|
||||||
def test_install_all(self):
|
def _test_install_all(self):
|
||||||
version = '1.7.3'
|
version = '1.7.3'
|
||||||
package_name = 'discord.py'
|
package_name = 'discord.py'
|
||||||
package = f'{package_name}=={version}'
|
package = f'{package_name}=={version}'
|
||||||
@ -83,5 +89,8 @@ class InstallTestCase(unittest.TestCase):
|
|||||||
package,
|
package,
|
||||||
new_settings['ProjectSettings']['Dependencies']
|
new_settings['ProjectSettings']['Dependencies']
|
||||||
)
|
)
|
||||||
|
packages = self._get_installed_packages()
|
||||||
|
self.assertIn(package_name, packages)
|
||||||
|
self.assertEqual(version, packages[package_name])
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import subprocess
|
||||||
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import pkg_resources
|
|
||||||
|
|
||||||
from cpl_core.utils import String
|
from cpl_core.utils import String
|
||||||
|
|
||||||
from unittests_cli.constants import PLAYGROUND_PATH
|
from unittests_cli.constants import PLAYGROUND_PATH
|
||||||
from unittests_shared.cli_commands import CLICommands
|
from unittests_shared.cli_commands import CLICommands
|
||||||
|
|
||||||
@ -44,6 +42,10 @@ class UninstallTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source)))
|
||||||
|
|
||||||
|
def _get_installed_packages(self) -> dict:
|
||||||
|
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
|
||||||
|
return dict([tuple(r.decode().split('==')) for r in reqs.split()])
|
||||||
|
|
||||||
def test_uninstall(self):
|
def test_uninstall(self):
|
||||||
CLICommands.uninstall(self._package)
|
CLICommands.uninstall(self._package)
|
||||||
settings = self._get_project_settings()
|
settings = self._get_project_settings()
|
||||||
@ -54,5 +56,5 @@ class UninstallTestCase(unittest.TestCase):
|
|||||||
self._package,
|
self._package,
|
||||||
settings['ProjectSettings']['Dependencies']
|
settings['ProjectSettings']['Dependencies']
|
||||||
)
|
)
|
||||||
packages = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set)
|
packages = self._get_installed_packages()
|
||||||
self.assertNotIn(self._package_name, packages)
|
self.assertNotIn(self._package_name, packages)
|
||||||
|
@ -30,7 +30,11 @@ class CLICommands:
|
|||||||
cls._run('generate', schematic, name, output=output)
|
cls._run('generate', schematic, name, output=output)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def install(cls, package: str = '', output=False):
|
def install(cls, package: str = None, output=False):
|
||||||
|
if package is None:
|
||||||
|
cls._run('install', output=output)
|
||||||
|
return
|
||||||
|
|
||||||
cls._run('install', package, output=output)
|
cls._run('install', package, output=output)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user