-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new CLI command
summary
(#1127)
* Added command summary * Added command named summary * Added to_summary function to ReportTask * Added tests for both 'summary' command and 'to_summary' function * fixes for failing tests * Revised code * Rearranged code and placed it in the relevant places "separation of concerns" * Made changes to tests and added new tests * Revised summary command code * added test for file not found error * refactor validate command * replaced the report table display code with new to_summary function * fixed failing tests * removed print statement * made validation_summary part of the report class * fixes to failing test * simplified test output for multiline text * * Refactored display summary code in report.py class/file. Added validation_summary as to_summary to report task class * Changed the code of report.to_summary to use reporttask summary function * Removed unrelated tests code added in previous commit and added new ones for schema, resource, reporttask and report * Organized tests files for summary feature * fixes for failing tests
- Loading branch information
1 parent
b25c896
commit 8ba2621
Showing
17 changed files
with
687 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,20 @@ | ||
# ------- | ||
# invalid: test-tabulator | ||
# ------- | ||
## Errors | ||
|
||
|
||
# Summary | ||
|
||
Description Size/Name/Count | ||
------------------------------- ----------------- | ||
File name (Not Found) test-tabulator | ||
File size N/A | ||
Total Time Taken (sec) | ||
Total Errors 1 | ||
Resource Error (resource-error) 1 | ||
|
||
# Errors | ||
|
||
row field code message | ||
----- ------- --------- ------------------------------------------------- | ||
resource- The data resource has an error: "{'format': | ||
error 'inline', 'hashing': 'md5', 'name': 'test- | ||
tabulator', 'profile': 'tabular-data-resource', | ||
'resources': [{'name': 'first-resource', 'path': | ||
'table.xls', 'schema': {'fields': [{'name': 'id', | ||
'type': 'number'}, {'name': 'name', 'type': | ||
'string'}]}}, {'name': 'number-two', 'path': | ||
'table-reverse.csv', 'schema': {'fields': | ||
[{'name': 'id', 'type': 'integer'}, {'name': | ||
'name', 'type': 'string'}]}}], 'scheme': '', | ||
'stats': {'bytes': 0, 'fields': 0, 'hash': '', | ||
'rows': 0}} is not valid under any of the given | ||
schemas" at "" in metadata and at "oneOf" in | ||
profile | ||
+-------+---------+-----------+---------------------------------------------------+ | ||
| row | field | code | message | | ||
+=======+=========+===========+===================================================+ | ||
| | | resource- | The data resource has an error: "{'format': | | ||
| | | error | 'inline', 'hashing': 'md5', 'name': 'test- | | ||
| | | | tabulator', 'profile': 'tabular-data-resource', | | ||
| | | | 'resources': [{'name': 'first-resource', 'path': | | ||
| | | | 'table.xls', 'schema': {'fields': [{'name': 'id', | | ||
| | | | 'type': 'number'}, {'name': 'name', 'type': | | ||
| | | | 'string'}]}}, {'name': 'number-two', 'path': | | ||
| | | | 'table-reverse.csv', 'schema': {'fields': | | ||
| | | | [{'name': 'id', 'type': 'integer'}, {'name': | | ||
| | | | 'name', 'type': 'string'}]}}], 'scheme': '', | | ||
| | | | 'stats': {'bytes': 0, 'fields': 0, 'hash': '', | | ||
| | | | 'rows': 0}} is not valid under any of the given | | ||
| | | | schemas" at "" in metadata and at "oneOf" in | | ||
| | | | profile | | ||
+-------+---------+-----------+---------------------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,8 @@ | ||
# ----- | ||
# valid: ogd10_energieforschungstatistik_ch.csv | ||
# ----- | ||
|
||
# Summary | ||
|
||
Description Size/Name/Count | ||
---------------------- -------------------------------------- | ||
File name ogd10_energieforschungstatistik_ch.csv | ||
File size (KB) 88541 | ||
Total Time Taken (sec) | ||
# ------- | ||
# invalid: ogd10_catalogs.zip => capital-invalid.csv | ||
# ------- | ||
|
||
|
||
# Summary | ||
|
||
Description Size/Name/Count | ||
--------------------------- ----------------------------------------- | ||
File name (Not Found) ogd10_catalogs.zip => capital-invalid.csv | ||
File size N/A | ||
Total Time Taken (sec) | ||
Total Errors 1 | ||
Schema Error (schema-error) 1 | ||
|
||
# Errors | ||
|
||
row field code message | ||
----- ------- ------- ------------------------------------------------- | ||
schema- Schema is not valid: Schemas with duplicate field | ||
error names are not supported | ||
|
||
# ----- | ||
# valid: ogd10_catalogs.zip => finanzquellen.csv | ||
# ----- | ||
|
||
# Summary | ||
|
||
Description Size/Name/Count | ||
---------------------- --------------------------------------- | ||
File name (Not Found) ogd10_catalogs.zip => finanzquellen.csv | ||
File size N/A | ||
Total Time Taken (sec) | ||
## Errors | ||
|
||
+-------+---------+---------+---------------------------------------------------+ | ||
| row | field | code | message | | ||
+=======+=========+=========+===================================================+ | ||
| | | schema- | Schema is not valid: Schemas with duplicate field | | ||
| | | error | names are not supported | | ||
+-------+---------+---------+---------------------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
+-------+---------+------------+----------------------------------------------------+ | ||
| row | field | code | message | | ||
+=======+=========+============+====================================================+ | ||
| 4 | 5 | extra-cell | Row at position "4" has an extra value in field at | | ||
| | | | position "5" | | ||
+-------+---------+------------+----------------------------------------------------+ | ||
| 7 | 2 | missing- | Row at position "7" has a missing cell in field | | ||
| | | cell | "neighbor_id" at position "2" | | ||
+-------+---------+------------+----------------------------------------------------+ | ||
| 7 | 3 | missing- | Row at position "7" has a missing cell in field | | ||
| | | cell | "name" at position "3" | | ||
+-------+---------+------------+----------------------------------------------------+ | ||
| 7 | 4 | missing- | Row at position "7" has a missing cell in field | | ||
| | | cell | "population" at position "4" | | ||
+-------+---------+------------+----------------------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Errors | ||
|
||
+-------+---------+---------+---------------------------------------------------+ | ||
| row | field | code | message | | ||
+=======+=========+=========+===================================================+ | ||
| | | scheme- | The data source could not be successfully loaded: | | ||
| | | error | [Errno 2] No such file or directory: | | ||
| | | | 'data/countriess.csv' | | ||
+-------+---------+---------+---------------------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from .api import program_api | ||
from .describe import program_describe | ||
from .extract import program_extract | ||
from .summary import program_summary | ||
from .main import program, program_main | ||
from .transform import program_transform | ||
from .validate import program_validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import typer | ||
from .main import program | ||
from . import common | ||
from ..resource import Resource | ||
|
||
|
||
@program.command(name="summary") | ||
def program_summary(source: str = common.source): | ||
"""Summary of data source. | ||
It will return schema, sample of the data and validation report for the resource. | ||
""" | ||
# Validate input | ||
if not source: | ||
message = 'Providing "source" is required' | ||
typer.secho(message, err=True, fg=typer.colors.RED, bold=True) | ||
raise typer.Exit(1) | ||
# Infer Resource | ||
try: | ||
resource = Resource(source) | ||
resource.infer() | ||
except Exception as exception: | ||
typer.secho(str(exception), err=True, fg=typer.colors.RED, bold=True) | ||
raise typer.Exit(1) | ||
typer.secho("") | ||
typer.secho("# Describe ", bold=True) | ||
typer.secho("") | ||
typer.secho(str(resource.schema.to_summary())) | ||
typer.secho("") | ||
typer.secho("# Extract ", bold=True) | ||
typer.secho("") | ||
typer.secho(str(resource.to_view())) | ||
# Validate | ||
try: | ||
report = resource.validate() | ||
except Exception as exception: | ||
typer.secho(str(exception), err=True, fg=typer.colors.RED, bold=True) | ||
raise typer.Exit(1) | ||
typer.secho("") | ||
typer.secho("# Validate ", bold=True) | ||
typer.secho(str(report.to_summary())) | ||
|
||
# Return retcode | ||
raise typer.Exit(code=int(not report.valid)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.