Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair schema-enforcer schema command #68

Merged
merged 16 commits into from
Jan 20, 2021
Merged

Repair schema-enforcer schema command #68

merged 16 commits into from
Jan 20, 2021

Conversation

PhillSimonds
Copy link
Contributor

@PhillSimonds PhillSimonds commented Jan 7, 2021

This PR repairs the schema-enforcer schema command per #63. It also documents the schema-enforcer schema command and it's various options.

Of Note:

  • The pattern was added to examples/example3/schema/definitions/properties/ip.yml because format: ipv4 wasn't correctly catching errors with an IP address. It was disabled from yamllint because, when double quoted, YAMLLint fusses about the string having an invalid escape sequence. Likewise, schema validation fails being unable to parse the string when run if it is double quoted.
  • I created a "find_file" function as "find_and_load" is a little unclean -- thinking to factor functions so they each serve a single purpose, as much as possible. Pylint says the list I'm passing in (list of formats of files) is a dangerous value -- some input on what to use here instead would be beneficial.
  • The additional noqa statements in cli.py were added to fix an incompatability between pydocstyle and click. Pydocstyle doesn't like it when a \ is used in a doc string unless the docstring is "raw" (proceeded by an r). \f is used in the docstring so that click only shows what proceeds the \f in it's contextual help output to stdout. When the string is preceeded by r, click shows the entire string in it's contextual help. I had to use a non-raw string and disable some pydocstyle particularities in order to get click to show the contextual help correctly and for pydocstyle not to fail.

fixes #63

- Add --schema as viable option
- Make print statement print more elegantly using rich
- Validate inputs and raises an error if expected inputs don't exist
- Refactor code to make intent a little more clear
- Update example3 definitions
- Add logic to validate test directories exist before running unit tests
- Refactor acquisition of test directory into it's own method for clarity
  in up stream method call
- Update `schema-enforcer schema` command documentation.
- Use _get_test_dir_absolute() method in place of _get_test_dir() as test_directory
  is defined as a property referenced by _get_test_dir_absolute and the naming was
  ambiguous
- Update YAMLLint
docs/schema_command.md Show resolved Hide resolved
docs/schema_command.md Show resolved Hide resolved
docs/schema_command.md Outdated Show resolved Hide resolved

```cli
bash$ schema-enforcer schema --check
WARNING | Could not find expected_results_file /Users/ntc/schema_enforcer/examples/example3/schema/tests/ntp/invalid/invalid_format/results. Skipping...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this should be a failure rather than a warn-and-pass case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought in making it a warn-case was to have the tool not hard-fail in the event that the user is in the process of developing checks (e.g. maybe populates a few different folders with a few different test cases, but either hasn't yet defined data for those or hasn't yet defined results). I can definitely toggle this so it fails though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed with Glenn I think it should be an error

docs/schema_command.md Outdated Show resolved Hide resolved
schema_enforcer/schemas/manager.py Outdated Show resolved Hide resolved
schema_enforcer/utils.py Outdated Show resolved Hide resolved
@glennmatthews
Copy link
Contributor

Was examples/example3/schema/tests/dns_servers/invalid/invalid_ip/data.yml deleted from Git intentionally?

schema_enforcer/utils.py Outdated Show resolved Hide resolved
schema_enforcer/utils.py Outdated Show resolved Hide resolved
schema_enforcer/schemas/manager.py Show resolved Hide resolved
@PhillSimonds
Copy link
Contributor Author

Per your previous comment, I had deleted it to test something but didn't mean to commit. It's remediated :).

@PhillSimonds PhillSimonds merged commit 97edb15 into develop Jan 20, 2021
@PhillSimonds PhillSimonds deleted the psi/fix-63 branch January 20, 2021 17:48
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.

"schema-enforcer schema" throws a TypeError
3 participants