Commit graph

39 commits

Author SHA1 Message Date
Jussi Kukkonen
927a598877 tests: Keep linter happy
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-02-17 12:15:12 +02:00
Jussi Kukkonen
0785c78b33 Make linter happy after python upgrade
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-01-08 13:08:53 +02:00
Jussi Kukkonen
8513f46c2b Bump minimum Python version to 3.10
We could just stop testing with 3.9... but I think this will lead to
unintentionally breaking 3.9 anyway sooner or later.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2026-01-08 13:08:47 +02:00
Dimitri Papadopoulos
4a28307270
Fix typos
Signed-off-by: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com>
2025-03-10 22:06:30 +01:00
Jussi Kukkonen
f35b237739 tests: Make tests cope with root history in local cache
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2025-02-20 11:00:50 +02:00
Jussi Kukkonen
1d81a04707 Use __future.annotations module
This allows using some more nice annotations from 3.10
while still being compatible with even Python 3.8.

These are all annotation changes, should not modify any functionality.

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-11-29 12:41:09 +02:00
NicholasTanz
5c71f4f062 update python annotations
Signed-off-by: NicholasTanz <nicholastanzillo@gmail.com>
2024-11-03 23:21:23 -05:00
Jussi Kukkonen
419bfe34ec linting: Enable all Ruff rulesets by default
The goal here is to have ruff enable new rulesets when new releases are
made without us having to o anything: we can then decide if we disable
or not.

* Enable a couple more rulesets (ERA, INP, T )
* Add a few individual ignores to tests and examples
* Default to enable all, disable the rulesets we don't want

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-07 15:39:53 +03:00
Jussi Kukkonen
9a61be1bf4 lint: Enable flake8-executable
* Remove exectuable flag from a couple of files
* Half of the test files have a shebang (but are
  still not executable): remove the shebang

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-05-06 09:19:19 +03:00
E3E
52601e2bd8 add RUF and BLE rulesets; ignore some broad exceptions (BLE001) and RUF012
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-04-21 01:37:40 -04:00
Jussi Kukkonen
009e1ddbf4 lint: Enable more ruff ulesets
Minor fixes were needed, the only possibly interesting one is
the one in RequestsFetcher (use "yield from").

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-04-02 11:02:48 +03:00
Jussi Kukkonen
1512653995 linter: Enable more rules
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2024-03-19 16:30:52 +02:00
E3E
f156e21537 remove pylint and suppressed inline errors from pylint
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-20 22:57:53 -05:00
E3E
cd543c9947 add ruff format and format 2 files
Signed-off-by: E3E <ntanzill@purdue.edu>
2024-02-18 00:38:05 -05:00
Jussi Kukkonen
b67b8c8ad3 Whitespace changes to make new black linter happy
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
2023-02-06 15:29:28 +02:00
Abhisman Sarkar
9f1c86f4a9 Grammar Fix
Fixed a grammatical error in a comment in utils.py

Signed-off-by: Abhisman Sarkar <abhisman.sarkar@gmail.com>
2022-06-27 18:09:43 +05:30
Lukas Puehringer
2bb977cd9c test: drop usage of custom log module in new test
Old tests are not touched as they will be removed in subsequent
commits, along with the custom log module.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-01-26 14:54:43 +01:00
Lukas Puehringer
7da6a38335 test: define TESTS_DIR constant
Define TESTS_DIR constant in tests/util.py as full path to the
parent directory of the util module. This may be used to reliably
read other files in tests dir, such es "repository_data" or
"simple_server", regardless of cwd.

