39 Commits

Author SHA1 Message Date
Patrick McCarty 5112fba1ac Add target to run unit tests without coverage
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2021-06-01 16:16:47 -07:00
Patrick McCarty 06dd69f747 Ignore new B902 warnings from flake8
These warnings are worth addressing eventually, but they shouldn't be
blockers for now.

The warnings are:

  autospec/abireport.py:59:1: B902 blind except Exception: statement
  autospec/abireport.py:73:1: B902 blind except Exception: statement
  autospec/abireport.py:128:1: B902 blind except Exception: statement
  autospec/abireport.py:165:1: B902 blind except Exception: statement
  autospec/abireport.py:191:1: B902 blind except Exception: statement
  autospec/abireport.py:237:1: B902 blind except Exception: statement
  autospec/abireport.py:262:1: B902 blind except Exception: statement
  autospec/abireport.py:273:1: B902 blind except Exception: statement
  autospec/autospec.py:237:1: B902 blind except Exception: statement
  autospec/autospec.py:307:1: B902 blind except Exception: statement
  autospec/build.py:177:1: B902 blind except Exception: statement
  autospec/buildreq.py:563:1: B902 blind except Exception: statement
  autospec/buildreq.py:600:1: B902 blind except Exception: statement
  autospec/buildreq.py:689:1: B902 blind except Exception: statement
  autospec/buildreq.py:713:1: B902 blind except Exception: statement
  autospec/buildreq.py:735:1: B902 blind except Exception: statement
  autospec/commitmessage.py:51:1: B902 blind except Exception: statement
  autospec/commitmessage.py:293:1: B902 blind except Exception: statement
  autospec/config.py:475:1: B902 blind except Exception: statement
  autospec/config.py:821:1: B902 blind except Exception: statement
  autospec/pkg_integrity.py:551:1: B902 blind except Exception: statement
  autospec/pkg_integrity.py:669:1: B902 blind except Exception: statement
  autospec/pkg_integrity.py:765:1: B902 blind except Exception: statement

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2021-01-28 14:14:05 -08:00
Lucius Hu 9f6870c740 Removed infile features
https://github.com/clearlinux/autospec/issues/645
https://github.com/clearlinux/autospec/issues/646
2020-09-01 16:52:52 -07:00
William Douglas 0e412270aa Re-organize buildpattern function into config
The buildpattern is a bit of an odd standalone module that was a
vestiage of the pre-refactor days where modules owned global
data. These days are coming to a close so move this data to a more
sensible owner in config.

This resolves #612 though likely more will be done as part of #131.
2020-04-17 13:49:33 -07:00
Patrick McCarty 3f04dd7e5e Implement unified download interface
The download code for licenses, tarballs, and signature files are
similar enough to warrant consolidation into a unified interface, so add
a new function do_curl() that satisfies the needs of all the callers.

Note that I made one change that noticeably changes the output,
hopefully to reduce confusion: The signature download loop no longer
prints error messages, since the end user should not need to care at all
unless a signature cannot be downloaded and verification is required. If
the latter case is true, autospec will still exit and print the fatal
error, so the issue should be straightforward to diagnose after seeing
that error.

A couple of bugs are fixed as a result of using the new function:

  - The FAILONERROR pycurl option is now set for tarball downloads. This
    prevents certain undesirable side-effects like downloading 404
    response pages.

  - Responses from FTP servers are now handled better, since a more
    common "success" code from FTP servers is 226, not 200.

And unit tests have been updated:

  - Added new tests for download.do_curl().

  - Replaced "mock" import with "unittest.mock" for pkg_integrity tests.

  - Revised license and pkg_integrity tests to reflect the new download
    paths.

  - Added missing mocks for the download paths in PyPIVerifier and
    GEMShaVerifier.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2018-12-09 23:08:10 -08:00
Patrick McCarty e0f0bd098d Rename test.py to check.py
Because the Python standard library provides a package named "test",
pep8 thinks autospec is using it, but really it's importing
autospec/test.py. Rename test.py to check.py to avoid this issue and
tidy up the imports more.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2018-11-07 11:22:36 -08:00
William Douglas 9253e03f86 flake8 clean autospec based on Clear Linux 25890
Update autospec to be largely flake8 clean with 2 exceptions added to
the Makefile. One for Module docs that autospec is intentionally not
including as the file splits aren't real modules at this point. And
the second for import groups needing newline separation that autospec
is ignoring to avoid splitting up each autospec "module" being
imported as autospec today isn't really built on modules the python
way.
2018-11-05 14:20:21 -08:00
Arzhan Kinzhalin 6740ba1683 Fix linter (flake8) errors.
Also:
* flake8 configuration is moved from the command-line in the makefile to
  setup.cfg
2018-10-25 09:30:46 -07:00
Matthew Johnson 9739ab703a Turn off ConfigParser string interpolation
configparser.ConfigParser attempts to interpolate "%" characters in the
values of the key-value pairs when parsing. This is absolutely unwanted
behavior, especially when parsing URLs such as

