This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move one unit test from the standard series of unit test
- Loading branch information
Showing
3 changed files
with
94 additions
and
47 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
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,93 @@ | ||
""" | ||
@brief test log(time=3s) | ||
""" | ||
|
||
|
||
import sys | ||
import os | ||
import unittest | ||
import datetime | ||
import warnings | ||
|
||
|
||
try: | ||
import src | ||
import pyquickhelper as skip_ | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
".."))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
"..", | ||
"..", | ||
"pyquickhelper", | ||
"src"))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
import src | ||
import pyquickhelper as skip_ | ||
|
||
from pyquickhelper.loghelper import fLOG | ||
from pyquickhelper.pycode import is_travis_or_appveyor | ||
from src.pyensae.finance.astock import StockPrices | ||
|
||
|
||
class TestLONGStockFile (unittest.TestCase): | ||
|
||
def test_save_stock_google(self): | ||
fLOG( | ||
__file__, | ||
self._testMethodName, | ||
OutputPrint=__name__ == "__main__") | ||
cache = os.path.abspath(os.path.split(__file__)[0]) | ||
cache = os.path.join(cache, "temp_cache_file_google") | ||
name = os.path.join(cache, "NASDAQ_GOOG.2000-01-03.2014-01-15.txt") | ||
if os.path.exists(name): | ||
os.remove(name) | ||
|
||
try: | ||
stock = StockPrices( | ||
"NASDAQ:GOOG", | ||
url="google", | ||
folder=cache, | ||
end=datetime.datetime( | ||
2014, | ||
1, | ||
15)) | ||
except ImportError as e: | ||
# There is an issue with pandas_datareader on travis. | ||
# Not up to date with the latest pandas. | ||
if is_travis_or_appveyor(): | ||
warnings.warn( | ||
"Probably an issue with pandas_datareader.\n" + str(e)) | ||
return | ||
else: | ||
raise e | ||
|
||
file = os.path.join(cache, "save.txt") | ||
if os.path.exists(file): | ||
os.remove(file) | ||
stock.to_csv(file) | ||
assert os.path.exists(file) | ||
|
||
stock2 = StockPrices(file, sep="\t") | ||
assert stock.dataframe.shape == stock2.dataframe.shape | ||
df = stock2.dataframe | ||
file = os.path.join(cache, "out_excel.xlsx") | ||
if os.path.exists(file): | ||
os.remove(file) | ||
df.to_excel(file) | ||
assert os.path.exists(file) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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