Add tests for MarketUtil.parse_date and fix its utcnow() deprecation - #81
Open
propcgamer20-png wants to merge 2 commits into
Open
propcgamer20-png wants to merge 2 commits into
propcgamer20-png wants to merge 2 commits into
Conversation
… without it
`import finmarketpy` - and therefore `pytest` collecting any test - hard
failed whenever the optional `chartpy` plotting stack could not be
imported (e.g. a plotly version mismatch inside chartpy). Five modules
imported `chartpy` at module load:
economics/quickchart.py, economics/report.py,
backtest/backtestcomparison.py, backtest/backtestengine.py,
backtest/tradeanalysis.py
and finmarketpy/__init__ eagerly imports all of them, so the whole test
suite errored at collection ("Interrupted: 1 error during collection").
Changes:
- quickchart.py: import Chart / Style locally in the methods that draw
(dropped the unused ChartConstants import).
- report.py / backtestcomparison.py / backtestengine.py /
tradeanalysis.py: wrap the top-level `from chartpy import ...` in
try/except ImportError, falling back to None, and guard the
class-body `ChartConstants()` / `Style()` evaluations and
TradeAnalysis.__init__'s default engine arg.
When chartpy is installed, behaviour is unchanged. When it is missing or
broken, the modules import (chart attributes are None) and only actually
drawing a chart fails. `pytest tests/` now collects and passes (5 passed,
was 0 collected / 1 error). `ruff check` on the touched files is
unchanged (81 pre-existing findings, 0 added).
Closes cuemacro#71
MarketUtil.parse_date had no test coverage. Adds tests/test_marketutil.py
covering the relative-keyword forms ("midnight", "year", "week", "day",
"hour", "decade"), the four documented string date formats, the
non-string passthrough, and the Timestamp return type.
Also replaces the deprecated `datetime.datetime.utcnow()` (removed in a
future Python) with `datetime.datetime.now(datetime.timezone.utc)
.replace(tzinfo=None)`, which keeps the existing naive-UTC semantics.
Toward cuemacro#71 (increase test coverage). Stacked on the chartpy lazy-import
change so the tests can collect.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Toward #71 ("Increase test coverage").
MarketUtil.parse_date(src/finmarketpy/util/marketutil.py) had no test coverage. Addstests/test_marketutil.py(13 tests) covering:midnight,decade,year,month,week,day,hour%b %d %Y %H:%M,%d %b %Y %H:%M,%b %d %Y,%d %b %Y)pd.Timestamp/datetime/date)pd.Timestampreturn typeAlso replaces the deprecated
datetime.datetime.utcnow()withdatetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)- a drop-in that preserves the existing naive-UTC semantics (sopd.Timestamp(date1)stays tz-naive as before).Stacked on #79 (
lazy-chartpy-import) - without itfrom finmarketpy.util.marketutil import MarketUtilcan't be imported (and no test collects) when the optionalchartpyplotting stack is unavailable. Once #79 merges, this PR's diff narrows to just the two files here.Toward #71