lib-x17-fintech 2.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lib_x17_fintech-2.1.3.dist-info/METADATA +633 -0
- lib_x17_fintech-2.1.3.dist-info/RECORD +282 -0
- lib_x17_fintech-2.1.3.dist-info/WHEEL +5 -0
- lib_x17_fintech-2.1.3.dist-info/licenses/LICENSE +1 -0
- lib_x17_fintech-2.1.3.dist-info/top_level.txt +1 -0
- xfintech/__init__.py +0 -0
- xfintech/connect/__init__.py +18 -0
- xfintech/connect/artifact/__init__.py +5 -0
- xfintech/connect/artifact/artifact.py +168 -0
- xfintech/connect/artifact/tests/__init__.py +3 -0
- xfintech/connect/artifact/tests/test_class_artifact_all.py +564 -0
- xfintech/connect/common/__init__.py +12 -0
- xfintech/connect/common/connect.py +49 -0
- xfintech/connect/common/connectref.py +119 -0
- xfintech/connect/common/error.py +62 -0
- xfintech/connect/common/tests/__init__.py +1 -0
- xfintech/connect/common/tests/test_class_connectlike_all.py +544 -0
- xfintech/connect/common/tests/test_class_connectref_all.py +586 -0
- xfintech/connect/common/tests/test_class_errors_all.py +524 -0
- xfintech/connect/instance/__init__.py +7 -0
- xfintech/connect/instance/macos.py +121 -0
- xfintech/connect/instance/s3.py +176 -0
- xfintech/connect/instance/tests/__init__.py +1 -0
- xfintech/connect/instance/tests/test_class_macosconnect_all.py +692 -0
- xfintech/connect/instance/tests/test_class_s3connect_all.py +603 -0
- xfintech/data/__init__.py +20 -0
- xfintech/data/common/__init__.py +15 -0
- xfintech/data/common/cache.py +186 -0
- xfintech/data/common/coolant.py +171 -0
- xfintech/data/common/metric.py +138 -0
- xfintech/data/common/paginate.py +132 -0
- xfintech/data/common/params.py +162 -0
- xfintech/data/common/retry.py +201 -0
- xfintech/data/common/tests/__init__.py +1 -0
- xfintech/data/common/tests/test_class_cache_all.py +681 -0
- xfintech/data/common/tests/test_class_coolant_all.py +534 -0
- xfintech/data/common/tests/test_class_metric_all.py +705 -0
- xfintech/data/common/tests/test_class_paginate_all.py +508 -0
- xfintech/data/common/tests/test_class_params_all.py +891 -0
- xfintech/data/common/tests/test_class_retry_all.py +714 -0
- xfintech/data/job/__init__.py +17 -0
- xfintech/data/job/errors.py +112 -0
- xfintech/data/job/house.py +156 -0
- xfintech/data/job/job.py +247 -0
- xfintech/data/job/joblike.py +47 -0
- xfintech/data/job/tests/__init__.py +1 -0
- xfintech/data/job/tests/test_class_errors_all.py +275 -0
- xfintech/data/job/tests/test_class_house_all.py +801 -0
- xfintech/data/job/tests/test_class_job_all.py +684 -0
- xfintech/data/job/tests/test_class_joblike_all.py +482 -0
- xfintech/data/relay/__init__.py +7 -0
- xfintech/data/relay/client.py +114 -0
- xfintech/data/relay/clientlike.py +45 -0
- xfintech/data/relay/tests/test_class_relayclient_all.py +484 -0
- xfintech/data/relay/tests/test_class_relayclientlike_all.py +500 -0
- xfintech/data/source/__init__.py +7 -0
- xfintech/data/source/baostock/__init__.py +21 -0
- xfintech/data/source/baostock/job/__init__.py +5 -0
- xfintech/data/source/baostock/job/job.py +217 -0
- xfintech/data/source/baostock/job/tests/__init__.py +0 -0
- xfintech/data/source/baostock/job/tests/test_class_baostockjob_all.py +547 -0
- xfintech/data/source/baostock/session/__init__.py +8 -0
- xfintech/data/source/baostock/session/relay.py +223 -0
- xfintech/data/source/baostock/session/session.py +241 -0
- xfintech/data/source/baostock/session/tests/__init__.py +0 -0
- xfintech/data/source/baostock/session/tests/test_class_relay_all.py +694 -0
- xfintech/data/source/baostock/session/tests/test_class_session_all.py +505 -0
- xfintech/data/source/baostock/stock/__init__.py +0 -0
- xfintech/data/source/baostock/stock/hs300stock/__init__.py +3 -0
- xfintech/data/source/baostock/stock/hs300stock/constant.py +49 -0
- xfintech/data/source/baostock/stock/hs300stock/hs300stock.py +133 -0
- xfintech/data/source/baostock/stock/hs300stock/tests/__init__.py +1 -0
- xfintech/data/source/baostock/stock/hs300stock/tests/test_class_hs300index_all.py +413 -0
- xfintech/data/source/baostock/stock/minuteline/__init__.py +19 -0
- xfintech/data/source/baostock/stock/minuteline/constant.py +89 -0
- xfintech/data/source/baostock/stock/minuteline/minuteline.py +163 -0
- xfintech/data/source/baostock/stock/minuteline/tests/__init__.py +0 -0
- xfintech/data/source/baostock/stock/minuteline/tests/test_class_minuteline_all.py +582 -0
- xfintech/data/source/baostock/stock/stock/__init__.py +19 -0
- xfintech/data/source/baostock/stock/stock/constant.py +55 -0
- xfintech/data/source/baostock/stock/stock/stock.py +149 -0
- xfintech/data/source/baostock/stock/stock/tests/__init__.py +0 -0
- xfintech/data/source/baostock/stock/stock/tests/test_class_stock_all.py +508 -0
- xfintech/data/source/baostock/stock/stockinfo/__init__.py +5 -0
- xfintech/data/source/baostock/stock/stockinfo/constant.py +66 -0
- xfintech/data/source/baostock/stock/stockinfo/stockinfo.py +176 -0
- xfintech/data/source/baostock/stock/stockinfo/tests/__init__.py +1 -0
- xfintech/data/source/baostock/stock/stockinfo/tests/test_class_stockinfo_all.py +617 -0
- xfintech/data/source/baostock/stock/sz50stock/__init__.py +3 -0
- xfintech/data/source/baostock/stock/sz50stock/constant.py +49 -0
- xfintech/data/source/baostock/stock/sz50stock/sz50stock.py +133 -0
- xfintech/data/source/baostock/stock/sz50stock/tests/__init__.py +1 -0
- xfintech/data/source/baostock/stock/sz50stock/tests/test_class_sz50stock_all.py +397 -0
- xfintech/data/source/baostock/stock/tradedate/__init__.py +19 -0
- xfintech/data/source/baostock/stock/tradedate/constant.py +72 -0
- xfintech/data/source/baostock/stock/tradedate/tests/__init__.py +0 -0
- xfintech/data/source/baostock/stock/tradedate/tests/test_class_tradedate_all.py +695 -0
- xfintech/data/source/baostock/stock/tradedate/tradedate.py +208 -0
- xfintech/data/source/baostock/stock/zz500stock/__init__.py +3 -0
- xfintech/data/source/baostock/stock/zz500stock/constant.py +55 -0
- xfintech/data/source/baostock/stock/zz500stock/tests/__init__.py +1 -0
- xfintech/data/source/baostock/stock/zz500stock/tests/test_class_zz500stock_all.py +421 -0
- xfintech/data/source/baostock/stock/zz500stock/zz500stock.py +133 -0
- xfintech/data/source/tushare/__init__.py +61 -0
- xfintech/data/source/tushare/job/__init__.py +5 -0
- xfintech/data/source/tushare/job/job.py +257 -0
- xfintech/data/source/tushare/job/tests/test_class_tusharejob_all.py +589 -0
- xfintech/data/source/tushare/session/__init__.py +5 -0
- xfintech/data/source/tushare/session/relay.py +231 -0
- xfintech/data/source/tushare/session/session.py +239 -0
- xfintech/data/source/tushare/session/tests/test_class_relay_all.py +719 -0
- xfintech/data/source/tushare/session/tests/test_class_session_all.py +705 -0
- xfintech/data/source/tushare/stock/__init__.py +55 -0
- xfintech/data/source/tushare/stock/adjfactor/__init__.py +19 -0
- xfintech/data/source/tushare/stock/adjfactor/adjfactor.py +150 -0
- xfintech/data/source/tushare/stock/adjfactor/constant.py +71 -0
- xfintech/data/source/tushare/stock/adjfactor/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/adjfactor/tests/test_class_adjfactor_all.py +372 -0
- xfintech/data/source/tushare/stock/capflow/__init__.py +19 -0
- xfintech/data/source/tushare/stock/capflow/capflow.py +171 -0
- xfintech/data/source/tushare/stock/capflow/constant.py +105 -0
- xfintech/data/source/tushare/stock/capflow/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/capflow/tests/test_class_capflow_all.py +589 -0
- xfintech/data/source/tushare/stock/capflowdc/__init__.py +19 -0
- xfintech/data/source/tushare/stock/capflowdc/capflowdc.py +167 -0
- xfintech/data/source/tushare/stock/capflowdc/constant.py +95 -0
- xfintech/data/source/tushare/stock/capflowdc/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/capflowdc/tests/test_class_capflowdc_all.py +814 -0
- xfintech/data/source/tushare/stock/capflowths/__init__.py +19 -0
- xfintech/data/source/tushare/stock/capflowths/capflowths.py +173 -0
- xfintech/data/source/tushare/stock/capflowths/constant.py +92 -0
- xfintech/data/source/tushare/stock/capflowths/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/capflowths/tests/test_class_capflowths_all.py +551 -0
- xfintech/data/source/tushare/stock/company/__init__.py +19 -0
- xfintech/data/source/tushare/stock/company/company.py +188 -0
- xfintech/data/source/tushare/stock/company/constant.py +92 -0
- xfintech/data/source/tushare/stock/company/tests/__init__.py +1 -0
- xfintech/data/source/tushare/stock/company/tests/test_class_company_all.py +829 -0
- xfintech/data/source/tushare/stock/companybusiness/__init__.py +21 -0
- xfintech/data/source/tushare/stock/companybusiness/companybusiness.py +183 -0
- xfintech/data/source/tushare/stock/companybusiness/constant.py +91 -0
- xfintech/data/source/tushare/stock/companybusiness/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companybusiness/tests/test_class_companybusiness_all.py +633 -0
- xfintech/data/source/tushare/stock/companycashflow/__init__.py +21 -0
- xfintech/data/source/tushare/stock/companycashflow/companycashflow.py +277 -0
- xfintech/data/source/tushare/stock/companycashflow/constant.py +293 -0
- xfintech/data/source/tushare/stock/companycashflow/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companycashflow/tests/test_class_companycashflow_all.py +619 -0
- xfintech/data/source/tushare/stock/companydebt/__init__.py +19 -0
- xfintech/data/source/tushare/stock/companydebt/companydebt.py +339 -0
- xfintech/data/source/tushare/stock/companydebt/constant.py +403 -0
- xfintech/data/source/tushare/stock/companydebt/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companydebt/tests/test_class_companydebt_all.py +655 -0
- xfintech/data/source/tushare/stock/companyoverview/__init__.py +21 -0
- xfintech/data/source/tushare/stock/companyoverview/companyoverview.py +214 -0
- xfintech/data/source/tushare/stock/companyoverview/constant.py +152 -0
- xfintech/data/source/tushare/stock/companyoverview/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companyoverview/tests/test_class_companyoverview_all.py +647 -0
- xfintech/data/source/tushare/stock/companyprofit/__init__.py +21 -0
- xfintech/data/source/tushare/stock/companyprofit/companyprofit.py +272 -0
- xfintech/data/source/tushare/stock/companyprofit/constant.py +259 -0
- xfintech/data/source/tushare/stock/companyprofit/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/companyprofit/tests/test_class_companyprofit_all.py +635 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/__init__.py +21 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/conceptcapflowdc.py +175 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/constant.py +106 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/conceptcapflowdc/tests/test_class_conceptcapflowdc_all.py +568 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/__init__.py +21 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/conceptcapflowths.py +188 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/constant.py +89 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/conceptcapflowths/tests/test_class_conceptcapflowths_all.py +516 -0
- xfintech/data/source/tushare/stock/dayline/__init__.py +19 -0
- xfintech/data/source/tushare/stock/dayline/constant.py +87 -0
- xfintech/data/source/tushare/stock/dayline/dayline.py +177 -0
- xfintech/data/source/tushare/stock/dayline/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/dayline/tests/test_class_dayline_all.py +585 -0
- xfintech/data/source/tushare/stock/industrycapflowths/__init__.py +21 -0
- xfintech/data/source/tushare/stock/industrycapflowths/constant.py +89 -0
- xfintech/data/source/tushare/stock/industrycapflowths/industrycapflowths.py +192 -0
- xfintech/data/source/tushare/stock/industrycapflowths/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/industrycapflowths/tests/test_class_industrycapflowths_all.py +683 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/__init__.py +21 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/constant.py +90 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/marketindexcapflowdc.py +173 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/marketindexcapflowdc/tests/test_class_marketindexcapflowdc_all.py +793 -0
- xfintech/data/source/tushare/stock/monthline/__init__.py +19 -0
- xfintech/data/source/tushare/stock/monthline/constant.py +87 -0
- xfintech/data/source/tushare/stock/monthline/monthline.py +180 -0
- xfintech/data/source/tushare/stock/monthline/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/monthline/tests/test_class_monthline_all.py +574 -0
- xfintech/data/source/tushare/stock/stock/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stock/constant.py +105 -0
- xfintech/data/source/tushare/stock/stock/stock.py +193 -0
- xfintech/data/source/tushare/stock/stock/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stock/tests/test_class_stock_all.py +788 -0
- xfintech/data/source/tushare/stock/stockdividend/__init__.py +21 -0
- xfintech/data/source/tushare/stock/stockdividend/constant.py +111 -0
- xfintech/data/source/tushare/stock/stockdividend/stockdividend.py +180 -0
- xfintech/data/source/tushare/stock/stockdividend/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockdividend/tests/test_class_stockdividend_all.py +725 -0
- xfintech/data/source/tushare/stock/stockinfo/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stockinfo/constant.py +104 -0
- xfintech/data/source/tushare/stock/stockinfo/stockinfo.py +208 -0
- xfintech/data/source/tushare/stock/stockinfo/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockinfo/tests/test_class_stockinfo_all.py +881 -0
- xfintech/data/source/tushare/stock/stockipo/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stockipo/constant.py +90 -0
- xfintech/data/source/tushare/stock/stockipo/stockipo.py +234 -0
- xfintech/data/source/tushare/stock/stockipo/tests/__init__.py +1 -0
- xfintech/data/source/tushare/stock/stockipo/tests/test_class_stockipo_all.py +750 -0
- xfintech/data/source/tushare/stock/stockpledge/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stockpledge/constant.py +72 -0
- xfintech/data/source/tushare/stock/stockpledge/stockpledge.py +158 -0
- xfintech/data/source/tushare/stock/stockpledge/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockpledge/tests/test_class_stockpledge_all.py +664 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/__init__.py +21 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/constant.py +85 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/stockpledgedetail.py +171 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockpledgedetail/tests/test_class_stockpledgedetail_all.py +112 -0
- xfintech/data/source/tushare/stock/stockst/__init__.py +19 -0
- xfintech/data/source/tushare/stock/stockst/constant.py +80 -0
- xfintech/data/source/tushare/stock/stockst/stockst.py +189 -0
- xfintech/data/source/tushare/stock/stockst/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stockst/tests/test_class_stockst_all.py +693 -0
- xfintech/data/source/tushare/stock/stocksuspend/__init__.py +21 -0
- xfintech/data/source/tushare/stock/stocksuspend/constant.py +75 -0
- xfintech/data/source/tushare/stock/stocksuspend/stocksuspend.py +151 -0
- xfintech/data/source/tushare/stock/stocksuspend/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/stocksuspend/tests/test_class_stocksuspend_all.py +626 -0
- xfintech/data/source/tushare/stock/techindex/__init__.py +19 -0
- xfintech/data/source/tushare/stock/techindex/constant.py +600 -0
- xfintech/data/source/tushare/stock/techindex/techindex.py +314 -0
- xfintech/data/source/tushare/stock/techindex/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/techindex/tests/test_class_techindex_all.py +576 -0
- xfintech/data/source/tushare/stock/tradedate/__init__.py +19 -0
- xfintech/data/source/tushare/stock/tradedate/constant.py +93 -0
- xfintech/data/source/tushare/stock/tradedate/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/tradedate/tests/test_class_tradedate_all.py +947 -0
- xfintech/data/source/tushare/stock/tradedate/tradedate.py +234 -0
- xfintech/data/source/tushare/stock/weekline/__init__.py +19 -0
- xfintech/data/source/tushare/stock/weekline/constant.py +87 -0
- xfintech/data/source/tushare/stock/weekline/tests/__init__.py +0 -0
- xfintech/data/source/tushare/stock/weekline/tests/test_class_weekline_all.py +575 -0
- xfintech/data/source/tushare/stock/weekline/weekline.py +182 -0
- xfintech/fabric/__init__.py +18 -0
- xfintech/fabric/column/__init__.py +7 -0
- xfintech/fabric/column/info.py +202 -0
- xfintech/fabric/column/kind.py +102 -0
- xfintech/fabric/column/tests/__init__.py +0 -0
- xfintech/fabric/column/tests/test_class_info_all.py +207 -0
- xfintech/fabric/column/tests/test_class_kind_all.py +80 -0
- xfintech/fabric/table/__init__.py +5 -0
- xfintech/fabric/table/info.py +263 -0
- xfintech/fabric/table/tests/__init__.py +0 -0
- xfintech/fabric/table/tests/test_class_info_all.py +547 -0
- xfintech/serde/__init__.py +35 -0
- xfintech/serde/common/__init__.py +9 -0
- xfintech/serde/common/dataformat.py +78 -0
- xfintech/serde/common/deserialiserlike.py +38 -0
- xfintech/serde/common/error.py +182 -0
- xfintech/serde/common/serialiserlike.py +38 -0
- xfintech/serde/common/tests/__init__.py +1 -0
- xfintech/serde/common/tests/test_class_dataformat_all.py +694 -0
- xfintech/serde/common/tests/test_class_deserialiserlike_all.py +500 -0
- xfintech/serde/common/tests/test_class_errors_all.py +518 -0
- xfintech/serde/common/tests/test_class_serialiserlike_all.py +401 -0
- xfintech/serde/deserialiser/__init__.py +7 -0
- xfintech/serde/deserialiser/pandas.py +113 -0
- xfintech/serde/deserialiser/python.py +68 -0
- xfintech/serde/deserialiser/tests/__init__.py +1 -0
- xfintech/serde/deserialiser/tests/test_class_pandasdeserialiser_all.py +503 -0
- xfintech/serde/deserialiser/tests/test_class_pythondeserialiser_all.py +570 -0
- xfintech/serde/serialiser/__init__.py +7 -0
- xfintech/serde/serialiser/pandas.py +116 -0
- xfintech/serde/serialiser/python.py +71 -0
- xfintech/serde/serialiser/tests/__init__.py +1 -0
- xfintech/serde/serialiser/tests/test_class_pandasserialiser_all.py +474 -0
- xfintech/serde/serialiser/tests/test_class_pythonserialiser_all.py +508 -0
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from xfintech.data.source.tushare.stock.companycashflow import CompanyCashflow
|
|
5
|
+
from xfintech.data.source.tushare.stock.companycashflow.constant import (
|
|
6
|
+
KEY,
|
|
7
|
+
NAME,
|
|
8
|
+
PAGINATE,
|
|
9
|
+
SOURCE,
|
|
10
|
+
TARGET,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
# Test Fixtures
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class FakeConnection:
|
|
17
|
+
"""Fake Tushare connection for testing"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, frame: pd.DataFrame):
|
|
20
|
+
self.frame = frame
|
|
21
|
+
|
|
22
|
+
def cashflow_vip(self, **kwargs):
|
|
23
|
+
"""Mock cashflow_vip API call"""
|
|
24
|
+
return self.frame
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class FakeSession:
|
|
28
|
+
"""Fake session for testing"""
|
|
29
|
+
|
|
30
|
+
def __init__(self, connection: FakeConnection):
|
|
31
|
+
self.connection = connection
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@pytest.fixture
|
|
35
|
+
def mock_session():
|
|
36
|
+
"""Create a mock session with empty data"""
|
|
37
|
+
fake_conn = FakeConnection(frame=pd.DataFrame())
|
|
38
|
+
return FakeSession(fake_conn)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.fixture
|
|
42
|
+
def sample_source_data():
|
|
43
|
+
"""Sample cash flow data in Tushare format"""
|
|
44
|
+
return pd.DataFrame(
|
|
45
|
+
{
|
|
46
|
+
"ts_code": ["000001.SZ", "000001.SZ", "000002.SZ"],
|
|
47
|
+
"ann_date": ["20200430", "20201031", "20200430"],
|
|
48
|
+
"f_ann_date": ["20200430", "20201031", "20200430"],
|
|
49
|
+
"end_date": ["20200331", "20200930", "20200331"],
|
|
50
|
+
"comp_type": ["2", "2", "1"],
|
|
51
|
+
"report_type": ["1", "1", "1"],
|
|
52
|
+
"end_type": ["Q1", "Q3", "Q1"],
|
|
53
|
+
"net_profit": ["100000.50", "120000.75", "50000.25"],
|
|
54
|
+
"n_cashflow_act": ["150000.30", "180000.40", "60000.15"],
|
|
55
|
+
"n_cashflow_inv_act": ["-80000.20", "-90000.35", "-30000.10"],
|
|
56
|
+
"n_cash_flows_fnc_act": ["50000.00", "60000.00", "20000.00"],
|
|
57
|
+
"c_cash_equ_beg_period": ["200000.50", "270000.75", "100000.25"],
|
|
58
|
+
"c_cash_equ_end_period": ["270000.25", "340000.50", "120000.10"],
|
|
59
|
+
"finan_exp": ["15000.00", "18000.00", "8000.00"],
|
|
60
|
+
"update_flag": ["1", "1", "1"],
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# Initialization Tests
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_companycashflow_init_basic(mock_session):
|
|
69
|
+
"""Test basic initialization with required session"""
|
|
70
|
+
cashflow = CompanyCashflow(session=mock_session)
|
|
71
|
+
assert cashflow.name == NAME
|
|
72
|
+
assert cashflow.key == KEY
|
|
73
|
+
assert cashflow.source == SOURCE
|
|
74
|
+
assert cashflow.target == TARGET
|
|
75
|
+
assert cashflow.paginate == PAGINATE
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_companycashflow_init_with_params_dict(mock_session):
|
|
79
|
+
"""Test initialization with params as dict"""
|
|
80
|
+
params = {"ts_code": "000001.SZ", "start_date": "20200101", "end_date": "20201231"}
|
|
81
|
+
cashflow = CompanyCashflow(session=mock_session, params=params)
|
|
82
|
+
assert cashflow.params.get("ts_code") == "000001.SZ"
|
|
83
|
+
assert cashflow.params.get("start_date") == "20200101"
|
|
84
|
+
assert cashflow.params.get("end_date") == "20201231"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_companycashflow_init_with_params_object(mock_session):
|
|
88
|
+
"""Test initialization with params as Params object"""
|
|
89
|
+
from xfintech.data.common.params import Params
|
|
90
|
+
|
|
91
|
+
params = Params(ts_code="000001.SZ", start_date="20200101")
|
|
92
|
+
cashflow = CompanyCashflow(session=mock_session, params=params)
|
|
93
|
+
assert cashflow.params.get("ts_code") == "000001.SZ"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_companycashflow_init_with_period_param(mock_session):
|
|
97
|
+
"""Test initialization with period parameter"""
|
|
98
|
+
params = {"ts_code": "000001.SZ", "period": "20201231"}
|
|
99
|
+
cashflow = CompanyCashflow(session=mock_session, params=params)
|
|
100
|
+
assert cashflow.params.get("period") == "20201231"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_companycashflow_init_with_cache_bool_true(mock_session):
|
|
104
|
+
"""Test initialization with cache enabled"""
|
|
105
|
+
cashflow = CompanyCashflow(session=mock_session, cache=True)
|
|
106
|
+
assert cashflow.cache is not None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_companycashflow_init_with_cache_bool_false(mock_session):
|
|
110
|
+
"""Test initialization with cache disabled"""
|
|
111
|
+
cashflow = CompanyCashflow(session=mock_session, cache=False)
|
|
112
|
+
assert cashflow.cache is None
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_companycashflow_init_with_cache_dict(mock_session):
|
|
116
|
+
"""Test initialization with cache config dict"""
|
|
117
|
+
cache_config = {"path": "/tmp/cache", "key": "test"}
|
|
118
|
+
cashflow = CompanyCashflow(session=mock_session, cache=cache_config)
|
|
119
|
+
assert cashflow.cache is not None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_companycashflow_init_default_paginate_limit(mock_session):
|
|
123
|
+
"""Test that default pagination limit is set correctly"""
|
|
124
|
+
cashflow = CompanyCashflow(session=mock_session)
|
|
125
|
+
assert cashflow.paginate.pagesize == 1000
|
|
126
|
+
assert cashflow.paginate.pagelimit == 1000
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_companycashflow_init_with_all_params(mock_session):
|
|
130
|
+
"""Test initialization with all parameters"""
|
|
131
|
+
params = {"ts_code": "000001.SZ", "start_date": "20200101", "end_date": "20201231"}
|
|
132
|
+
coolant = {"interval": 0.5}
|
|
133
|
+
retry = {"max_attempts": 3}
|
|
134
|
+
cache = True
|
|
135
|
+
|
|
136
|
+
cashflow = CompanyCashflow(session=mock_session, params=params, coolant=coolant, retry=retry, cache=cache)
|
|
137
|
+
assert cashflow.params.get("ts_code") == "000001.SZ"
|
|
138
|
+
assert cashflow.cache is not None
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_companycashflow_constants():
|
|
142
|
+
"""Test that constants are correctly defined"""
|
|
143
|
+
assert NAME == "companycashflow"
|
|
144
|
+
assert KEY == "/tushare/companycashflow"
|
|
145
|
+
assert SOURCE.name == "cashflow_vip"
|
|
146
|
+
assert TARGET.name == "companycashflow"
|
|
147
|
+
assert PAGINATE.pagesize == 1000
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
# Transform Tests
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_companycashflow_transform_basic(sample_source_data):
|
|
154
|
+
"""Test basic transformation of cash flow data"""
|
|
155
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
156
|
+
session = FakeSession(fake_conn)
|
|
157
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
158
|
+
|
|
159
|
+
result = cashflow.transform(sample_source_data)
|
|
160
|
+
|
|
161
|
+
assert len(result) == 3
|
|
162
|
+
assert "code" in result.columns
|
|
163
|
+
assert "date" in result.columns
|
|
164
|
+
assert "datecode" in result.columns
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_companycashflow_transform_code_mapping(sample_source_data):
|
|
168
|
+
"""Test that ts_code is correctly mapped to code"""
|
|
169
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
170
|
+
session = FakeSession(fake_conn)
|
|
171
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
172
|
+
|
|
173
|
+
result = cashflow.transform(sample_source_data)
|
|
174
|
+
|
|
175
|
+
assert result.iloc[0]["code"] == "000001.SZ"
|
|
176
|
+
assert result.iloc[2]["code"] == "000002.SZ"
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def test_companycashflow_transform_date_format(sample_source_data):
|
|
180
|
+
"""Test that dates are properly formatted"""
|
|
181
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
182
|
+
session = FakeSession(fake_conn)
|
|
183
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
184
|
+
|
|
185
|
+
result = cashflow.transform(sample_source_data)
|
|
186
|
+
|
|
187
|
+
assert pd.api.types.is_datetime64_any_dtype(result["date"]) is False
|
|
188
|
+
assert result.iloc[0]["date"] == "2020-03-31"
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def test_companycashflow_transform_datecode_preserved(sample_source_data):
|
|
192
|
+
"""Test that datecode is correctly created from end_date"""
|
|
193
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
194
|
+
session = FakeSession(fake_conn)
|
|
195
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
196
|
+
|
|
197
|
+
result = cashflow.transform(sample_source_data)
|
|
198
|
+
|
|
199
|
+
assert result.iloc[0]["datecode"] == "20200331"
|
|
200
|
+
assert result.iloc[1]["datecode"] == "20200930"
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def test_companycashflow_transform_numeric_conversions(sample_source_data):
|
|
204
|
+
"""Test that numeric fields are properly converted"""
|
|
205
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
206
|
+
session = FakeSession(fake_conn)
|
|
207
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
208
|
+
|
|
209
|
+
result = cashflow.transform(sample_source_data)
|
|
210
|
+
|
|
211
|
+
assert result.iloc[0]["net_profit"] == 100000.50
|
|
212
|
+
assert result.iloc[0]["n_cashflow_act"] == 150000.30
|
|
213
|
+
assert pd.api.types.is_numeric_dtype(result["net_profit"])
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def test_companycashflow_transform_string_fields(sample_source_data):
|
|
217
|
+
"""Test that string fields are properly converted"""
|
|
218
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
219
|
+
session = FakeSession(fake_conn)
|
|
220
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
221
|
+
|
|
222
|
+
result = cashflow.transform(sample_source_data)
|
|
223
|
+
|
|
224
|
+
assert result.iloc[0]["comp_type"] == "2"
|
|
225
|
+
assert result.iloc[0]["report_type"] == "1"
|
|
226
|
+
assert result.iloc[0]["update_flag"] == "1"
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def test_companycashflow_transform_empty_dataframe():
|
|
230
|
+
"""Test transformation with empty dataframe"""
|
|
231
|
+
fake_conn = FakeConnection(frame=pd.DataFrame())
|
|
232
|
+
session = FakeSession(fake_conn)
|
|
233
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
234
|
+
|
|
235
|
+
result = cashflow.transform(pd.DataFrame())
|
|
236
|
+
|
|
237
|
+
assert isinstance(result, pd.DataFrame)
|
|
238
|
+
assert result.empty
|
|
239
|
+
assert len(result.columns) == len(TARGET.list_column_names())
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def test_companycashflow_transform_none_input():
|
|
243
|
+
"""Test transformation with None input"""
|
|
244
|
+
fake_conn = FakeConnection(frame=pd.DataFrame())
|
|
245
|
+
session = FakeSession(fake_conn)
|
|
246
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
247
|
+
|
|
248
|
+
result = cashflow.transform(None)
|
|
249
|
+
|
|
250
|
+
assert isinstance(result, pd.DataFrame)
|
|
251
|
+
assert result.empty
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def test_companycashflow_transform_handles_invalid_dates():
|
|
255
|
+
"""Test that invalid dates are handled gracefully"""
|
|
256
|
+
data = pd.DataFrame(
|
|
257
|
+
{
|
|
258
|
+
"ts_code": ["000001.SZ"],
|
|
259
|
+
"ann_date": ["invalid"],
|
|
260
|
+
"f_ann_date": ["20200430"],
|
|
261
|
+
"end_date": ["20200331"],
|
|
262
|
+
"comp_type": ["1"],
|
|
263
|
+
"report_type": ["1"],
|
|
264
|
+
"end_type": ["Q1"],
|
|
265
|
+
"update_flag": ["1"],
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
fake_conn = FakeConnection(frame=data)
|
|
270
|
+
session = FakeSession(fake_conn)
|
|
271
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
272
|
+
|
|
273
|
+
result = cashflow.transform(data)
|
|
274
|
+
|
|
275
|
+
assert len(result) == 1
|
|
276
|
+
assert pd.isna(result.iloc[0]["ann_date"])
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def test_companycashflow_transform_removes_duplicates(sample_source_data):
|
|
280
|
+
"""Test that duplicate rows are removed"""
|
|
281
|
+
# Create data with duplicates
|
|
282
|
+
data = pd.concat([sample_source_data, sample_source_data.iloc[[0]]], ignore_index=True)
|
|
283
|
+
|
|
284
|
+
fake_conn = FakeConnection(frame=data)
|
|
285
|
+
session = FakeSession(fake_conn)
|
|
286
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
287
|
+
|
|
288
|
+
result = cashflow.transform(data)
|
|
289
|
+
|
|
290
|
+
# Should have 3 unique rows, not 4
|
|
291
|
+
assert len(result) == 3
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def test_companycashflow_transform_sorts_by_code_and_date(sample_source_data):
|
|
295
|
+
"""Test that output is sorted by code and date"""
|
|
296
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
297
|
+
session = FakeSession(fake_conn)
|
|
298
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
299
|
+
|
|
300
|
+
result = cashflow.transform(sample_source_data)
|
|
301
|
+
|
|
302
|
+
# Check first row is 000001.SZ, 2020-03-31
|
|
303
|
+
assert result.iloc[0]["code"] == "000001.SZ"
|
|
304
|
+
assert result.iloc[0]["date"] == "2020-03-31"
|
|
305
|
+
# Check last row is 000002.SZ
|
|
306
|
+
assert result.iloc[2]["code"] == "000002.SZ"
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def test_companycashflow_transform_resets_index():
|
|
310
|
+
"""Test that index is reset after transformation"""
|
|
311
|
+
data = pd.DataFrame(
|
|
312
|
+
{
|
|
313
|
+
"ts_code": ["000001.SZ", "000002.SZ"],
|
|
314
|
+
"ann_date": ["20200430", "20200430"],
|
|
315
|
+
"f_ann_date": ["20200430", "20200430"],
|
|
316
|
+
"end_date": ["20200331", "20200331"],
|
|
317
|
+
"comp_type": ["1", "1"],
|
|
318
|
+
"report_type": ["1", "1"],
|
|
319
|
+
"end_type": ["Q1", "Q1"],
|
|
320
|
+
"update_flag": ["1", "1"],
|
|
321
|
+
},
|
|
322
|
+
index=[5, 10],
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
fake_conn = FakeConnection(frame=data)
|
|
326
|
+
session = FakeSession(fake_conn)
|
|
327
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
328
|
+
|
|
329
|
+
result = cashflow.transform(data)
|
|
330
|
+
|
|
331
|
+
assert result.index.tolist() == [0, 1]
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def test_companycashflow_transform_only_target_columns(sample_source_data):
|
|
335
|
+
"""Test that only target columns are in output"""
|
|
336
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
337
|
+
session = FakeSession(fake_conn)
|
|
338
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
339
|
+
|
|
340
|
+
result = cashflow.transform(sample_source_data)
|
|
341
|
+
|
|
342
|
+
expected_cols = set(TARGET.list_column_names())
|
|
343
|
+
actual_cols = set(result.columns)
|
|
344
|
+
|
|
345
|
+
assert actual_cols == expected_cols
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
# Run Method Tests
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def test_companycashflow_run_with_cache_hit(sample_source_data):
|
|
352
|
+
"""Test that run() returns cached data when available"""
|
|
353
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
354
|
+
session = FakeSession(fake_conn)
|
|
355
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"}, cache=True)
|
|
356
|
+
|
|
357
|
+
# First run should fetch and cache
|
|
358
|
+
result1 = cashflow.run()
|
|
359
|
+
|
|
360
|
+
# Second run should return cached data
|
|
361
|
+
result2 = cashflow.run()
|
|
362
|
+
|
|
363
|
+
pd.testing.assert_frame_equal(result1, result2)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def test_companycashflow_run_basic_date_range(sample_source_data):
|
|
367
|
+
"""Test run() with date range parameters"""
|
|
368
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
369
|
+
session = FakeSession(fake_conn)
|
|
370
|
+
cashflow = CompanyCashflow(
|
|
371
|
+
session=session,
|
|
372
|
+
params={"ts_code": "000001.SZ", "start_date": "20200101", "end_date": "20201231"},
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
result = cashflow.run()
|
|
376
|
+
|
|
377
|
+
assert isinstance(result, pd.DataFrame)
|
|
378
|
+
assert len(result) > 0
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def test_companycashflow_run_with_datetime_params(sample_source_data):
|
|
382
|
+
"""Test run() with datetime objects as parameters"""
|
|
383
|
+
from datetime import datetime
|
|
384
|
+
|
|
385
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
386
|
+
session = FakeSession(fake_conn)
|
|
387
|
+
cashflow = CompanyCashflow(
|
|
388
|
+
session=session,
|
|
389
|
+
params={
|
|
390
|
+
"ts_code": "000001.SZ",
|
|
391
|
+
"start_date": datetime(2020, 1, 1),
|
|
392
|
+
"end_date": datetime(2020, 12, 31),
|
|
393
|
+
},
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
result = cashflow.run()
|
|
397
|
+
|
|
398
|
+
assert isinstance(result, pd.DataFrame)
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def test_companycashflow_run_sets_cache(sample_source_data):
|
|
402
|
+
"""Test that run() saves result to cache"""
|
|
403
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
404
|
+
session = FakeSession(fake_conn)
|
|
405
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"}, cache=True)
|
|
406
|
+
|
|
407
|
+
result = cashflow.run()
|
|
408
|
+
|
|
409
|
+
# Cache should be set after run
|
|
410
|
+
cached = cashflow._load_cache()
|
|
411
|
+
assert cached is not None
|
|
412
|
+
pd.testing.assert_frame_equal(result, cached)
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def test_companycashflow_run_calls_transform(sample_source_data):
|
|
416
|
+
"""Test that run() calls transform method"""
|
|
417
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
418
|
+
session = FakeSession(fake_conn)
|
|
419
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
420
|
+
|
|
421
|
+
# Monkey patch transform to track if it was called
|
|
422
|
+
original_transform = cashflow.transform
|
|
423
|
+
transform_called = {"called": False}
|
|
424
|
+
|
|
425
|
+
def mock_transform(data):
|
|
426
|
+
transform_called["called"] = True
|
|
427
|
+
return original_transform(data)
|
|
428
|
+
|
|
429
|
+
cashflow.transform = mock_transform
|
|
430
|
+
cashflow.run()
|
|
431
|
+
|
|
432
|
+
assert transform_called["called"] is True
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def test_companycashflow_run_uses_cashflow_vip_api(sample_source_data):
|
|
436
|
+
"""Test that run() uses cashflow_vip API"""
|
|
437
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
438
|
+
session = FakeSession(fake_conn)
|
|
439
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
440
|
+
|
|
441
|
+
# Monkey patch _fetchall to capture API
|
|
442
|
+
captured_api = {"api": None}
|
|
443
|
+
|
|
444
|
+
def mock_fetchall(api, **kwargs):
|
|
445
|
+
captured_api["api"] = api
|
|
446
|
+
return sample_source_data
|
|
447
|
+
|
|
448
|
+
cashflow._fetchall = mock_fetchall
|
|
449
|
+
cashflow.run()
|
|
450
|
+
|
|
451
|
+
assert captured_api["api"] == session.connection.cashflow_vip
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
# Integration Tests
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def test_companycashflow_full_workflow(sample_source_data):
|
|
458
|
+
"""Test complete workflow from initialization to output"""
|
|
459
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
460
|
+
session = FakeSession(fake_conn)
|
|
461
|
+
|
|
462
|
+
cashflow = CompanyCashflow(
|
|
463
|
+
session=session,
|
|
464
|
+
params={"ts_code": "000001.SZ", "start_date": "20200101", "end_date": "20201231"},
|
|
465
|
+
cache=True,
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
result = cashflow.run()
|
|
469
|
+
|
|
470
|
+
# Verify output structure
|
|
471
|
+
assert isinstance(result, pd.DataFrame)
|
|
472
|
+
assert len(result) == 3
|
|
473
|
+
assert "code" in result.columns
|
|
474
|
+
assert "date" in result.columns
|
|
475
|
+
assert "net_profit" in result.columns
|
|
476
|
+
assert "n_cashflow_act" in result.columns
|
|
477
|
+
|
|
478
|
+
# Verify data types
|
|
479
|
+
assert pd.api.types.is_numeric_dtype(result["net_profit"])
|
|
480
|
+
assert result.iloc[0]["code"] == "000001.SZ"
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def test_companycashflow_cache_persistence(sample_source_data):
|
|
484
|
+
"""Test that cache persists across multiple runs"""
|
|
485
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
486
|
+
session = FakeSession(fake_conn)
|
|
487
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"}, cache=True)
|
|
488
|
+
|
|
489
|
+
# Run once to populate cache
|
|
490
|
+
result1 = cashflow.run()
|
|
491
|
+
|
|
492
|
+
# Clear in-memory data to simulate fresh load
|
|
493
|
+
cashflow2 = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"}, cache=True)
|
|
494
|
+
result2 = cashflow2.run()
|
|
495
|
+
|
|
496
|
+
pd.testing.assert_frame_equal(result1, result2)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def test_companycashflow_params_uniqueness(mock_session):
|
|
500
|
+
"""Test that different params produce different cache keys"""
|
|
501
|
+
cashflow1 = CompanyCashflow(
|
|
502
|
+
session=mock_session,
|
|
503
|
+
params={"ts_code": "000001.SZ", "start_date": "20200101"},
|
|
504
|
+
cache=True,
|
|
505
|
+
)
|
|
506
|
+
cashflow2 = CompanyCashflow(
|
|
507
|
+
session=mock_session,
|
|
508
|
+
params={"ts_code": "000001.SZ", "start_date": "20210101"},
|
|
509
|
+
cache=True,
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
# Test that different params are properly stored
|
|
513
|
+
assert cashflow1.params.get("start_date") == "20200101"
|
|
514
|
+
assert cashflow2.params.get("start_date") == "20210101"
|
|
515
|
+
assert cashflow1.params.get("start_date") != cashflow2.params.get("start_date")
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def test_companycashflow_different_stocks(sample_source_data):
|
|
519
|
+
"""Test that different stock codes are handled correctly"""
|
|
520
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
521
|
+
session = FakeSession(fake_conn)
|
|
522
|
+
|
|
523
|
+
cashflow1 = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
524
|
+
result1 = cashflow1.run()
|
|
525
|
+
|
|
526
|
+
cashflow2 = CompanyCashflow(session=session, params={"ts_code": "000002.SZ"})
|
|
527
|
+
result2 = cashflow2.run()
|
|
528
|
+
|
|
529
|
+
# Both should have data for their respective stocks
|
|
530
|
+
assert "000001.SZ" in result1["code"].values
|
|
531
|
+
assert "000002.SZ" in result2["code"].values
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def test_companycashflow_empty_result_handling():
|
|
535
|
+
"""Test handling of empty API results"""
|
|
536
|
+
empty_data = pd.DataFrame()
|
|
537
|
+
fake_conn = FakeConnection(frame=empty_data)
|
|
538
|
+
session = FakeSession(fake_conn)
|
|
539
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
540
|
+
|
|
541
|
+
result = cashflow.run()
|
|
542
|
+
|
|
543
|
+
assert isinstance(result, pd.DataFrame)
|
|
544
|
+
assert result.empty
|
|
545
|
+
assert len(result.columns) > 0
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
def test_companycashflow_large_dataset_handling():
|
|
549
|
+
"""Test handling of large datasets"""
|
|
550
|
+
# Create large dataset
|
|
551
|
+
large_data = pd.DataFrame(
|
|
552
|
+
{
|
|
553
|
+
"ts_code": ["000001.SZ"] * 1000,
|
|
554
|
+
"ann_date": ["20200430"] * 1000,
|
|
555
|
+
"f_ann_date": ["20200430"] * 1000,
|
|
556
|
+
"end_date": ["20200331"] * 1000,
|
|
557
|
+
"comp_type": ["1"] * 1000,
|
|
558
|
+
"report_type": ["1"] * 1000,
|
|
559
|
+
"end_type": ["Q1"] * 1000,
|
|
560
|
+
"net_profit": ["100000.00"] * 1000,
|
|
561
|
+
"update_flag": ["1"] * 1000,
|
|
562
|
+
}
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
fake_conn = FakeConnection(frame=large_data)
|
|
566
|
+
session = FakeSession(fake_conn)
|
|
567
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
568
|
+
|
|
569
|
+
result = cashflow.run()
|
|
570
|
+
|
|
571
|
+
# Should deduplicate to 1 row
|
|
572
|
+
assert len(result) == 1
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
def test_companycashflow_without_cache(sample_source_data):
|
|
576
|
+
"""Test that class works correctly without caching"""
|
|
577
|
+
fake_conn = FakeConnection(frame=sample_source_data)
|
|
578
|
+
session = FakeSession(fake_conn)
|
|
579
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"}, cache=False)
|
|
580
|
+
|
|
581
|
+
result = cashflow.run()
|
|
582
|
+
|
|
583
|
+
assert isinstance(result, pd.DataFrame)
|
|
584
|
+
assert len(result) > 0
|
|
585
|
+
assert cashflow.cache is None
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
def test_companycashflow_handles_missing_numeric_fields():
|
|
589
|
+
"""Test that missing numeric fields don't break transformation"""
|
|
590
|
+
# Data with only subset of fields
|
|
591
|
+
minimal_data = pd.DataFrame(
|
|
592
|
+
{
|
|
593
|
+
"ts_code": ["000001.SZ"],
|
|
594
|
+
"ann_date": ["20200430"],
|
|
595
|
+
"f_ann_date": ["20200430"],
|
|
596
|
+
"end_date": ["20200331"],
|
|
597
|
+
"comp_type": ["1"],
|
|
598
|
+
"report_type": ["1"],
|
|
599
|
+
"end_type": ["Q1"],
|
|
600
|
+
"net_profit": ["100000.00"],
|
|
601
|
+
"update_flag": ["1"],
|
|
602
|
+
}
|
|
603
|
+
)
|
|
604
|
+
|
|
605
|
+
fake_conn = FakeConnection(frame=minimal_data)
|
|
606
|
+
session = FakeSession(fake_conn)
|
|
607
|
+
cashflow = CompanyCashflow(session=session, params={"ts_code": "000001.SZ"})
|
|
608
|
+
|
|
609
|
+
result = cashflow.run()
|
|
610
|
+
|
|
611
|
+
# Should complete without error
|
|
612
|
+
assert len(result) == 1
|
|
613
|
+
# Missing fields should be NaN
|
|
614
|
+
assert pd.isna(result.iloc[0]["n_cashflow_act"])
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
def test_companycashflow_api_doc_reference():
|
|
618
|
+
"""Test that class correctly references API documentation"""
|
|
619
|
+
assert "doc_id=44" in CompanyCashflow.__doc__
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from xfintech.data.source.tushare.stock.companydebt.companydebt import CompanyDebt
|
|
4
|
+
from xfintech.data.source.tushare.stock.companydebt.constant import (
|
|
5
|
+
KEY,
|
|
6
|
+
NAME,
|
|
7
|
+
PAGINATE,
|
|
8
|
+
SOURCE,
|
|
9
|
+
TARGET,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"CompanyDebt",
|
|
14
|
+
"KEY",
|
|
15
|
+
"NAME",
|
|
16
|
+
"PAGINATE",
|
|
17
|
+
"SOURCE",
|
|
18
|
+
"TARGET",
|
|
19
|
+
]
|