diff options
author | James Cammarata <jimi@sngx.net> | 2015-05-03 21:47:26 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2015-05-03 21:47:26 -0500 |
commit | ce3ef7f4c16e47d5a0b5600e1c56c177b7c93f0d (patch) | |
tree | ebb90eaba034dfb4ea8a3afe746a87f9b7dee66f /lib/ansible/compat | |
parent | 8cf4452d48e583cfd59f96e67cfd34a1c35226e7 (diff) | |
download | ansible-ce3ef7f4c16e47d5a0b5600e1c56c177b7c93f0d.tar.gz |
Making the switch to v2
Diffstat (limited to 'lib/ansible/compat')
-rw-r--r-- | lib/ansible/compat/__init__.py | 27 | ||||
-rw-r--r-- | lib/ansible/compat/tests/__init__.py | 40 | ||||
-rw-r--r-- | lib/ansible/compat/tests/mock.py | 38 | ||||
-rw-r--r-- | lib/ansible/compat/tests/unittest.py | 36 |
4 files changed, 141 insertions, 0 deletions
diff --git a/lib/ansible/compat/__init__.py b/lib/ansible/compat/__init__.py new file mode 100644 index 0000000000..e77b77d2a6 --- /dev/null +++ b/lib/ansible/compat/__init__.py @@ -0,0 +1,27 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +''' +Compat library for ansible. This contains compatibility definitions for older python +When we need to import a module differently depending on python version, do it +here. Then in the code we can simply import from compat in order to get what we want. +''' + diff --git a/lib/ansible/compat/tests/__init__.py b/lib/ansible/compat/tests/__init__.py new file mode 100644 index 0000000000..fc05b2549b --- /dev/null +++ b/lib/ansible/compat/tests/__init__.py @@ -0,0 +1,40 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +''' +This module contains things that are only needed for compat in the testsuites, +not in ansible itself. If you are not installing the test suite, you can +safely remove this subdirectory. +''' + +# +# Compat for python2.7 +# + +# One unittest needs to import builtins via __import__() so we need to have +# the string that represents it +try: + import __builtin__ +except ImportError: + BUILTINS = 'builtins' +else: + BUILTINS = '__builtin__' + diff --git a/lib/ansible/compat/tests/mock.py b/lib/ansible/compat/tests/mock.py new file mode 100644 index 0000000000..0614391c4b --- /dev/null +++ b/lib/ansible/compat/tests/mock.py @@ -0,0 +1,38 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +''' +Compat module for Python3.x's unittest.mock module +''' + +# Python 2.7 + +# Note: Could use the pypi mock library on python3.x as well as python2.x. It +# is the same as the python3 stdlib mock library + +try: + from unittest.mock import * +except ImportError: + # Python 2 + try: + from mock import * + except ImportError: + print('You need the mock library installed on python2.x to run tests') diff --git a/lib/ansible/compat/tests/unittest.py b/lib/ansible/compat/tests/unittest.py new file mode 100644 index 0000000000..a629849b31 --- /dev/null +++ b/lib/ansible/compat/tests/unittest.py @@ -0,0 +1,36 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +''' +Compat module for Python2.7's unittest module +''' + +import sys + +# Python 2.6 +if sys.version_info < (2, 7): + try: + # Need unittest2 on python2.6 + from unittest2 import * + except ImportError: + print('You need unittest2 installed on python2.6.x to run tests') +else: + from unittest import * |