<sourceforge url>/joe-editor/files/JOE%20sources/<joe tar>

which cause an uncaught exception.

Turn off interpolation by passing the interpolation=None argument to
ConfigParser.

Add a unit tests to report when ConfigParser(...) is called in the
codebase without setting interpolation to None.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-01-11 17:24:39 -08:00
Matthew Johnson eb4ba41d37 Remove no-longer-used functional test suite
This test suite is extremely hard to keep up-to-date and is no longer as
valuable now that unit tests have been written for much of the code
base. Actual functional testing can be done against package repos
without requiring them to be included in the autospec repository.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-01-11 14:47:39 -08:00
Gabi Beyer aef3399d10 Refactor to use multiple files and change inputs
Create 3 separate infile files, the infile_handler reads in the
inputs and determnes how to parse them. The --infile argument now
allows a url, file, or directory of files to be passed as the
input. The infile_handler determines that type of input, calls the
correct parser depending on the filetype, and calls the update to
the specfile.

The infile parsers contains the scraping and parsing for all file
types. Currently it scrapes both .bb and .inc files and stores the
data into one dictionary. Because these files are both for recipes
their data corresponds and the .inc file takes presedence.

The infile update spec file udpates aspects of the specfile that
have been scraped and stored into a dict from the infile parsers
file. If there exists a value for ROS_SPN in the .bb file, use that
when replace the ROS_SNP value in the replace PV function.

Signed-off-by: Gabi Beyer <gabib@live.com>
2017-11-30 09:07:19 -08:00
Gabi Beyer 8b0c5439e5 Initial commit for infile parser
Add --infile argument that takes a url, path, or directory
to a bitbake/recipe file. It scrapes the .bb/.inc file for
configuration data and stores it in a dictionary. This
architecture can be used for multiple file formats.

Also adds some initial unit tests for scraping functionality.

Signed-off-by: Gabi Beyer <gabib@live.com>
2017-11-30 09:07:19 -08:00
Matthew Johnson 9b8ef511d2 Add coverage statistics to unittest runs
Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-11-07 11:04:46 -08:00
Matthew Johnson 32aa9c70ff Ignore bare excepts with flake8
The previous ignore, import not at top of file (E402) was unneeded. Bare
excepts are handy when we want to fail gracefully from any error. This
is a script, not an imported library.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-10-23 12:08:01 -07:00
Matthew Johnson 2552c9786f Move test generators out of name guard
This allows python3 unittest to properly generate the tests when running
all the tests in the tests directory.

Also adds a fix to test_test.py to reset buildpattern.default_pattern
every test. This was a bug introduced by running all tests at once -
this was not being cleared correctly.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-09-26 15:30:34 -07:00
William Douglas 57280362e0 Add travis config 2017-09-22 15:20:17 -07:00
Matthew Johnson d200c719d7 Add simple unit tests for the util module 2017-07-13 09:14:45 -07:00
Matthew Johnson 9f1e14a06c Manually run each unit test suite in Makefile
The unittest discover method did not run any code within the
if __name__ == "__main__": guard, which prevented it from picking up
generated tests for some of our large pattern-based tests. Just run them
manually so we can actually see all the tests being run.
2017-07-13 09:14:45 -07:00
Matthew Johnson 99b9ed6dd5 Add unit tests for the test module
This patch adds unit tests for the test module.
2017-07-12 08:46:47 -07:00
Matthew Johnson 9f023f87eb Add unit tests for count.py
Add unit tests for the very large count.py module/script. These unit
tests attempt to test every regular expression present in the parse_log
function and helped catch several bugs in the original regexes ported
from perl.
2017-07-11 14:16:55 -07:00
Matthew Johnson e8efee61dc Add unit tests for the specdescription module
Unit tests added for the specdescription module. At the time of this
commit, there are two failing tests due to bugs in the module.

Failures:

- test_description_from_pkginfo

  This test fails because a string.find() method is checked as a boolean
  as if find returned 0 if the substring was not present. find()
  actually returns -1 in this case. Because find() was being used as a
  guard to find the end of a section, the end was found immediately and
  the section was not parsed.

- test_description_from_spec_no_info

  This test fails due to the default description being overridden, even
  when the override is just an empty string.
2017-07-07 12:34:30 -07:00
Matthew Johnson d5b6abc9d2 Add unittests for the buildreq module
Unit tests can be run from the root of the autospec directory by
invoking `make test_buildreq` or `make unittests`.
2017-05-01 11:47:00 -07:00
Matthew Johnson 13c6cdd838 Add unittests for the build module
This patch adds 26 tests for the build module. They can be tested by
running `make test_build` from the root of the autospec repo.
2017-04-25 16:55:07 -07:00
Matthew Johnson 11569333b4 Add simple tests for buildpattern module
The complexity of the buildpattern has been significantly reduced with
the move to a centralized specfiles class to handle specfile writes.
This patch tests the remaining functionality and fixes a typo in
buildpattern.py (pattern_strengh -> pattern_strength).
2017-04-25 14:48:33 -07:00
Matthew Johnson 0c51d2697c Use Make ${CURDIR} instead of invoking pwd at runtime 2017-04-03 20:36:12 -07:00
Matthew Johnson 5a805b704a Refactor and test the license module
Several changes to the license module including changes to where local
hashes are stored. Tests were added as well. Detailed changes below.

