Skip to content

wip:settings validation - #630

Closed
noviluni wants to merge 3 commits into
scrapinghub:masterfrom
noviluni:add_warning_for_invalid_settings
Closed

noviluni wants to merge 3 commits into
scrapinghub:masterfrom
noviluni:add_warning_for_invalid_settings

Conversation

@noviluni

@noviluni noviluni commented Mar 7, 2020

Copy link
Copy Markdown
Contributor

I think we should add warnings if the values of the settings are not the expected.

I have done this PR to illustrate the idea of a common framework to do it.

Examples:

>>> dateparser.parse('3 days', settings={'PREFER_DAY_OF_MONTH': 'aaaa'}) 
"aaaa" is not a valid value for PREFER_DAY_OF_MONTH, it should be: 'current', 'first' or 'last'. Using default behaviour: 'current'
datetime.datetime(2020, 3, 4, 16, 36, 3, 322839)
>>> dateparser.parse('3 days', settings={'PREFER_DATES_FROM': 'afuture'})
"afuture" is not a valid value for PREFER_DATES_FROM, it should be: 'past', 'future' or 'current_period'. Using default behaviour: 'current_period'
datetime.datetime(2020, 3, 10, 16, 37, 25, 516574)
>>> dateparser.parse('03/04/05', settings={'DATE_ORDER': 'DEE'}) 
ValueError: "DEE" is not a valid value for DATE_ORDER, it should be: 'MDY', 'MYD', 'DMY', 'DYM', 'YDM' or 'YMD'. Using default behaviour: 'MDY'

Let me know what you think or any idea you have.

@codecov

codecov Bot commented Mar 7, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #630 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #630      +/-   ##
==========================================
- Coverage   95.23%   95.21%   -0.03%     
==========================================
  Files         302      302              
  Lines        2560     2507      -53     
==========================================
- Hits         2438     2387      -51     
+ Misses        122      120       -2     
Impacted Files Coverage Δ
dateparser/calendars/__init__.py 95.06% <0.00%> (-0.45%) ⬇️
dateparser/languages/validation.py 93.43% <0.00%> (-0.44%) ⬇️
dateparser/search/detection.py 94.23% <0.00%> (-0.11%) ⬇️
dateparser/parser.py 98.87% <0.00%> (-0.06%) ⬇️
dateparser/date.py 97.97% <0.00%> (-0.04%) ⬇️
dateparser/search/search.py 99.35% <0.00%> (-0.01%) ⬇️
dateparser/languages/dictionary.py 99.33% <0.00%> (ø)
dateparser/freshness_date_parser.py 98.94% <0.00%> (ø)
dateparser/calendars/jalali_parser.py 100.00% <0.00%> (ø)
dateparser/calendars/hijri_parser.py 91.30% <0.00%> (+3.80%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6dc38bb...45fa4e1. Read the comment docs.

@Gallaecio

Copy link
Copy Markdown
Contributor

I would raise ValueError.

@noviluni
noviluni marked this pull request as draft April 29, 2020 14:51
@noviluni noviluni added this to the v1.0.0 milestone Jun 22, 2020
@noviluni noviluni changed the title PoC settings validation wip:settings validation Jun 25, 2020
@noviluni noviluni mentioned this pull request Jun 25, 2020
@noviluni
noviluni force-pushed the add_warning_for_invalid_settings branch from 5e6fa6e to 768fd4a Compare June 25, 2020 12:24
@noviluni

Copy link
Copy Markdown
Contributor Author

This PR is waiting for this: #722 and this #728 to decide if we delete some older settings or not.

@noviluni

Copy link
Copy Markdown
Contributor Author

@noviluni noviluni closed this Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants