Commit graph

56 commits

Author SHA1 Message Date
Shane Lee
fdfb0e1310 Fix test_log_beacon.py::test_log_match test on Windows 2024-03-06 15:19:54 +00:00
Gareth J. Greenaway
7ad348dd48 increase test coverage for textfsm module. 2024-03-06 15:19:54 +00:00
Pedro Algarvio
03ad4c6337 Update code to be Py3.7+ to reduce merge forward conflicts 2024-02-29 10:16:58 +00:00
Pedro Algarvio
3dea2eb541 Update pre-commit hook versions 2024-02-29 10:16:58 +00:00
Pedro Algarvio
37ca0c08d0 Upgrade to mock==5.1.0
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
2023-10-04 20:54:42 +01:00
Pedro Algarvio
8a769342d6 Remove tests code/skips targeted for Py<3.6
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
2022-12-06 06:03:10 +00:00
Pedro Algarvio
4d49013247 Update to isort 5.10.1
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
2022-08-01 12:49:16 -06:00
Pedro Algarvio
f2a783643d Update to latest `pyupgrade` hook. Stop skipping it on CI.
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
2022-01-26 15:18:32 -08:00
Pedro Algarvio
da8b59266c We require mock>=3.0.0, remove unneeded static method 2021-09-22 14:01:19 -04:00
Pedro Algarvio
f5e8e98607 Remove all occurrences of `# future lint:`. There's no tool using it. 2021-07-14 11:38:58 -04:00
Pedro Algarvio
05bbe14088 Drop Py2 and six on tests/support/mock.py 2021-03-01 10:42:23 +00:00
Daniel A. Wozniak
79dcb64917 Blacken changed files 2020-05-10 11:11:31 -07:00
Daniel A. Wozniak
196fa56137 Blacken changed files 2020-05-10 11:11:31 -07:00
Daniel A. Wozniak
6ab29e80f4 Blacken changed files 2020-05-10 11:11:31 -07:00
Pablo Suárez Hernández
97735d727b Fix pylint issues on unit tests 2020-05-10 11:11:31 -07:00
Pablo Suárez Hernández
15f58db818 Move MockTimedProc implementation to tests.support.mock 2020-05-10 11:11:31 -07:00
Blacken Salt
0b2a5613b3
Blacken salt 2020-04-03 13:05:41 -05:00
Pedro Algarvio
ba94b4b878
By these days, we should blowup if mock is not available 2019-12-13 05:16:10 +00:00
Erik Johnson
3b6356f4b0
Raise TypeError when trying to read from filehandles not opened for reading 2018-06-23 21:27:58 -05:00
Erik Johnson
0e8c83bac6
2 MockFH enhancements:
1. Raise appropriate TypeErrors when wrong type is written
2. Don't raise exception about read_data unless we actually try to read
   from the filehandle. This makes it a bit more permissive when testing
   code where the file is only being written to.
2018-06-23 15:00:26 -05:00
Erik Johnson
1cbe89feee
Implement tell() for filehandle iteration 2018-06-18 16:23:35 -05:00
Erik Johnson
38df912fa6
Operate on a copy of the read_data
This keeps us from mangling it if it contains lists, which we would be
popping items off of. We don't want to pop items from the list that was
passed in.
2018-06-18 14:45:40 -05:00
Erik Johnson
67c036dc2d
Add MockCall to tests.support.mock to track calls 2018-06-18 10:34:33 -05:00
Erik Johnson
fd9d700157
Add additional docs to MockOpen class 2018-06-18 00:28:06 -05:00
Erik Johnson
fc0aa9934f
Track call_count in MockOpen 2018-06-18 00:21:26 -05:00
Erik Johnson
51b3faa7b4
Add support for passing multiple strings for a given match in read_data 2018-06-18 00:21:26 -05:00
Erik Johnson
f5823252bb
Track call args/kwargs in MockFH
This allows for them to be verified in tests
2018-06-18 00:21:25 -05:00
Erik Johnson
335591ca90
Mock the seek function in MockFH 2018-06-18 00:21:25 -05:00
Erik Johnson
2be19cfa89
Report correct location when reading using explicit size and EOF reached 2018-06-18 00:21:25 -05:00
Erik Johnson
5ec95ba5ca
On second thought, actually implement tell() 2018-06-18 00:21:25 -05:00
Erik Johnson
19022eb9e5
Add tell mock to MockFH 2018-06-18 00:21:25 -05:00
Erik Johnson
4e67955572
Replace the rest of mock_open with a class 2018-06-18 00:21:25 -05:00
Erik Johnson
836fde9a30
Allow Python 2 to accept an exception as read_data 2018-06-18 00:21:25 -05:00
Erik Johnson
543385fd02
Add writelines_calls property 2018-06-18 00:21:25 -05:00
Erik Johnson
42fa842456
Make read funcs mocks so their calls can be tracked
Also add a property func as a shorthand to return all the write calls
for a given filehandle.
2018-06-18 00:21:25 -05:00
Erik Johnson
b9200dbc3e
add a dict containing the handles to the mock_open return object
This allows tests to access the MockFH objects opened during the
execution of the unit test.
2018-06-18 00:16:03 -05:00
Erik Johnson
852ba4b982
Add mocked close() function to MockFH 2018-06-18 00:16:02 -05:00
Erik Johnson
1861e9b944
mock_open: rewrite multi-file support
The initial approach tied all opened files to the same mocked
filehandle. This new approach moves all the read functions into a class,
and then uses a separate instance of that class for each opened file.
2018-06-18 00:16:02 -05:00
Erik Johnson
5e6b539770
Use function for empty string
Missed this when making changes for multi-file support
2018-06-18 00:16:02 -05:00
Erik Johnson
5d09b178d7
Separate mocked file contents per filename, not glob
This allows for multiple opens of a file matching the same glob.
Otherwise, subsequent opens would already be at EOF.
2018-06-18 00:16:02 -05:00
Erik Johnson
875102f538
Modify mock_open to support multiple file paths 2018-06-18 00:16:02 -05:00
Erik Johnson
8ba6cadac7
More mock_open bugfixes
This makes readline() a regular function and not an iterator. It also
makes the different side_effect functions all operate on the same
generator representing the file contents, and adds support for reading
an explicit amount of bytes from the file. The side effect functions can
now be run one after another and the mocked filehandle will work
properly.
2018-06-18 00:16:02 -05:00
Erik Johnson
e6a4744f85
Use errno instead of hard-coding error 2 2018-06-13 01:11:55 -05:00
Erik Johnson
ff63f36932
Fixes / enhancements for mock_open
This makes the following changes:

1. Now works properly when read_data is a bytestring
2. Now works properly when mocked filehandle is iterated (e.g. `for line in fh:`)
3. Adds ability to make mocked filehandle raise an IOError when the path
   being opened doesn't match a pattern (or one of a list of patterns).
2018-06-13 01:05:44 -05:00
rallytime
3273bbdab7
Merge branch '2017.7' into '2018.3'
Conflicts:
  - doc/ref/configuration/master.rst
  - doc/ref/modules/all/index.rst
  - doc/topics/grains/index.rst
  - doc/topics/releases/2016.3.4.rst
  - doc/topics/spm/spm_formula.rst
  - doc/topics/tutorials/cron.rst
  - doc/topics/tutorials/index.rst
  - doc/topics/tutorials/stormpath.rst
  - salt/engines/slack.py
  - salt/log/handlers/fluent_mod.py
  - salt/modules/cyg.py
  - salt/modules/junos.py
  - salt/modules/namecheap_dns.py
  - salt/modules/namecheap_domains.py
  - salt/modules/namecheap_ns.py
  - salt/modules/namecheap_ssl.py
  - salt/modules/namecheap_users.py
  - salt/modules/reg.py
  - salt/modules/tomcat.py
  - salt/modules/vault.py
  - salt/modules/win_file.py
  - salt/modules/zpool.py
  - salt/output/highstate.py
  - salt/renderers/pass.py
  - salt/runners/cache.py
  - salt/states/boto_apigateway.py
  - salt/states/boto_iam.py
  - salt/states/boto_route53.py
  - salt/states/msteams.py
  - salt/states/reg.py
  - salt/states/win_iis.py
  - tests/integration/modules/test_cmdmod.py
  - tests/integration/states/test_user.py
  - tests/support/helpers.py
  - tests/unit/cloud/clouds/test_openstack.py
  - tests/unit/fileserver/test_gitfs.py
  - tests/unit/modules/test_junos.py
  - tests/unit/pillar/test_git.py
  - tests/unit/states/test_win_path.py
  - tests/unit/test_pillar.py
  - tests/unit/utils/test_format_call.py
  - tests/unit/utils/test_utils.py
  - tests/unit/utils/test_warnings.py
2018-06-01 14:54:12 -04:00
Erik Johnson
93ee5ee2b0
Fix all Sphinx warnings
Well, all but one, which we expect to see
2018-05-31 15:28:25 -05:00
Erik Johnson
9d004f6512 Use mock 2.0.0 instead of unittest.mock on Python 3 (#2)
This preserves the custom mock_open we backported from unittest.mock,
but otherwise ditches unittest.mock as it does not have
MagicMock.assert_called in Python releases before 3.6.

This allows us to maintain a uniform mock version across all platforms
and Python releases.
2018-02-13 20:16:03 +01:00
Erik Johnson
d6d7da5c90
Replace all usage of six.b
It can't be trusted to produce bytes, it returns unicode when a unicode
string is passed.
2018-01-24 09:17:28 -06:00
Erik Johnson
272044c688
Roll back use of explicit unicode literals 2017-12-10 17:41:45 -06: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