config:
  - Move the license hashes from an internal repo to a config file
    (license_hashes) in autospec.

test_license:
  - Unit tests added
  - Unit test target added to autospec Makefile
  - COPYING_TEST file added with GPL-3.0 text for test purposes

license:
  - scan_for_licenses: separate out search strings from conditional to
    make the code more readable and remove unused parameter (required a
    change to where autospec.py called the function).
  - remove duplicate licenses from license_translation list.
  - convert license_blacklist dict to list (values were unused, it was
    being treated as a list anyways).
  - separate out search strings from code in license_from_copying_hash
    and license_from_doc.
  - move curl code out of `with open(file) as fname:` clause in
    license_from_copying_hash.
2017-04-03 20:36:12 -07:00
Matthew Johnson d497f7e2cb files: general cleanup of module
The files module was being treated like a class, in that it was
necessary to keep state throughout the entire autospec run. Convert the
files module to a class and make some other general clean ups. This
changed how the files module was instantiated and called by the main
autospec module and other modules such as tarball and config.

Test the files module with unit tests and add the target to the
makefile.
2017-03-28 22:35:11 -07:00
Matthew Johnson 192ee3570d Add unit tests for commitmessage module 2017-02-16 15:35:35 -08:00
Matthew Johnson 101b2f74bb Add unit tests for abireport
Tests most helper functions in the abireport module. Excludes some
helpers that are just wrappers for os and shutil calls. Also excludes
the 100-line examine_abi main method, which may require functional
tests.
2017-01-24 15:01:38 -08:00
Matthew Johnson 13dc417c0a Add arguments to only run specific functional tests
Functional tests take a long time to run, some longer than others. This
adds the option to run specific test cases defined by passing
whitespace-separated options to the '-c' flag, allowing the tester to
avoid long-running tests like libjpeg-turbo if they don't need to. This
can be run with make by setting the CASES argument:

make test_autospec CASES="c-helloworld c-helloworld-32"
2017-01-19 11:38:56 -08:00
Matthew Johnson 5407d741be Import refactor of pkg_integrity tests
Since pkg_integrity now depends on config.py, it is necessary to change
how imports are done in the tests so mocking can be achieved. This also
required renaming the tests/pkg_integrity.py file to
tests/test_pkg_integrity.py to avoid a name collision. Before each test
the necessary config option is set correctly and the configuration file
rewrite is mocked away.
2017-01-07 08:38:28 -08:00
Matthew Johnson e34771c7a9 Use epoch time for reproducible build env variable
Instead of using the date the configure file was modified, use the UNIX
epoch time for the SOURCE_DATE_EPOCH environment variable. This allows
reproducible package binaries per autospec build.

Functional tests updated to match change and 'unittest' make target
added to ease testing.
2016-12-27 13:05:39 -08:00
Matthew Johnson 4dcb271dac Add unit tests for new Specfile class
Includes a rename of specfile.py -> specfiles.py for easier imports and
related change to how it imported in autospec.py. Also includes a minor
fix to how lang files are written to the specfile. The error was
identified by these unit tests.
2016-12-16 12:40:20 -08:00
Matthew Johnson e0111cc30e Add a unit test for version detection
This unit test reads test cases from tests/packageurls and attempts to
determine the version and name from the url specified. tests/packageurls
defines these cases and their expected results in the format:

<package url>,<expected name>,<expected version>

There are currently some test cases that fail. This unit test will make
it easier to make changes to the tarball.name_and_version() function.
2016-12-14 15:06:35 -08:00
Matthew Johnson 90b3942927 Standardize testing invocation and structure
This involves moving the tests to the top-level tests/ directory, adding
a Makefile target (make test_autospec) to run the functional tests, and
adding a tests/README.rst to explain the various testing files and test
structure.
2016-11-28 14:57:40 -08:00
Alex Jaramillo d56b7189a5 Changing module name
Signature verification was extended to do hash
validation for ruby gems, so integrity validation
is a better description of module. The module
was changed from verify_sign to pkg_integrity
2016-11-16 18:33:28 +00:00
Alex Jaramillo 3f194a5c1c Adding unittests for verify sign 2016-11-15 00:43:45 +00:00
Simental Magana, Marcos 2a7ba09747 Fix Makefile to check autospec/*.py
autospec code was moved into autospec/ folder and current
Makefile does not check it, this commit changes the check
target to run flake8 in autospec/*.py instead of ./*.py
2015-12-21 14:21:51 -06:00
Ikey Doherty f548853a31 Initial commit
Signed-off-by: Ikey Doherty <michael.i.doherty@intel.com>
2015-11-06 17:30:13 +00:00