diff --git a/.travis.yml b/.travis.yml index f4a51ed..066caa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: python jobs: include: + - os: linux + python: 2.7 + env: TOXENV=py27 + - os: linux python: 3.5 env: TOXENV=py35 @@ -22,6 +26,10 @@ jobs: python: 3.9 env: TOXENV=py39 + - os: linux + python: 3.10-dev + env: TOXENV=py310 + # Install the required packages not included in the standard distribution. install: pip install --no-cache-dir --upgrade tox diff --git a/notebook_environments.py b/notebook_environments.py index 0926bd9..314dcbd 100755 --- a/notebook_environments.py +++ b/notebook_environments.py @@ -8,9 +8,7 @@ import argparse import base64 -import binascii import collections -import contextlib import errno import glob import io @@ -264,10 +262,8 @@ def _write_python_logos(path): for logo_name, logo_image in logos_spec.items(): try: with io.open(os.path.join(path, logo_name), mode="wb") as stream_out: - # Skip this step when an unexpected error has occurred. - with contextlib.suppress(binascii.Error): - # Create a new python logo on the current machine. - stream_out.write(base64.b64decode(logo_image)) + # Create a new python logo on the current machine. + stream_out.write(base64.b64decode(logo_image)) except (IOError, OSError) as err: _logger.error("It's impossible to create python logos on the current machine.") _logger.debug("An unexpected error occurred at this program runtime:", exc_info=True) @@ -369,8 +365,8 @@ def initialize_new_notebook_environment(): try: from jupyter_core.paths import jupyter_path # noqa except ImportError: - def jupyter_path(path): # this function is to return a list - return [_get_data_path(path)] + def jupyter_path(subdirs): # this function is to return a list + return [_get_data_path(subdirs)] # Find and remove all python kernels from the working notebook server. for path in jupyter_path("kernels"): diff --git a/notebook_environments_test.py b/notebook_environments_test.py index 67b3caa..67caddd 100755 --- a/notebook_environments_test.py +++ b/notebook_environments_test.py @@ -14,12 +14,17 @@ import subprocess import sys import unittest -import unittest.mock as mock +import six from pyfakefs.fake_filesystem_unittest import TestCase import notebook_environments +try: + import unittest.mock as mock +except ImportError: + import mock + class SysMock(object): @@ -85,8 +90,13 @@ def setUp(self): json.dump(kernel_spec, stream_out) def tearDown(self): - # Remove all the fake python kernels after the each test case from the current machine. - self.fs.remove_object(self.data_path) + if os.path.exists(self.data_path): + # Remove all the fake python kernels after the each test case from the current machine. + self.fs.remove_object(self.data_path) + + def _assertCountEqual(self, *args, **kwargs): + # An unordered sequence comparison asserting that the same elements. + return six.assertCountEqual(self, *args, **kwargs) @mock.patch.dict("notebook_environments.os.environ", {}, clear=True) def test_virtual_environment_active(self, sys_mock): @@ -194,7 +204,7 @@ def test_get_kernel_name_error(self, logger_mock, basename_mock, sys_mock): def test_list_kernels_in(self, sys_mock): sys_mock.deactivate() - self.assertCountEqual( + self._assertCountEqual( # for python2 and python3 list(notebook_environments._list_kernels_in(self.data_path)), [ notebook_environments._kernel_info(os.path.basename(kernel_path), kernel_path) @@ -242,7 +252,7 @@ def test_write_python_logos(self, logger_mock, sys_mock): self.assertTrue(os.path.isfile(os.path.join(self.data_path, "logo-32x32.png"))) self.assertTrue(os.path.isfile(os.path.join(self.data_path, "logo-64x64.png"))) - with mock.patch("notebook_environments.io.open", new=mock.mock_open()) as open_mock: + with mock.patch("notebook_environments.io.open") as open_mock: # Raise an operating system exception to test a function fault tolerance. open_mock.side_effect = OSError(errno.EPERM, "") @@ -318,7 +328,7 @@ def test_write_kernel_specification(self, logger_mock, sys_mock): # Check the correctness of the current settings for the installed kernel system. self.assertEqual(json.load(stream_in), kernel_spec) - with mock.patch("notebook_environments.io.open", new=mock.mock_open()) as open_mock: + with mock.patch("notebook_environments.io.open") as open_mock: # Raise an operating system exception to test a function fault tolerance. open_mock.side_effect = OSError(errno.EPERM, "") @@ -531,7 +541,7 @@ def test_remove_dead_kernels_error(self, logger_mock, list_kernels_in_mock, sys_ def test_check_and_remove_broken_kernel(self, remove_dir_mock, sys_mock): sys_mock.deactivate() - with mock.patch("notebook_environments.io.open", new=mock.mock_open()) as open_mock: + with mock.patch("notebook_environments.io.open") as open_mock: # Raise an operating system exception to test a function fault tolerance. open_mock.side_effect = OSError(errno.EPERM, "") diff --git a/setup.py b/setup.py index a7dd597..ac11483 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ "Source code": "https://github.com/vladpunko/notebook-environments", }, - python_requires=">=3.0", # this package is to work on python version 2.7 or later + python_requires=">=2.7", # this package is to work on python version 2.7 or later platforms=["macOS", "POSIX"], py_modules=["notebook_environments"], classifiers=[ @@ -58,14 +58,15 @@ "Operating System :: MacOS :: MacOS X", "Operating System :: POSIX", - # "Programming Language :: Python :: 2", - # "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities", diff --git a/tox.ini b/tox.ini index 2400cc1..b0a75da 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35, py36, py37, py38, py39 +envlist = py{27,35,36,37,38,39,310} # Ignore errors related to absence of some python interpreters on the current machine. skip_missing_interpreters = true @@ -8,9 +8,12 @@ skip_missing_interpreters = true commands = pytest --cov --verbose notebook_environments_test.py deps = jupyter-core - pyfakefs<4.5.0 # mock the python file system modules + mock pytest pytest-cov + six + py{27,35}: pyfakefs<4.5.0 # mock the python file system modules for some previous interpreter versions + py{36,37,38,39,310}: pyfakefs [testenv:lint] commands = python -m pre_commit run --all-files --config .githooks.yml