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

tests fail in March #215

Open
brianmay opened this issue Mar 10, 2017 · 12 comments
Open

tests fail in March #215

brianmay opened this issue Mar 10, 2017 · 12 comments
Assignees
Labels

Comments

@brianmay
Copy link

======================================================================
FAIL: testFloat (tests.TestDelta.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/brian/tree/debian/python-modules/parsedatetime/tests/TestDelta.py", line 64, in testFloat
    self.cal.parse('1.4 months ago', self.source), months=-1.4)
  File "/home/brian/tree/debian/python-modules/parsedatetime/tests/TestDelta.py", line 37, in assertDelta
    self.assertTrue(diff < 0.05, '%s is not less than 0.05' % diff)
AssertionError: 0.0666666666667 is not less than 0.05

----------------------------------------------------------------------

I suspect this is because February only has 28 days, not the 30 days assumed by the test.

@idpaterson
Copy link
Collaborator

idpaterson commented Mar 10, 2017

Thank you for reporting, I am personally grateful for this observation since it identifies a few issues that I need to fix in the new test suite for v3.0 (#199).

The assertion checks that there is not more than a 5% variation between the targeted time and the output, in this case your test shows 6.7%. Over the span of 1.4 months, that represents a difference of 2.8 days.

I believe that this is a bug in the test case rather than in parsedatetime. The test assertion uses the following logic to calculate months:

        if months:
            delta += datetime.timedelta(days=30 * months)

Whereas Calendar.inc(), which I believe is used in these deltas, calculates month deltas based on the calendar (1 month before March 10 is always Feb 10 regardless of leap years), then adds the partial months.

The 5% rule for deltas is problematic, that can represent a huge variation from expectation when the range is months or years. Fortunately the new test suite uses different logic for deltas and as a result this test passes (once I fixed the few minor issues that this case exposed).

To help determine whether there is actually a bug in parsedatetime, here is a comparison between 2016 and 2017:

>>> cal.parse('1.4 months ago', sourceTime=datetime.datetime(2016,3,10,9,24,0))
(time.struct_time(tm_year=2016, tm_mon=1, tm_mday=29, tm_hour=19, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=29, tm_isdst=-1), 1)
>>> cal.parse('1.4 months ago', sourceTime=datetime.datetime(2017,3,10,9,24,0))
(time.struct_time(tm_year=2017, tm_mon=1, tm_mday=30, tm_hour=4, tm_min=36, tm_sec=0, tm_wday=0, tm_yday=30, tm_isdst=-1), 1)

@bmw
Copy link

bmw commented Mar 10, 2017

Is there a way a fix for this can be prioritized? I work at EFF where I'm a developer of Certbot. Certbot depends on parsedatetime and this issue is causing some trouble in Debian packaging. In the worst case, if this bug isn't fixed parsedatetime may be removed from the next version of Debian which will also cause problems with Certbot's packaging.

When can we expect a fix for this to be available to the Debian developers so they can continue to include parsedatetime?

@idpaterson
Copy link
Collaborator

The assertion can be made more lax but I will have to defer to @bear regarding publishing a release with that change. Is that something you could push out soon, Mike?

@idpaterson idpaterson assigned idpaterson and bear and unassigned idpaterson Mar 10, 2017
@idpaterson idpaterson added the bug label Mar 10, 2017
@bear
Copy link
Owner

bear commented Mar 10, 2017

yes, we can push one a release out now if needed

@bear
Copy link
Owner

bear commented Mar 10, 2017

@idpaterson any reason we don't use Calendar.inc() to calculate that instead of the hardcoded 30 ?

@brianmay
Copy link
Author

I personally don't like the test as is, it tests something different depending on the current time. The tests should test the same thing every time it is run. If you want it to test from multiple times, that should be allowed for in the tests. Instead of requiring you to run the tests multiple times throughout the year. I would suggest the fix is to hard code the source time, to something that is known to work, for example (I picked 2017-01-01 but this is arbitrary):

diff --git a/tests/TestDelta.py b/tests/TestDelta.py
index c628d5e..054eabe 100644
--- a/tests/TestDelta.py
+++ b/tests/TestDelta.py
@@ -3,7 +3,6 @@
 Test time delta
 """
 
-import time
 import datetime
 import unittest
 import parsedatetime as pdt
@@ -13,9 +12,9 @@ class test(unittest.TestCase):
 
     def setUp(self):
         self.cal = pdt.Calendar(version=pdt.VERSION_CONTEXT_STYLE)
-        self.source = (self.yr, self.mth, self.dy,
-                       self.hr, self.mn, self.sec,
-                       self.wd, self.yd, self.isdst) = time.localtime()
+        self.source = (2017, 1, 1,
+                       7, 1, 2,
+                       6, 1, 1)
 
     def assertDelta(self, ts, years=None, months=None, **deltakw):
         ts = ts[0]

@bear
Copy link
Owner

bear commented Mar 10, 2017

I think that test may be one of the more older of them, so is very likely broken in the sense that it's not following our current style.

@idpaterson I'm all for making the change @brianmay suggests

@idpaterson
Copy link
Collaborator

idpaterson commented Mar 10, 2017

@bear I agree that using Calendar.inc() here is best. It is consistent with how the new test suite handles deltas, is already tested elsewhere, and is much more accurate than the < 5% assertion. I don't think I have time for that tonight but could work on it tomorrow if you're busy.

@brianmay the new tests for v3.0 do exactly that, every test is automatically run against a consistent set of source times. Modifying or adding to those dates is trivial, though with too many values the tests could take too long to run. I selected three dates so far:

DEFAULT_SOURCE_TIMES = (
    datetime(2016, 2, 29, 3, 4, 5),
    datetime(2015, 2, 28, 23, 22, 21),
    datetime(1945, 12, 31, 3, 4, 5),
)

@bear
Copy link
Owner

bear commented Mar 10, 2017

fixed in release v2.3 which i'm pushing out now - we can add more tests and switch to .inc() later

@bmw
Copy link

bmw commented Mar 11, 2017

Thanks so much for fixing this unbelievably quickly.

@bear
Copy link
Owner

bear commented Mar 11, 2017

I know how OS packagers can be (used to be one way back in the day) and it needed fixing...

long way of saying your welcome! :)

@exarkun
Copy link

exarkun commented Jun 30, 2021

This issue is still open but the comments suggest that the test was fixed. What's the current status?

jlarue26 added a commit to dremio/dbt-dremio that referenced this issue Mar 27, 2023
Bumps [parsedatetime](https://github.com/bear/parsedatetime) from 2.4 to
2.6.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/bear/parsedatetime/releases">parsedatetime's
releases</a>.</em></p>
<blockquote>
<h2>2.6</h2>
<p>Push out v2.6 to gather up local fixes and updates</p>
<p>PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/244">#244</a>
Polished README.rst
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/242">#242</a>
fix pyicu import to suppress warnings
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/239">#239</a>
Fixed missing comma in seconds strings</p>
<p>Updated Pipfile and Makefile to:
- update and move packages to the &quot;dev&quot; section
- use Python 3.7 for pipenv
- install tox-pipenv plugin to try and fix Tox (currently doesn't)
- simplify tox.ini to try and fix Tox (didn't)
- move ci makefile target to the circle config</p>
<h2>2.5</h2>
<p>v2.5 release</p>
<p>PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/222">#222</a>
Fix to sanitize abbreviated months from icu
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/223">#223</a>
typo in RU locale in abbreviation for January
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/224">#224</a>
Fix lint errors for flake8 v3.5.0
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/225">#225</a>
Add a constant for start hour
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/233">#233</a>
Add 'secs' and 'mins' into base units
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/226">#226</a>
Remove unused dependency on future</p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/bear/parsedatetime/blob/master/CHANGES.txt">parsedatetime's
changelog</a>.</em></p>
<blockquote>
<p>9 Oct 2021 - bear
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/261">#261</a>
Bump urllib3 from 1.25.9 to 1.26.5
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/255">#255</a>
support 'next 10 days' query
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/252">#252</a>
Include pytest.ini in source distributions, fixes tests
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/250">#250</a>
Update nl_NL.py
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/248">#248</a>
pyicu 'module' object has no attribute 'Locale'</p>
<pre><code>Update Pipfile to reference Python 3.9
Updated Copyright statement
</code></pre>
<p>31 May 2020 - bear
v2.6 release
bump version to v2.7</p>
<p>PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/244">#244</a>
Polished README.rst
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/242">#242</a>
fix pyicu import to suppress warnings
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/239">#239</a>
Fixed missing comma in seconds strings</p>
<p>Updated Pipfile and Makefile to:
- update and move packages to the &quot;dev&quot; section
- use Python 3.7 for pipenv
- install tox-pipenv plugin to try and fix Tox (currently doesn't)
- simplify tox.ini to try and fix Tox (didn't)
- move ci makefile target to the circle config</p>
<p>Currently Tox is broken (see <a
href="https://redirect.github.com/tox-dev/tox-pipenv/issues/61">tox-dev/tox-pipenv#61</a>)</p>
<p>18 Nov 2019 - bear
v2.5 release</p>
<p>PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/222">#222</a>
Fix to sanitize abbreviated months from icu
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/223">#223</a>
typo in RU locale in abbreviation for January
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/224">#224</a>
Fix lint errors for flake8 v3.5.0
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/225">#225</a>
Add a constant for start hour
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/233">#233</a>
Add 'secs' and 'mins' into base units
PR <a
href="https://redirect.github.com/bear/parsedatetime/issues/226">#226</a>
Remove unused dependency on future</p>
<p>14 May 2017 - bear
v2.4 release
v2.5 bump</p>
<pre><code>Issue
[#219](bear/parsedatetime#219) - remove
'setup_requires' from setup.py
</code></pre>
<p>10 Mar 2017 - bear
v2.3 release
v2.4 bump</p>
<pre><code>Issue
[#215](bear/parsedatetime#215) - tests fail in
March
</code></pre>
<p>02 Mar 2016 - bear</p>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/bear/parsedatetime/commit/c55337589ee582813182b74f2d3ae80e2fcd9738"><code>c553375</code></a>
force update</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/55a2b1d16df3eb9a4977be5da0ccdfc7162235d5"><code>55a2b1d</code></a>
Updated Pipfile and Makefile to:</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/50dc61787bfa703cb50d8dd0a46d7b19032e02b0"><code>50dc617</code></a>
Merge pull request <a
href="https://redirect.github.com/bear/parsedatetime/issues/242">#242</a>
from quantrocket-llc/master</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/acb579820dc34aa1b9aaa15a3e0afd058fad7702"><code>acb5798</code></a>
Merge pull request <a
href="https://redirect.github.com/bear/parsedatetime/issues/244">#244</a>
from boxed/patch-2</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/f0110909d06d48d31cdd408ea0a6764fc8b06e03"><code>f011090</code></a>
Update README.rst</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/18837504778c0dd41ae412bdf86eb81b1be7cdd7"><code>1883750</code></a>
fix pyicu import to suppress warnings</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/655783d5f96a1defd331da84478fb8f3efb0f3b9"><code>655783d</code></a>
Merge pull request <a
href="https://redirect.github.com/bear/parsedatetime/issues/239">#239</a>
from psav/psav/fix_missing_comma</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/7a759c1f8ff7563f12ac2c1f2ea0b41452f61dec"><code>7a759c1</code></a>
Fixed missing comma in seconds strings</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/bea2bdb56992d2ae639843cc8a961818ac394794"><code>bea2bdb</code></a>
Convert to using pipenv and simplify to python 3.7 and 2.7 for
testing</li>
<li><a
href="https://github.com/bear/parsedatetime/commit/04c095790f0a2f9b8d32f35cfbb8498e7f6dc9be"><code>04c0957</code></a>
v2.6 bump</li>
<li>Additional commits viewable in <a
href="https://github.com/bear/parsedatetime/compare/v2.4...v2.6">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=parsedatetime&package-manager=pip&previous-version=2.4&new-version=2.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jared <97905507+jlarue26@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants