-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "initial_id", | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import unittest\n", | ||
"from platform import python_version\n", | ||
"import importlib\n", | ||
"import toml\n", | ||
"\n", | ||
"def parse_pyproject_toml():\n", | ||
" with open('pyproject.toml', 'r') as file:\n", | ||
" pyproject_data = toml.load(file)\n", | ||
"\n", | ||
" dependencies = pyproject_data.get('tool', {}).get('poetry', {}).get('dependencies', {})\n", | ||
" dependencies.pop('python', None)\n", | ||
"\n", | ||
" return dependencies\n", | ||
"\n", | ||
"def parse_poetry_lock():\n", | ||
" with open('poetry.lock', 'r') as file:\n", | ||
" lock_data = toml.load(file)\n", | ||
"\n", | ||
" dependencies = {}\n", | ||
" for package in lock_data.get('package', []):\n", | ||
" name = package['name']\n", | ||
" version = package['version']\n", | ||
" dependencies[name] = version\n", | ||
"\n", | ||
" return dependencies\n", | ||
"\n", | ||
"def parse_python_version():\n", | ||
" with open('.python-version', 'r') as file:\n", | ||
" python_version = file.read()\n", | ||
" file.close()\n", | ||
"\n", | ||
" return python_version\n", | ||
"\n", | ||
"def get_major_minor(s):\n", | ||
" return '.'.join(s.split('.')[:2])\n", | ||
"\n", | ||
"class CommonTests(unittest.TestCase):\n", | ||
" def test_python_version(self):\n", | ||
" expected_major_minor = parse_python_version()\n", | ||
" actual_major_minor = get_major_minor(python_version())\n", | ||
" self.assertEqual(actual_major_minor, expected_major_minor, \"incorrect python version\")\n", | ||
"\n", | ||
" def test_dependencies_versions(self):\n", | ||
" direct_dependencies_map = parse_pyproject_toml()\n", | ||
" all_dependencies_map = parse_poetry_lock()\n", | ||
"\n", | ||
" for package, defined_version in direct_dependencies_map.items():\n", | ||
" expected_version = all_dependencies_map[package]\n", | ||
" installed_version = importlib.metadata.version(package)\n", | ||
" self.assertEqual(installed_version, expected_version, f\"incorrect {package} version\")\n", | ||
"\n", | ||
"unittest.main(argv=[''], verbosity=2, exit=False)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |