Commit Graph

140 Commits

Author SHA1 Message Date
rallytime
a40f007962
lint: get_context is in stringutils.py now 2018-04-17 16:29:48 -04:00
rallytime
3416e398c6
Update old utils paths references to use new paths 2018-04-17 11:02:38 -04:00
rallytime
94c2a12be6
Merge branch '2017.7' into '2018.3'
Conflicts:
  - tests/integration/modules/test_state.py
  - tests/unit/templates/test_jinja.py
  - tests/unit/test_minion.py
2018-04-17 10:54:42 -04:00
Daniel A. Wozniak
46fa2c04de
Fix py3 os.linesep wart 2018-04-14 17:09:50 -07:00
Daniel A. Wozniak
3c565d7e54
Use salt.utils.fopen 2018-04-13 13:14:19 -07:00
Daniel A. Wozniak
aa965310f1
Clean up cruft 2018-04-13 10:27:17 -07:00
Daniel A Wozniak
efc9866580
Jinja test fixes 2018-04-13 10:23:34 -07:00
Erik Johnson
2b887dd77d
Update tests to reflect changes to the SaltCacheLoader 2018-02-22 10:51:36 -05:00
Erik Johnson
e2c4702e0c
Update tests to reflect changes to the SaltCacheLoader 2018-02-21 23:20:02 -06:00
Erik Johnson
b4e24a69e6
Move get_context to salt.utils.stringutils
This avoids circular dependencies when salt.utils.jinja (which is
imported by salt.utils.templates) needs to use get_context()
2018-02-07 02:09:56 -06:00
Benjamin Drung
b6181b5ed6 Fix Unicode tests when run with LC_ALL=POSIX
When running the unit tests with the locale set to POSIX, some Unicode
tests fail:

$ LC_ALL=POSIX python3 ./tests/runtests.py --unit
[...]
======================================================================
ERROR: test_list_products (unit.modules.test_zypper.ZypperTestCase)
[CPU:0.0%|MEM:73.2%]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/unit/modules/test_zypper.py", line 236, in
test_list_products
    'stdout': get_test_data(filename)
  File "tests/unit/modules/test_zypper.py", line 53, in get_test_data
    return rfh.read()
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
828: ordinal not in range(128)

======================================================================
ERROR: test_non_ascii (unit.templates.test_jinja.TestGetTemplate)
[CPU:0.0%|MEM:73.2%]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/unit/templates/test_jinja.py", line 341, in test_non_ascii
    result = fp.read()
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5:
ordinal not in range(128)

======================================================================
ERROR: test_non_ascii_encoding
(unit.templates.test_jinja.TestGetTemplate)
[CPU:0.0%|MEM:73.2%]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/unit/templates/test_jinja.py", line 303, in
test_non_ascii_encoding
    fp_.read(),
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5:
ordinal not in range(128)
----------------------------------------------------------------------

Therefore open files in binary mode and explicitly decode them with
utf-8 instead of their default locale.
2018-02-01 19:24:23 +01:00
rallytime
3c298afa72
Merge branch '2017.7' into 'oxygen'
Conflicts:
  - salt/modules/pip.py
  - salt/modules/reg.py
  - salt/modules/win_pkg.py
  - salt/runners/manage.py
  - salt/states/pkg.py
  - salt/transport/zeromq.py
  - salt/utils/event.py
  - tests/integration/modules/test_pip.py
  - tests/integration/states/test_user.py
  - tests/unit/grains/test_core.py
  - tests/unit/states/test_archive.py
  - tests/unit/utils/test_boto.py
2018-01-23 13:26:43 -05:00
Daniel Wallace
808e26e69a
test simple website 2018-01-20 09:57:20 -07:00
twangboy
4517ca72b9
Ensure utf-8 encoding 2018-01-17 16:22:44 -07:00
Erik Johnson
b89efc16eb
Remove more unnecessary explicit unicode literals 2018-01-13 21:10:04 -06:00
Erik Johnson
1044b627a1
[PY3] Add unicode_literals to salt.utils modules (A-D) 2018-01-13 16:08:56 -06:00
Erik Johnson
002aa88a97
Replace yaml usage with a helper to ensure unicode is handled properly
Without allow_unicode=True, unicode characters are processed through the
str representer and on Python 2 are dumped as a Unicode code point (i.e.
a literal \u0414). This commit makes allow_unicode=True the default in
our salt.utils.yamlloader.safe_dump() helper. It also adds a new
salt.utils.yamlloader.dump() helper which wraps yaml.dump() and also
makes allow_unicode=True the default.

To make importing and using our custom yaml loader/dumper easier, a
convenience module called salt.utils.yaml has been added, which does a
wildcard import from both salt.utils.yamldumper and
salt.utils.yamlloader.

Refs to yaml.load/dump and yaml.safe_load/safe_dump have been updated to
salt.utils.yaml, to ensure that unicode is handled properly.
2018-01-03 14:14:21 -06:00
Erik Johnson
7b13a7df8b
Replace json module usage with a helper to ensure unicode content is handled properly
This adds wrappers for json.dump{,s} which disable `ensure_ascii` by
default.
2017-12-27 09:30:58 -06:00
Erik Johnson
4501d0d6f9
Fix nested structure test for py2 and py3 2017-12-19 15:34:11 -06:00
Erik Johnson
8cdb9ea54f
[PY3] Add print_function import to files with unicode_literals already added
This makes the 2.x usage invalid syntax and forces the use of print as a
function. This adds the import to the files which I've updated in the
last couple of days but forgot to add it.
2017-12-15 12:14:18 -06:00
Erik Johnson
2a8d7e2a0b
[PY3] Add unicode_literals to files in root salt/ dir (and associated tests) 2017-12-14 00:47:44 -06:00
Erik Johnson
272044c688
Roll back use of explicit unicode literals 2017-12-10 17:41:45 -06:00
rallytime
052b13c98e
Merge branch '2017.7' into 'develop'
Conflicts:
  - salt/cli/daemons.py
  - salt/client/ssh/__init__.py
  - salt/modules/win_pkg.py
  - salt/netapi/rest_cherrypy/app.py
  - salt/proxy/fx2.py
  - salt/utils/__init__.py
  - salt/utils/jinja.py
  - salt/utils/napalm.py
  - salt/utils/path.py
  - salt/utils/verify.py
  - tests/integration/modules/test_saltutil.py
  - tests/integration/states/test_service.py
  - tests/unit/utils/test_verify.py
2017-11-22 12:36:03 -05:00
Erik Johnson
958e1aeb8d
Fix test to reflect changes in YAML dumper
PR #42064 modified the YAML dumper to display unicode text as a unicode
literal rather than with the !!python/unicode extension prefix. This
updates the test to reflect the change in Salt's behavior.
2017-11-14 13:43:39 -06:00
Erik Johnson
df972db3ba
Merge pull request #42930 from CorvinM/issue36942
Jinja line statements and comments
2017-11-13 12:02:16 -08:00
rallytime
832aa3010c
Reorder and group imports in jina template unit tests
The imports were scattered around quite a bit, which made it hard
to see where multiple uses of salt/utils/* imports were being pulled
in.

This PR just adjusts the ordering so it's easier to see what is included
already for the future. (This is particularly useful for catching misuses
of salt.utils.__init__.py functions.)
2017-10-18 14:15:50 -04:00
rallytime
d712031a43
Update to_unicode util references to new stringutils path 2017-10-18 09:44:55 -04:00
rallytime
b8dc018178
Merge branch '2017.7' into 'develop'
Conflicts:
  - salt/modules/opkg.py
  - salt/utils/templates.py
  - tests/unit/templates/test_jinja.py
2017-10-18 09:37:47 -04:00
twangboy
a4e2d8059d
Fix unit.templates.test_jinja for Windows
Fix problem with files that end with new line on Windows
Fix some problems with regex
Fix some unicode conversion issues
2017-10-16 10:41:36 -06:00
Corvin Mcpherson
2dc593b48e Add jinja environment default options. 2017-08-16 20:02:13 -04:00
Petr Michalec
0bbb23d68c Merge unit tests from #41538 2017-08-16 18:29:34 -04:00
Erik Johnson
3184168365 Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.

A summary of the changes in this PR is as follows:

* Moves the following functions from `salt.utils` to new locations
  (including a deprecation warning if invoked from `salt.utils`):
  `to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
  `dequote`, `is_hex`, `is_bin_str`, `rand_string`,
  `contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
  `which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
  `is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
  `is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
  `is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
  `salt/utils/__init__.py` for better organization, so we can keep the
  deprecated ones separate from the ones yet to be deprecated as we
  continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
  unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
  import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
  accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
  such that it returns a string matching the passed size. Previously
  this function would get `size` bytes from `os.urandom()`,
  base64-encode it, and return the result, which would in most cases not
  be equal to the passed size.
2017-08-08 13:33:43 -05:00
rallytime
998834fbac Sort lists before compairing them in python 3 unit test 2017-08-07 16:09:43 -04:00
rallytime
f49da018e4 Sort lists before compairing them in python 3 unit test 2017-08-07 14:38:10 -04:00
Erik Johnson
2fb986f5ca Merge pull request #42367 from rallytime/files-util
Move file-related utilities out of init file and into salt.utils.files.py
2017-07-19 16:55:52 -05:00
rallytime
ccf790a83f Update all references for moved functions to use "files" util
- fopen
- flopen
- fpopen
- safe_rm
- is_empty
- is_fcntl_available
2017-07-18 10:31:01 -06:00
rallytime
f59ecb7ffe Merge branch '2017.7' into 'develop'
Conflicts:
  - salt/executors/sudo.py
2017-07-18 08:57:55 -06:00
rallytime
2be4865f48 [PY3] Fix test that is flaky in Python 3
We can't rely on lists having the same order in Python3 the same
way we rely on them in Python2. If we sort them first, and then
compare them, this test will be more reliable.
2017-07-07 09:43:52 -06:00
rallytime
add5b118a3 Merge branch '2017.7' into 'develop'
Conflicts:
  - salt/modules/yumpkg.py
  - tests/unit/templates/test_jinja.py
2017-06-19 14:12:36 -06:00
Mike Place
5bc7a20327 Missing colon 2017-06-19 10:52:45 -06:00
Mike Place
445f603568 Fix incorrect indentation 2017-06-19 09:37:00 -06:00
Daniel Wallace
4bf030ff65 don't break py2 2017-06-16 13:11:51 -06:00
Daniel Wallace
b65edc786c handle unordered sets in unique jinja tests 2017-06-16 08:40:40 -06:00
rallytime
e1bd7ce10a Merge branch 'nitrogen' into 'develop'
No conflicts.
2017-05-11 13:03:59 -06:00
rallytime
738681c20f Pylint fix 2017-05-11 09:03:10 -06:00
rallytime
6729587d54 Spelling fix 2017-05-10 16:59:39 -06:00
rallytime
3a5419ba3f Split up test asserts in jinja template unit test
Due to a bug in the equality handler, this test was failing on
CentOS 6 running Python 2.7.13. This PR splits up the test assertions
into several different pieces in order to cover all the possible
use cases, but also pass on CentOS 6.
2017-05-10 16:55:37 -06:00
Loren Gordon
bff15d4c61 Updates jinja template tests with salt context 2017-05-05 07:21:40 -04:00
Loren Gordon
ae89f14178 Updates tests to get custom filters from decorator class 2017-05-05 07:21:40 -04:00
Pedro Algarvio
9a11538b54
Stop using deprecated TestCase methods 2017-04-01 14:22:57 +01:00