Skip to content

Commit

Permalink
Merge pull request #1860 from eli-schwartz/unittest-mock
Browse files Browse the repository at this point in the history
switch from mock to the stdlib unittest.mock
  • Loading branch information
swryan committed Jan 28, 2021
2 parents 93c806e + fc0e1d9 commit 471a624
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 30 deletions.
8 changes: 2 additions & 6 deletions openmdao/devtools/docs_experiment/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext

#first item in makefile is default action of "make"
html-update: mock redbaron
html-update: redbaron
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html

single:
Expand All @@ -42,15 +42,11 @@ clean:
rm -rf tags
rm -rf tmp

mock:
@(python -c "import mock" >/dev/null 2>&1) || (echo "The 'mock' package \
is required to build the docs. Install with:\n pip install mock"; exit 1)

redbaron:
@(python -c "import redbaron" >/dev/null 2>&1) || (echo "The 'redbaron' package \
is required to build the docs. Install with:\n pip install redbaron"; exit 1)

all: mock redbaron
all: redbaron
# Cleaning up previously-generated files before docbuild
rm -rf _srcdocs/*

Expand Down
2 changes: 1 addition & 1 deletion openmdao/devtools/docs_experiment/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import textwrap

from numpydoc.docscrape import NumpyDocString, Reader
from mock import Mock
from unittest.mock import Mock

from openmdao.docs.config_params import MOCK_MODULES
from openmdao.docs._utils.patch import do_monkeypatch
Expand Down
1 change: 0 additions & 1 deletion openmdao/devtools/docs_experiment/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mock==2.0.0
redbaron==0.6.3
networkx==1.11
numpy==1.12.1
Expand Down
10 changes: 3 additions & 7 deletions openmdao/docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(SPHINXOPTS) .

# to remake only recently-changed files, not the entire document base.
# note - first item in makefile is default action of "make"
html-update: mock redbaron matplotlib build
html-update: redbaron matplotlib build

# to force the rebuild a file when its dependecy (e.g. code-embed) changes, not its rst file
single: touch buildone

# build it all over again (note: make all == make html)
all html: make_srcdocs n2html mock redbaron matplotlib tagg buildall post_remove
all html: make_srcdocs n2html redbaron matplotlib tagg buildall post_remove

# build it all on CI machines; all warnings are raised as errors.
travis: make_srcdocs n2html mock redbaron matplotlib tagg buildalltravis post_remove
travis: make_srcdocs n2html redbaron matplotlib tagg buildalltravis post_remove

clean:
rm -rf $(BUILDDIR)/*
Expand Down Expand Up @@ -95,10 +95,6 @@ post_remove:
rm -rf make_sourcedocs

# installation testers
mock:
@(python -c "import mock" >/dev/null 2>&1) || (echo "The 'mock' package \
is required to build the docs. Install with:\n pip install mock"; exit 1)

redbaron:
@(python -c "import redbaron" >/dev/null 2>&1) || (echo "The 'redbaron' package \
is required to build the docs. Install with:\n pip install redbaron"; exit 1)
Expand Down
2 changes: 1 addition & 1 deletion openmdao/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import importlib

from mock import Mock
from unittest.mock import Mock

from openmdao.docs.config_params import MOCK_MODULES
from openmdao.docs._utils.patch import do_monkeypatch
Expand Down
10 changes: 5 additions & 5 deletions openmdao/docs/other/repo_guide/docs_with_sphinx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ can rebuild an .rst file whose embed-code dependency has changed, though the .rs
# to remake only recently-changed files, not the entire document base.
# note - first item in makefile is default action of "make"
html-update: mock redbaron matplotlib build
html-update: redbaron matplotlib build
# to force the rebuild a file when its dependecy (e.g. code-embed) changes, not its rst file
single: mock redbaron matplotlib touch build
single: redbaron matplotlib touch build
# build it all over again (note: make all == make html)
all html: make_srcdocs mock redbaron matplotlib tagg buildall post_remove
all html: make_srcdocs redbaron matplotlib tagg buildall post_remove
# build it all on CI machines; all warnings are raised as errors.
travis: make_srcdocs mock redbaron matplotlib tagg buildalltravis post_remove
travis: make_srcdocs redbaron matplotlib tagg buildalltravis post_remove
clean:
rm -rf $(BUILDDIR)/*
Expand Down Expand Up @@ -137,4 +137,4 @@ Getting Docs For Your Plugin Transferred to github-pages
--------------------------------------------------------

Once you have your documents organized and building locally, and building without errors on Travis CI, then we can explore transferring those
built docs from Travis to github-pages. This is discussed in detail in the next doc on :ref:`github-pages setup <github_pages>`.
built docs from Travis to github-pages. This is discussed in detail in the next doc on :ref:`github-pages setup <github_pages>`.
2 changes: 1 addition & 1 deletion openmdao/docs/other/repo_guide/travis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ That file looks something like this:
fi
install:
- conda install --yes python=$PY numpy scipy nose sphinx mock swig pip;
- conda install --yes python=$PY numpy scipy nose sphinx swig pip;
- pip install --upgrade pip
- sudo apt-get install gfortran
- pip install numpy==1.14.1
Expand Down
1 change: 0 additions & 1 deletion openmdao/docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mock==2.0.0
redbaron==0.6.3
networkx==1.11
numpy==1.12.1
Expand Down
9 changes: 3 additions & 6 deletions openmdao/utils/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,7 @@ def set_pyoptsparse_opt(optname, fallback=True):
if force:
optname = force

try:
from mock import Mock
except ImportError:
Mock = None
from unittest.mock import Mock

try:
from pyoptsparse import OPT
Expand All @@ -428,7 +425,7 @@ def set_pyoptsparse_opt(optname, fallback=True):
except Exception:
pass
else:
if fallback and Mock and isinstance(opt, Mock):
if fallback and isinstance(opt, Mock):
try:
opt = OPT('SLSQP')
OPTIMIZER = 'SLSQP'
Expand All @@ -437,7 +434,7 @@ def set_pyoptsparse_opt(optname, fallback=True):
except Exception:
pass

if Mock and isinstance(opt, Mock):
if isinstance(opt, Mock):
OPT = OPTIMIZER = None

if not fallback and OPTIMIZER != optname:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
optional_dependencies = {
'docs': [
'matplotlib',
'mock',
'numpydoc>=0.9.1',
'redbaron',
'sphinx>=1.8.5',
Expand Down

0 comments on commit 471a624

Please sign in to comment.