Skip to content

Commit

Permalink
Use black to format
Browse files Browse the repository at this point in the history
  • Loading branch information
mlouielu committed May 15, 2024
1 parent fae4b1e commit 3324a6d
Show file tree
Hide file tree
Showing 21 changed files with 586 additions and 389 deletions.
56 changes: 27 additions & 29 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,48 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.coverage']
extensions = ["sphinx.ext.coverage"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'twstock'
copyright = '2017, Louie Lu'
author = 'Louie Lu'
project = "twstock"
copyright = "2017, Louie Lu"
author = "Louie Lu"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.0'
version = "1.0"
# The full version, including alpha/beta/rc tags.
release = '1.0.1'
release = "1.0.1"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'zh_TW'
language = "zh_TW"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -83,7 +83,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -94,13 +94,13 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'twstockdoc'
htmlhelp_basename = "twstockdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -109,15 +109,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -127,19 +124,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'twstock.tex', 'twstock Documentation',
'Louie Lu', 'manual'),
(master_doc, "twstock.tex", "twstock Documentation", "Louie Lu", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'twstock', 'twstock Documentation',
[author], 1)
]
man_pages = [(master_doc, "twstock", "twstock Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -148,13 +141,18 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'twstock', 'twstock Documentation',
author, 'twstock', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"twstock",
"twstock Documentation",
author,
"twstock",
"One line description of project.",
"Miscellaneous",
),
]



