Commit Graph

710 Commits

Author SHA1 Message Date
Joel Brobecker
9c970a4716 format testsuite/tests/* with black, include them in pre-commit checks
While many testcases don't meet flake8 requirements right now
(the most prevalent one is the "*" import, but we also have
expected output strings with lines longer than 88 characters),
we can still improve the testcases using black to format them.
If anything, this will avoid to break many of flake8's rules.

This commit changes the .pre-commit-config.yaml file to remove
the exclusion for testsuite/tests/*. From there, all the files
in testsuite/tests/ were reformatted via:

    $ pre-commit run --all

Change-Id: Ia4957899cabf909f401bb2a242ed7035d89f1df9
2021-06-27 10:07:36 -07:00
Joel Brobecker
e50b4a23bc Introduce a TestCase.run "method" (for transition to pytest)
This commit introduces a new run attribute in our testsuite's
TestCase class as a way to allow testcases to call this method
instead of instantiating the Run class. All testcases are then
modified to use this method, by running the following perl
command:

    $ cd testsuite/tests
    $ perl -pi -e 's/\bRun\(/testcase.run(/g' **/run_test.py

The testcases are then modified to remove the unused import using
the following perl command:

    $ perl -pi -e 's/\s+Run,//g' **/run_test.py

The goal is to help the transition to pytest, where the testcases
will be using the "run" method to call external commands such as
Git. The difference is that the pytest version of this method
will do more than being a simple wrapper (e.g. it will take care
of the default working directory).

TN: U530-006
Change-Id: I1823ef4331d8d16da6cf5f4a4efdbb667c68848d
2021-06-27 10:07:36 -07:00
Joel Brobecker
2132e6fb4a Rename "self" parameter to "testcase" in all our testcases
This is another preparation patch towards the transition of
the testsuite framework to pytest (as part of the transition
to Python 3.x), where we will use a fixture called "testcase"
to replace the TestCase object (self).

To facilitate the transition as well as the review of that (future)
transition, this commit renames the "self" parameter into "testcase".
Note that the change was performed entirely automatically thanks to
the following perl command:

    perl -pi -e 's/\bself\b/testcase/g' **/run_test.py

It's a departure from the convention that the object for which
a method is called be called "self", but it's only a temporary
situation; once we transition the testsuite to pytest, we will
no longer have classes -- just simple functions.

TN: U530-006
Change-Id: Id9cf32c8a8f1ed0c2fd4236f303c8fbd7b4894c1
2021-06-27 10:07:36 -07:00
Joel Brobecker
54455ff29f Remove all remaining calls to unittest.TestCase.assertTrue
This commit removes all the calls to assertTrue that were still
left. In this commit, all the changes were made by hand.

This is preparation work for the transition of the testsuite out
of gnatpython (Python 2.x only), and relying on pytest instead,
which will allow us to run the testsuite using Python 3.x.

TN: U530-006
Change-Id: I0f1925341954ff60a01149dd2075f87dfa3e573e
2021-06-27 10:07:36 -07:00
Joel Brobecker
ab67c06468 Remove most calls to unittest.TestCase.assertTrue in our testcases
TestCase.assertTrue does not bring anything compared to just using
the assert statement. So this commit uses the following perl command
to automatically rewrite all calls which fit in a single line
(which is most of our calls, but not all of them):

    $ cd testsuite/tests
    $ perl -pi -e 's/\S*\.assertTrue\((.*)\)\s*$/assert \1/' \
        **/run_test.py

This is preparation work for the transition of the testsuite out
of gnatpython (Python 2.x only), and relying on pytest instead,
which will allow us to run the testsuite using Python 3.x.

There are still a handful of calls to assertTrue due to them
being spread over more than one line. Those will be treated in
a separate commit to help with review, as those will be handled
manually.

TN: U530-006
Change-Id: I58daa2d6027e82edf5dc664159d08d9d9eaf2d7b
2021-06-27 10:05:45 -07:00
Joel Brobecker
310d9c5e01 update_l_tag,update_tag: Remove code aimed at supporting old Git version
This commit removes a bit of code aimed at supporting the output
from an old version of Git, and does so by modifying the .out
attribute of the Run object we got from running Git. Unfortunately,
this won't work when we switch to Python 3.x and E3's Run class,
as the "out" attribute has become a property instead, so we cannot
modify its value. Since the version of Git we're trying to support
is very old at this point (latest release on 1.7 branch was Oct 2012),
we don't really need to keep that code anymore.

Found while working on U530-006.

Change-Id: I0ad83b00bf1d9e46ab67fd9bc50400f75308f32b
2021-06-20 10:06:46 -07:00
Joel Brobecker
59b4db2b7f headless_branch_combined/run_test.py: Remove useless import (os)
Change-Id: I8a560d3f492169022cfedf35a7de2a69dee4c9c4
2021-06-20 09:43:03 -07:00
Joel Brobecker
d02692a690 avoid mix of spaces and tabs in cvs_check.py scripts used in testcases
A number of cvs_check.py scripts provided by some testcase use a mix
of spaces and tabs for indentation, in a way that causes some errors
when evaluating those scripts using Python 3.x. This commit enhances
those scripts to only use spaces for indentation.

Found while working on U530-006.

Change-Id: I17076204b470dc7cfc4d5ef81b40ef7f2217762b
2021-06-19 17:57:04 -07:00
Joel Brobecker
31bb4e4867 flush stdout and stderr before forking
This commit makes sure that the stdout and stderr output has been
flushed so that no output is left buffered by the time we call os.fork.
Otherwise, if there was any output still buffered, we would be getting
the same output printed multiple times, once by the parent process,
and once by each child process.

Found while working on the transition to Python 3.x (U530-006).

TN: U619-004
Change-Id: I9c38bfc410041e58de2a8f5d7d340f7bff599df4
2021-06-19 11:44:56 -07:00
Joel Brobecker
9b449d8d4e annotated_tag/run_test.py: Remove unused import (re)
Found while working on U530-006.

Change-Id: I5d6b04372b438ebe3956fdc328d88dd2d319c793
2021-06-19 07:54:27 -07:00
Joel Brobecker
3a5b99bb16 delete_tag/run_test.py: Remove unused import (re)
Found while working on U530-006.

Change-Id: I87f2ec29aa34096ca74c04e958c03257a971c583
2021-06-19 07:50:11 -07:00
Joel Brobecker
cf86204196 delete_tag_not_allowed: Rename test_xxx method to match testing objective
I noticed while looking at this testcase that the name of the test_xxx
method used to perform the testing in this testcase did not match what
the testing was trying to do (likely because this testcase was created
by first copying an existing testcase and then modifying it). This commit
fixes the issue by renaming that method.

Found while working on: U530-006.

Change-Id: Icbddfd9bc2ea801df28b68219dcc09bfe5e9e62b
2021-06-19 07:45:02 -07:00
Joel Brobecker
95b6ebdaea delete_tag_not_allowed/run_test.py: Remove unused import (re)
Found while working on U530-006.

Change-Id: I7e17601cd1729546b5e6eccb0add50d24746d5c4
2021-06-19 07:44:49 -07:00
Joel Brobecker
c9bbac817c git.diff_tree: Remove support for **kwargs
I noticed while working on the transition to Python 3.x that
this argument is not actually used, so this commit removes it.
It makes the API for this function simpler and also helps avoid
some pitfalls (as shown by one of the limitations we documented
that this commit removes).

TN: U530-006
Change-Id: I5ced7c6a979c5381d35498b06f1af8c569a3f9ed
2021-06-15 05:55:15 -07:00
Joel Brobecker
18254bffeb testsuite/coverage.sh: Add "pragma: py3-only" to coverage exclude lines
As part of the transition to Python 3.x, we will start adding some code
which should only be executed when running the hooks using Python 3.x.
In the meantime, until the testsuite gets transitionned to Python 3.x,
we still want the coverage report for Python 2.x to remain clean, so
this commit adds a new exclude line to the default one: Any line with
"pragma: py3-only" should now be excluded from the coverage report.

As for the future, what we will do when the transition to Python 3.x
actually happens, is change the config again to exclude lines marked
"py2-only" (or remove the Python-2.x-only code directly, if that makes
better sense).

TN: U530-006
Change-Id: I67a1fe27dbfe614c1dba5176d78f1d8d1fe9cd35
2021-06-15 05:55:15 -07:00
Joel Brobecker
64549c65ae testsuite/coverage.rc: Delete this file (auto-generated)
The file is auto-generated, so there is no need to keep it checked in.

TN: U530-006
Change-Id: I7ea78f1138da47eba29b0cb4664531a575f71cbe
2021-06-15 05:55:15 -07:00
Joel Brobecker
a83208e5a1 testsuite/coverage.sh: Use coverage.rc during report generation
The coverage.sh script creates a coverage.rc file, but this file wasn't
actually used during coverage generation. This change makes sure that
it is.

For now, this shouldn't make any difference, but this will help us
later for providing additional options during report generation
(in particular, it will allow us to add coverage exclusion patterns,
which will become handy to exclude code which is only meant to be
executed with a given version of Python).

TN: U530-006
Change-Id: Ifbba6dfb9a9347f7d5680b6cc464378282653813
2021-06-15 05:54:59 -07:00
Joel Brobecker
bd94624cec style_check_commit: Convert to tuple return value from call to "filter"
This is a preparation patch for the transition to Python 3.x.

Currently, we have the following code:

    | files_to_check = filter(needs_style_check_p, files_to_check)
    | if not files_to_check:
    |     debug("style_check_commit: no files to style-check")
    |     return

With Python 2.x, the "filter" function constructs a list, so
we can indeed check for emptiness using the logical operator "not".

With Python 3.x, however, filter returns an iterator, and using
the logical operator "not" no longer has the same semantics at all.

The easiest way to handle this is to simply convert the result to
a tuple.

TN: U530-006
Change-Id: I334f2657728405226d7da577e893b7c64a3220fb
2021-06-15 05:54:49 -07:00
Joel Brobecker
8de30044a4 .pre-commit-config.yaml: Update to black version 21.5b1
This commit updates the pre-commit hook to black version 21.5b1.
The hooks where then re-run on all files to update their formatting
to this new version of black.

Change-Id: Ib0866745ef8432cf93380a4d83fa23a479eb4a49
2021-06-15 05:52:32 -07:00
Joel Brobecker
cb041c2ec9 .pre-commit-config.yaml: Switch to flake8 version 3.9.1
Change-Id: I45cdc1e1a254128b889742c536419953035a13aa
2021-06-12 08:43:50 -07:00
Joel Brobecker
987d0692f0 style_check_files: Allow "filename_list" param to be any kind of iterable
The "filename_list" of the style_check_files function is expected
to be a list. However, as it happens, we have a call to this function
where the filename_list parameter was computed using the "filter"
function.

    files_to_check = filter(needs_style_check_p, files_to_check)
    style_check_files(files_to_check, new_rev, project_name)

This is no problem when trying to iterate on the list alone, but
at one point inside the "style_check_files" funtion, we try to
add to it like so:

    for filename in filename_list + aux_files:

With Python 3.x, this causes a crash because the "filter" function
now returns a generator rather than a list. Seems it seems desirable
to allow "style_check_files" to accept any iterable as "filename_list",
this commit modifies the code to allow it.

TN: U530-006
Change-Id: I8e5caaf09d177096788c522d7bff8168eb158ec7
2021-06-05 19:27:39 -07:00
Joel Brobecker
70335554e4 Access exception arguments through "args" attribute (for Python 3.x)
This commit changes some code which currently only works with
Python 2.x, to make it compatible with both Python 2.x and
Python 3.x.

TN: U530-006
Change-Id: I4874452cdbb26410dfe7a2d491ed400e6b038029
2021-06-05 19:12:22 -07:00
Joel Brobecker
334fe1aaf4 check_fast_forward: Minor test rewrite to avoid string comparison
This commit modifies a conditional expression to avoid comparing
the output from a git command with the empty string. With Python 3.x,
this wouldn't work unless we decoded the output first or compared
against the empty *byte* string. But since all we're interested in
is knowing whether the output is empty or not, we can use a simple
"truth" test instead, thus avoiding having to worry about the type
of the output entirely.

TN: U530-006
Change-Id: I0067cb6bfb37da4e1782a045beac19d970d7718f
2021-06-05 19:07:41 -07:00
Joel Brobecker
eaef13cfb5 simplify "diff" section computation in commit emails
This commit is inspired by the fact that I couldn't understand
why I was skipping the first character from the output of a Git
command whe computing a commit's "diff", like so):

    diff = git.show(commit.rev, [...], pretty="format:|")[1:]

(emphasis on the "[1:]" at the end).

To understand, I remove the subscripting and reran the testsuite
without it to see what failures I would get. This gave me
the answer, which is we were intentionally starting the "format:"
string with a "|", and so we needed to strip that extra character.

That's when I found a comment I wrote; I didn't see it at first
because it was placed further up:

     # For the diff, there is one subtlelty:
     # Git commands calls strip on the output, which is usually
     # a good thing, but not in the case of the diff output.
     # Prevent this from happening by putting an artificial
     # character at the start of the format string, and then
     # by stripping it from the output.

This may have made sense back when I wrote that comment, but
we no longer strip the start of the output anymore (see commit
af06d5ea54). So I decided to
simplify the code by removing the extraneous character in
the "format:" string.

As it happens, this revealed that git behaves slightly differently
when given an empty "format:" string. Before:

    | $ git show -p -M --stat --pretty="format:|" HEAD
    | |---
    |  hooks/git.py | 4 +---
    |  1 file changed, 1 insertion(+), 3 deletions(-)
    |
    | diff --git a/hooks/git.py b/hooks/git.py
    | index fe2b36b..0669111 100644
    | [snip]

After (removing the "|" in the "format:" string):

    | $ git show -p -M --stat --pretty="format:" HEAD
    |  hooks/git.py | 4 +---
    |  1 file changed, 1 insertion(+), 3 deletions(-)
    |
    | diff --git a/hooks/git.py b/hooks/git.py
    | [snip]

What we can see is that the "---" separate line is no longer shown
in the second command.

Rather than forcing Git to print it, or rather than staying with
the existing code, this commit simply hardcodes the separator line.
One minor bonus of doing it this way is that, if Git decides to
change that separator, this won't affect us, and thus we won't
have to change hundreds of tests accordingly.

And by doing so, this revealed that there was actually an inconsistency
in the formatting produced by Git: In some cases (e.g. merge commits),
it became apparent that Git was omitting this "---" separator line,
even when the "format:" string was empty. The corresponding testcases
where the inconsistency showed up were adjusted to match the new
behavior, which is consisdered (slightly) better, because more
consistent.

Found while working on U530-006 (transition to Python 3.x).

Change-Id: Ifc473fa471ba618e11c3c4bcc6d83cc6f82fc6bf
2021-06-05 17:32:18 -07:00
Joel Brobecker
34950804d3 Simplify git.commit_subject
The use of the "git log" command allows us to avoid having to
post-process the command's output in order to extra the subject.

Found while working on U530-006 (transition to Python 3).

Change-Id: I96e9545deece7a2094f9637b75d5e7fb6f334d9a
2021-06-04 17:06:38 -07:00