This commit also replaces a couple of `getcwd() + "filename"` with
`TESTS_DIR + filename`, so that in the future (post #1790) we
should be able to invoke the tests from anywhere, not only from
within the tests directory as is now the case.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-01-24 13:54:07 +01:00
Teodora Sechkova
568580701c
tests: move _cleanup_dir to utils.py
Make the method _cleanup_dir public and move it
to tests/utils.py.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-10 15:59:51 +02:00
Martin Vrachev
8d73330f86 Address more pylint warnings on tests files
All of the changes are made manual.
The target files are only those who test the new code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-09 16:13:14 +02:00
Jussi Kukkonen
942e6d25ab
Merge pull request #1691 from MVrachev/key-rotations
Tests: add tests for non-root key rotations
2021-12-08 11:07:59 +02:00
Martin Vrachev
d203834e5c Apply linters on tests/utils.py
Apply all 4 linters on tests/utils.py, so we can lint it in future and
not rename and exclude it.
It's expected that most if not all code in tests/utils.py will be
useful even when we remove the tests file on the old code.
Keep in mind when reviewing that type annotations where already added
in e2deff3148

Black and isort changes where automatically made.
The only manual changes are:
- pylint disables
- function docstrings
- initializations of attributes of "TestServerProcess" __init__()
- additional asserts of the attributes types

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-03 18:17:33 +02:00
Martin Vrachev
3def667844 Tests decorator: save case name
Save the case name in the "unittest.TestCase" object when executing
test cases through the "run_sub_tests_with_dataset" decorator.
This allows dumping directories with names specific to the test case
that can be used for debugging as showed in
test_updater_key_rotations.py

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-02 15:40:30 +02:00
Martin Vrachev
e2deff3148 Address mypy warnings
This commit includes manual fixes for a lot of mypy warnings.
When there were warnings that we are calling non-annotated function
in annotated context I decided to add annotations instead of ignoring
those warnings.
That's how I end up adding annotations in the whole tests/utils.py
module.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-11-24 20:50:10 +02:00
Martin Vrachev
9989d3c614 Tests: move decorator in utils so it can be reused
Generalize the decorator used in test_metadata_serialization.py and
move it inside tests/utils.py, so it can be reused in other similar
situations.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-10-07 15:19:50 +03:00
Philippe Coval
f00f89328e tests: Use current python interpreter for sub tests
Can be useful to run tests using distro runtimes,
(like python3 on Debian).

Relate-to: https://github.com/theupdateframework/tuf/issues/263
Origin: https://salsa.debian.org/rzr/python-tuf/-/tree/debian/review/master
Forwarded: https://github.com/theupdateframework/tuf/pull/1337
Signed-off-by: Philippe Coval <rzr@users.sf.net>
2021-04-12 23:34:31 +02:00
Joshua Lock
13b085712f tests: remove some Python 2 specific tests
Signed-off-by: Joshua Lock <jlock@vmware.com>
2021-03-03 09:38:36 +00:00
Teodora Sechkova
2af63cfd8d
Add host address as a test level constant
Use a common test level constant for defining
the host address forming the download URL on
the client side.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-02-24 11:41:34 +02:00
Jussi Kukkonen
e54869c98c Tests: Fix first line of test server output
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-11-27 12:18:44 +02:00
Martin Vrachev
cf4902131e Fix empty list as a default value for function arg
This quote from the Google Python style guide made me realize
why empty list as a default value for an argument could be
dangerous:

"Default arguments are evaluated once at module load time.
This may cause problems if the argument is a mutable object
such as a list or a dictionary. If the function modifies the object
(e.g., by appending an item to a list), the default value is modified."

Read more here:
https://google.github.io/styleguide/pyguide.html#2123-cons

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-23 21:55:51 +02:00
Martin Vrachev
ea20e86380 Make "bind successful" the first server message
The current implementation for server startup in TestServerProcess
relies on the fact that "bind successful..." is the first message
sent by the server process.
Make sure that this is true and leave a comment about this.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
Martin Vrachev
5d9a6f6598 Tests: Queue replace tmp files, OS port creation
These changes can be summarized with the following bullets:
- Delegate generation of ports used for the tests to the OS
- Use thread-safe Queue for processes communication
instead of temporary files
- Remove all instances of port generation or hardcoded ports
- Make test_slow_retrieval.py fully conform with TestServerProcess

Delegate generation of ports used for the tests to the OS is much
better than if we manually generate them, because there is always
a chance that the port we have randomly pick turns out to be taken.
By giving 0 to the port argument we ask the OS to give us
an arbitrary unused port.

Use thread-safe Queue for processes communication instead of temporary
files became a necessity because of findings made by Jussi Kukkonen.
With the latest changes made in pr 1192 we were rapidly reading
from the temporary files and Jussi found that it happened rarely
the successful message "bind succeded..." to be corrupted.
It seems, this is a thread issue related to the thread redirecting
the subprocess stdout to the temp file and our thread rapidly
reading from the file.
By using a thread-safe Queue we eliminate this possibility.
For reference read:
https://github.com/theupdateframework/tuf/issues/1196

Lastly, test_slow_retrieval.py and slow_retrieval.py were refactored.
Until now, slow_retrieval.py couldn't use the TestServerProcess class
from utils.py for a port generation because of a bug related to
httpd.handle_request().
Now, when we use httpd.serve_forever() we can refactor both of those
files and fully conform with TestServerProcess.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-13 14:01:57 +02:00
Jussi Kukkonen
060ef1dfd5 tests: Filter useless warnings
Filter out:
 * DeprecationWarnings for updater module when we are on purpose
   testing deprecated methods from updater
 * SubjectAltNameWarning for connections to our test server

These warnings are visible with e.g.
  python3 test_updater.py

The large change in test_download.py is just indentation into with-block.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-10-09 12:10:49 +03:00
Martin Vrachev
2693620ee8 Make TimeoutError message more comprehensive
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-10-01 12:22:19 +03:00
Martin Vrachev
6f02646408 Log subproceses stdout and stderr in temp files
Logging the stdout and stderr from the test subprocesses into
temporary files clean the console from unnecessary messages from
the server-side such as "code 404, message File not found" or
"GET" queries.

I have decided to create TestServerProcess class that will handle
the server subprocess creation and redirection to a temporary file
object. That way that code can be reused in more than 10 files.

Also, I have cleaned some parts of the unit test to make them more
readable and efficient with the new abstraction.

The unit tests are executed in sequential order and that's why
we can reuse one temporary file object for multiple tests.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-10-01 12:22:08 +03:00
Jussi Kukkonen
1e7ca5fb42 tests: Set root logger level too
We want the tests own log output visible as well, and they are not
under the "tuf" logger. Set root level to the same value as "tuf".

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-16 14:38:10 +03:00
Jussi Kukkonen
03b15fb4be tests: Configure logging for all test files
all test_*.py files now accept zero or more '-v' to increase tuf
logging level. The default is now ERROR.

default: ERROR
"-v":    ERROR, but unittest prints test names
"-vv":   WARNING
"-vvv":  INFO
"-vvvv": DEBUG

Example to run a single test with DEBUG level:
  python3 test_updater.py -vvvv TestUpdater.test_4_refresh

Also make test_log.py restore the log level it modifies during test.

Fixes #1093

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-15 21:36:50 +03:00
Jussi Kukkonen
a22f6182dd tests: increase wait_for_server() default timeout
Travis managed to still timeout with 5 seconds: increasing the timeout
(now that it's not a sleep) doesn't really hurt normal non-VM use cases
so let's bump it to 10 seconds.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-08-10 16:11:33 +03:00
Jussi Kukkonen
740be9cdb6 tests: Avoid sleep(): make sure servers really start
* Add utility function to wait on a socket until it responds
* Use the function instead of sleeping in tests that need to wait for
  the server to start
* Increase the max timeout to 5 seconds by default (as appveyor builds
  still seem to hit the 3 second mark sometimes)

wait_for_server() functions quite differently depending on OS: Windows
can take 2 seconds to respond with ECONNREFUSED whereas Linux is almost
instant. There might be tricks to be faster on Windows (like setting
a shorter socket timeout) but this was not done here.

This makes a full Linux test run almost 40% faster and should be more
reproducible on every platform.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-08-10 16:11:33 +03:00