html_sidebars = {
'**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']
"**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"]
}
24 changes: 12 additions & 12 deletions docs/serve.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#!/usr/bin/env python3
'''
"""
Small wsgiref based web server. Takes a path to serve from and an
optional port number (defaults to 8000), then tries to serve files.
Mime types are guessed from the file names, 404 errors are raised
if the file is not found. Used for the make serve target in Doc.
'''
"""
import sys
import os
import mimetypes
from wsgiref import simple_server, util

def app(environ, respond):

fn = os.path.join(path, environ['PATH_INFO'][1:])
if '.' not in fn.split(os.path.sep)[-1]:
fn = os.path.join(fn, 'index.html')
def app(environ, respond):
fn = os.path.join(path, environ["PATH_INFO"][1:])
if "." not in fn.split(os.path.sep)[-1]:
fn = os.path.join(fn, "index.html")
type = mimetypes.guess_type(fn)[0]

if os.path.exists(fn):
respond('200 OK', [('Content-Type', type)])
respond("200 OK", [("Content-Type", type)])
return util.FileWrapper(open(fn, "rb"))
else:
respond('404 Not Found', [('Content-Type', 'text/plain')])
return [b'not found']
respond("404 Not Found", [("Content-Type", "text/plain")])
return [b"not found"]

if __name__ == '__main__':

if __name__ == "__main__":
path = sys.argv[1]
port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000
httpd = simple_server.make_server('', port, app)
httpd = simple_server.make_server("", port, app)
print("Serving {} on port {}, control-C to stop".format(path, port))
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\b\bShutting down.")

25 changes: 11 additions & 14 deletions test/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_ma_bias_ratio_pivot(self):
class BestFourPointTest(unittest.TestCase):
@classmethod
def setUpClass(self):
self.stock = stock.Stock('2330')
self.stock = stock.Stock("2330")
self.stock.fetch(2015, 5)
self.legacy = legacy.LegacyBestFourPoint(self.stock)
self.ng = analytics.BestFourPoint(self.stock)
Expand Down Expand Up @@ -119,27 +119,24 @@ def test_best_sell_4(self):
self.assertEqual(self.ng.best_sell_4(), self.legacy.best_sell_4())

def test_best_four_point_to_buy(self):
self.assertEqual(self.ng.best_four_point_to_buy(),
self.legacy.best_four_point_to_buy())
self.assertEqual(
self.ng.best_four_point_to_buy(), self.legacy.best_four_point_to_buy()
)

def test_best_four_point_to_sell(self):
self.assertEqual(self.ng.best_four_point_to_sell(),
self.legacy.best_four_point_to_sell())
self.assertEqual(
self.ng.best_four_point_to_sell(), self.legacy.best_four_point_to_sell()
)

def test_best_four_point(self):
self.stock.fetch(2014, 5)
self.assertEqual(self.ng.best_four_point(),
self.legacy.best_four_point())
self.assertEqual(self.ng.best_four_point(), self.legacy.best_four_point())

self.stock.fetch(2015, 5)
self.assertEqual(self.ng.best_four_point(),
self.legacy.best_four_point())
self.assertEqual(self.ng.best_four_point(), self.legacy.best_four_point())

self.stock.fetch(2016, 5)
self.assertEqual(self.ng.best_four_point(),
self.legacy.best_four_point())
self.assertEqual(self.ng.best_four_point(), self.legacy.best_four_point())

self.stock.fetch(2017, 5)
self.assertEqual(self.ng.best_four_point(),
self.legacy.best_four_point())

self.assertEqual(self.ng.best_four_point(), self.legacy.best_four_point())
2 changes: 1 addition & 1 deletion test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CLIFunctionTest(unittest.TestCase):
def setUp(self):
self.stocks = ['2330', '6223']
self.stocks = ["2330", "6223"]

def test_best_four_point(self):
cli.best_four_point.run(self.stocks)
Expand Down
18 changes: 11 additions & 7 deletions test/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@

class MockTest(unittest.TestCase):
def test_mock_get_stock_info_will_work(self):
self.assertIn('msgArray', mock.get_stock_info('2330'))
self.assertIn("msgArray", mock.get_stock_info("2330"))

def test_mock_get_stock_info_raw_data(self):
self.assertCountEqual(
mock.get_stock_info('2330').keys(),
['msgArray', 'userDelay', 'rtmessage', 'referer', 'queryTime', 'rtcode'])
mock.get_stock_info("2330").keys(),
["msgArray", "userDelay", "rtmessage", "referer", "queryTime", "rtcode"],
)

def test_mock_get_stock_info_msgarray(self):
self.assertEqual(mock.get_stock_info('2330')['msgArray'][0]['c'], '2330')
self.assertEqual(mock.get_stock_info("2330")["msgArray"][0]["c"], "2330")

def test_mock_get_stock_info_will_change_in_different_index(self):
self.assertNotEqual(
mock.get_stock_info('2330', 0), mock.get_stock_info('2330', 1))
mock.get_stock_info("2330", 0), mock.get_stock_info("2330", 1)
)
self.assertNotEqual(
mock.get_stock_info('2330', 1), mock.get_stock_info('2330', 2))
mock.get_stock_info("2330", 1), mock.get_stock_info("2330", 2)
)
self.assertNotEqual(
mock.get_stock_info('2330', 0), mock.get_stock_info('2330', 2))
mock.get_stock_info("2330", 0), mock.get_stock_info("2330", 2)
)
14 changes: 7 additions & 7 deletions test/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class ProxyProviderTest(unittest.TestCase):

def setUp(self):
reset_proxy_provider()

Expand All @@ -18,24 +17,25 @@ def test_configure(self):
self.assertDictEqual({}, get_proxies())

# configure fake proxy
configure_proxy_provider(SingleProxyProvider(dict(http="http-proxy", https="https-proxy")))
self.assertEqual("http-proxy", get_proxies()['http'])
self.assertEqual("https-proxy", get_proxies()['https'])
configure_proxy_provider(
SingleProxyProvider(dict(http="http-proxy", https="https-proxy"))
)
self.assertEqual("http-proxy", get_proxies()["http"])
self.assertEqual("https-proxy", get_proxies()["https"])

# reset proxy
reset_proxy_provider()
self.assertDictEqual({}, get_proxies())


def test_rr_proxies_provider(self):
proxies = ['a', 'b', 'c']
proxies = ["a", "b", "c"]
rr_provider = RoundRobinProxiesProvider(proxies)

for _ in range(3):
for p in proxies:
self.assertEqual(rr_provider.get_proxy(), p)

proxies = ['d', 'e', 'f']
proxies = ["d", "e", "f"]
rr_provider.proxies = proxies
for _ in range(3):
for p in proxies:
Expand Down
Loading

0 comments on commit 3324a6d

Please sign in to comment.