Skip to content

Improve tests and other refactorings - #369

Merged
pombredanne merged 59 commits into
developfrom
test-cleanup
Nov 21, 2018
Merged

Improve tests and other refactorings#369
pombredanne merged 59 commits into
developfrom
test-cleanup

Conversation

@pombredanne

Copy link
Copy Markdown
Member

This PR started with a focus on tests enhancements but does a few more things.

  • The test code has been streamlined and updated. In particular:

    • test files are now grouped by test module under a testdata/test_xxx directory.
    • All the unused test files have been removed.
    • All expectedFailure and FAILING_test_xxx tests have been either removed or updates except for one test that does live API call and is marked as skipped for now.
    • All tests now run in the CI, including doctests
    • new tests have been added including
      • validation of all ABOUT files
      • help text tests
  • Command line module has been streamlined and updated:

    • cmd.cli() has been renamed to cmd.about()
    • Options definitions have been streamlined and standardized including help and METAVAR
    • the command help has been reviewed and updated
    • We now use a validation callback functions for several options
    • command line error reporting functions have been refactored and made simpler.
    • The display of message at the start and end of a command run have been standardized
    • to avoid error.log file overwrite with When running multiple "inventory" command in //, error log file will be mixing several inventory errors or be deleted.  #363, it is now named after the "OUTPUT" argument as
      <OUTPUT>-error.log such that each command creates a mostly unique error log filename.
    • a new parse_key_values function is used to parse options that contain key=value such as --filter
    • internally the use_mapping and mapping_file variables and processing code common to many functions has been updated. Early in subcommands, the --mapping and --mapping-file options are evaluated. They are mutually exclusive options and a check is now done early and an error is returned if both options are used. Then the proper mapping file is used and passed around to functions as a single and optional mapping_file argument.
  • inventory subcommand:

    • The --filter option parsing has been streamlined and this option is now validated early.
  • attrib subcommand:

  • gen subcommand:

  • Other:

    • some u'' unicode string prefixes have been removed when not needed.
    • some formatting has been applied as needed.
    • several TODO: and FIXME: comments have been added as reminders.
    • the util module has been refactored and updated. Some shared functions have been moved there and non-shared functions moved out where they are used.
    • some NOQA and pragma: nocover comment tags have been added toward future coverage and code style validation

 * format and streamline test code
 * move all used test files to /testdata/test_util dir
 * add more tests for loading mappings
 * update util code accordingly

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * add docstrings
 * mionr variable renaming
 * split tests finctions

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * add more template tests for corner cases
 * add validation for all builtin templates

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * remove unused test files
 * move test files under tesdata/test_attrib
 streamline test code

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * and other minor formattings

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 Also do some minor cosmetic refactoring

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * this may not get the right results on Windows
 * also improve the usage of default_template

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Mapping can now only be used when using a CSV as an input.

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * Review and edit all command line option definitions
 * Remove AboutCommand since Click bug is now fixed
 * Implement cnsistently --quiet contract
 * Update and rename common error and error logging functions
 * Return proper exit code on errors #362
 * Rename attrib --vartext option to --variable and
   add validation callback and parsing function
 * Add validation callback to inventory --filter option

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * Update attrib.generate function to return an Error and the
   generated text to simplify error handling in the cmd module
 * Rename attrib.generate function args template_string to template and
   vartest to variables. Use variables everywhere too.
 * Move variables parsing and validatio to the cmd module
 * Remove any reference to mapping_output: Mapping can now only be
   used when using a CSV input.
 * JSON outputs can no longer use mappings
 * Remove use_mapping everywhere and use only mapping_file instead.
   mapping_file is either a builtin or custom mapping file.
 * add validation to every commands to avoid the combo of --mapping and
   --mapping-file that are mutually exclusive.
 * use click.UsageError for cmd validation
 * DEFAULT_MAPPING is now top level constant for the default
   mapping config file location
 * Improve docstrings
 * validate template early in cmd.attrib

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * also streamine test code for testing errors

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * Also add todo and remove dead code

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * remove unused test files and functions
 * update or remove failing tests
 * move test files under their own dir for each test_XXX module
 * update and correct all expectedFailure

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
This is to avoid CRLF issues difference on multiple
OSes

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * minimal tests for attrib, inventory and gen
 * update the code accordingly

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * Rename gen --license-notice-text-location to --reference
 * Renamere license_notice_text_location arg and variable name to
   reference_dir everywhere.
 * Update and refine the command help help for the gen subcommand.

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * rename cmd.cli() to cmd.about()
 * Use a common validation callback function for --mapping and
   --mapping-file options
 * Streamline and standardize help text and METAVAR usage
 * Standardize option definitions in particular for Path options

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
pombredanne and others added 12 commits November 18, 2018 21:51
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * The goal of this would be to replace entirely the mapping feature
   and options.

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * Monkey patch backports.csv to use OrderedDict and
   remove OrderedDictReader

 * Remove unused funtion check_duplicate_keys_about_file

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
 * These unused methods and functions have been removed
   and their tests updated or removed accordingly:

- AboutResourceField.resolve()
- About.attribution_fields()
- About.same_attribution()
- About.resolved_resources_paths()
- parse() and its pre-compiled regex
- by_license()
- by_name()
- by_license_content()
- verify_license_files_in_location()

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
@pombredanne

Copy link
Copy Markdown
Member Author

All green and merging in develop after a chat with @chinyeungli
The saneyaml and csv transform hare part of the branch now too.

@pombredanne
pombredanne merged commit dde73cb into develop Nov 21, 2018
@pombredanne
pombredanne deleted the test-cleanup branch November 21, 2018 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant