From fed7f7ab896113f821a6aabc879aac6d5a0f2416 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sun, 3 Jan 2016 17:42:26 -0500 Subject: [PATCH 1/2] error out if the version of python is old --- pirate/pirate.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pirate/pirate.py b/pirate/pirate.py index 32400a1..f3be04e 100755 --- a/pirate/pirate.py +++ b/pirate/pirate.py @@ -1,3 +1,9 @@ +import sys +from distutils.version import LooseVersion +if LooseVersion(sys.version) < LooseVersion("3.4.0"): + print("Python 3.4.0 required") + sys.exit(1) + import re import os import argparse @@ -6,7 +12,6 @@ import configparser import socket import urllib.request as request import urllib.error -import sys import builtins from collections import OrderedDict From af0c44fe8be912a2a0c8c04f93baeba4b469a4d3 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sun, 3 Jan 2016 18:05:58 -0500 Subject: [PATCH 2/2] test version check --- pirate/pirate.py | 2 +- tests/test_version.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 tests/test_version.py diff --git a/pirate/pirate.py b/pirate/pirate.py index f3be04e..c0052ef 100755 --- a/pirate/pirate.py +++ b/pirate/pirate.py @@ -1,7 +1,7 @@ import sys from distutils.version import LooseVersion if LooseVersion(sys.version) < LooseVersion("3.4.0"): - print("Python 3.4.0 required") + print("At least python 3.4.0 required. Your version is "+sys.version) sys.exit(1) import re diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100755 index 0000000..8894e8d --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +import sys +import unittest +import importlib +from unittest import mock +from unittest.mock import patch, call, MagicMock + +import pirate.pirate + +class TestPirate(unittest.TestCase): + + @patch('sys.exit') + def test_unsupported(self, mock_exit): + sys.version = '3.2.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' + importlib.reload(pirate.pirate) + mock_exit.assert_called_once_with(1) + + @patch('sys.exit') + def test_unsupported2(self, mock_exit): + sys.version = '2.5.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' + importlib.reload(pirate.pirate) + mock_exit.assert_called_once_with(1) + + + @patch('sys.exit') + def test_supported(self, mock_exit): + sys.version = '3.5.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' + importlib.reload(pirate.pirate) + mock_exit.assert_not_called() + + @patch('sys.exit') + def test_supported_exact(self, mock_exit): + sys.version = '3.4.0 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' + importlib.reload(pirate.pirate) + mock_exit.assert_not_called() + +if __name__ == '__main__': + unittest.main()