Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tomli test case for different python versions #48

Merged
merged 2 commits into from Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pyproject.toml
Expand Up @@ -21,7 +21,10 @@ task = 'taskipy.cli:main'

[tool.poetry.dependencies]
python = "^3.6"
tomli = "^1.2.3"
tomli = [
{ version = "^2.0.1", python = "^3.7" },
{ version = "^1.2.3", python = "~3.6" }
]
psutil = "^5.7.2"
mslex = { version = "^0.3.0", markers = "sys_platform == 'win32'" }
colorama = "^0.4.4"
Expand Down
49 changes: 49 additions & 0 deletions tests/test_tomli_install.py
@@ -0,0 +1,49 @@
import subprocess
import sys
import unittest
from typing import Dict, List, Tuple


class TomliInstallTestCase(unittest.TestCase):
def test_correct_tomli_version_installed(self):
python_major, python_minor = self.__get_current_python_version()
packages = self.__get_installed_pip_packages()
tomli_version = packages.get('tomli')
v1_regex = r'1.[0-9]+.[0-9]+'
v2_regex = r'2.[0-9]+.[0-9]+'

if python_major == 3 and python_minor == 6:
self.assertRegex(tomli_version, v1_regex)
elif python_major == 3 and python_minor >= 7:
self.assertRegex(tomli_version, v2_regex)
else:
self.fail("Executed with invalid Python version")

def __get_current_python_version(self) -> Tuple[int, int]:
python_version = sys.version_info

return python_version.major, python_version.minor

def __get_installed_pip_packages(self) -> Dict[str, str]:
cmd = "pip list"
process = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, _ = process.communicate()
exit_code = process.returncode
if exit_code != 0:
raise RuntimeError(
'listing pip packages got a non-zero exit code'
)

result = {}
packages = self.__remove_pip_list_table_header(stdout.splitlines())
for package in packages:
decoded_package = package.decode('utf-8')
name, version = decoded_package.split()
result[name] = version

return result

def __remove_pip_list_table_header(self, lines: List[bytes]) -> List[bytes]:
return lines[2:]