From 8b246687ad6322a415fc5e04ac5ff76e4fa94081 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 12:44:00 -0400 Subject: [PATCH 01/19] test on windows/osx --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dfc5498e..091b906e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,11 +10,12 @@ permissions: contents: read jobs: test: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ['3.8', '3.9', '3.10'] + runs-on: ${{ matrix.os }} name: Unit test ${{ matrix.python-version }} steps: - uses: actions/checkout@v3 From 4a849a91a6799e29c6066ea529a3f144b98e7a12 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 14:16:54 -0400 Subject: [PATCH 02/19] fix test paths for osx and windows --- .github/workflows/test.yml | 2 +- polygon/rest/base.py | 6 ++++-- polygon/rest/models/tickers.py | 2 +- polygon/rest/snapshot.py | 6 +++--- test_rest/base.py | 9 ++++++++- ...&precision=2.json => USD&amount=100&precision=2.json} | 0 ...?adjusted=True.json => 2005-04-01&adjusted=True.json} | 0 ...?adjusted=True.json => 2005-04-04&adjusted=True.json} | 0 .../{news?ticker=NFLX.json => news&ticker=NFLX.json} | 0 .../{gainers?market.type=stocks.json => gainers.json} | 0 .../tickers/{AAPL?market.type=stocks.json => AAPL.json} | 0 .../index.json} | 0 ...T0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json} | 0 ...ss=stocks.json => conditions&asset_class=stocks.json} | 0 ...1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json} | 0 .../v3/trades/{AAPL?limit=2.json => AAPL&limit=2.json} | 0 test_rest/test_snapshots.py | 6 +++--- test_rest/test_tickers.py | 5 ++--- 18 files changed, 22 insertions(+), 14 deletions(-) rename test_rest/mocks/v1/conversion/AUD/{USD?amount=100&precision=2.json => USD&amount=100&precision=2.json} (100%) rename test_rest/mocks/v1/open-close/AAPL/{2005-04-01?adjusted=True.json => 2005-04-01&adjusted=True.json} (100%) rename test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/{2005-04-04?adjusted=True.json => 2005-04-04&adjusted=True.json} (100%) rename test_rest/mocks/v2/reference/{news?ticker=NFLX.json => news&ticker=NFLX.json} (100%) rename test_rest/mocks/v2/snapshot/locale/us/markets/stocks/{gainers?market.type=stocks.json => gainers.json} (100%) rename test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/{AAPL?market.type=stocks.json => AAPL.json} (100%) rename test_rest/mocks/v2/snapshot/locale/us/markets/stocks/{tickers?market.type=stocks.json => tickers/index.json} (100%) rename test_rest/mocks/v3/quotes/{AAPL?cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json => AAPL&cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json} (100%) rename test_rest/mocks/v3/reference/{conditions?asset.class=stocks.json => conditions&asset_class=stocks.json} (100%) rename test_rest/mocks/v3/reference/{tickers?cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json => tickers&cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json} (100%) rename test_rest/mocks/v3/trades/{AAPL?limit=2.json => AAPL&limit=2.json} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 091b906e..52f2471a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ['3.8', '3.9', '3.10'] runs-on: ${{ matrix.os }} - name: Unit test ${{ matrix.python-version }} + name: ${{ matrix.os }} Unit test ${{ matrix.python-version }} steps: - uses: actions/checkout@v3 - name: Setup Python diff --git a/polygon/rest/base.py b/polygon/rest/base.py index 43afa2e1..0dbb7519 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -101,7 +101,7 @@ def time_mult(timestamp_res: str) -> int: return 1 def _get_params( - self, fn, caller_locals: Dict[str, Any], datetime_res: str = "nanos" + self, fn, caller_locals: Dict[str, Any], datetime_res: str = "nanos" ): params = caller_locals["params"] if params is None: @@ -119,7 +119,9 @@ def _get_params( elif isinstance(val, datetime): val = int(val.timestamp() * self.time_mult(datetime_res)) if val is not None: - params[argname.replace("_", ".")] = val + if argname.endswith('_lt') or argname.endswith('_lte') or argname.endswith('_gt') or argname.endswith('_gte'): + argname = argname.replace('_', '.') + params[argname] = val return params diff --git a/polygon/rest/models/tickers.py b/polygon/rest/models/tickers.py index ee4712b1..35b1102b 100644 --- a/polygon/rest/models/tickers.py +++ b/polygon/rest/models/tickers.py @@ -159,7 +159,7 @@ def from_dict(d): published_utc=d.get("published_utc", None), publisher=None if "publisher" not in d - else [Publisher.from_dict(d["publisher"])], + else Publisher.from_dict(d["publisher"]), tickers=d.get("tickers", None), title=d.get("title", None), ) diff --git a/polygon/rest/snapshot.py b/polygon/rest/snapshot.py index 2aa5eefa..83208058 100644 --- a/polygon/rest/snapshot.py +++ b/polygon/rest/snapshot.py @@ -13,7 +13,7 @@ class SnapshotClient(BaseClient): def get_snapshot_all( self, - market_type: Optional[Union[str, SnapshotMarketType]] = "stocks", + market_type: Optional[Union[str, SnapshotMarketType]], tickers: Optional[Union[str, List[str]]] = None, params: Optional[Dict[str, Any]] = None, raw: bool = False, @@ -40,8 +40,8 @@ def get_snapshot_all( def get_snapshot_direction( self, + market_type: Optional[Union[str, SnapshotMarketType]], direction: Union[str, Direction], - market_type: Optional[Union[str, SnapshotMarketType]] = "stocks", params: Optional[Dict[str, Any]] = None, raw: bool = False, ) -> Union[List[Snapshot], HTTPResponse]: @@ -67,8 +67,8 @@ def get_snapshot_direction( def get_snapshot_ticker( self, + market_type: Optional[Union[str, SnapshotMarketType]], ticker: str, - market_type: Optional[Union[str, SnapshotMarketType]] = "stocks", params: Optional[Dict[str, Any]] = None, raw: bool = False, ) -> Union[Snapshot, HTTPResponse]: diff --git a/test_rest/base.py b/test_rest/base.py index 69e94acb..ff1576a7 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -1,6 +1,7 @@ from polygon import RESTClient import os +import re import unittest import httpretty # type: ignore @@ -13,7 +14,13 @@ if fname.endswith(".json"): abspath = os.path.join(dname, fname) with open(abspath, "r") as f: - urllpath = abspath.replace(mockdir, "").replace(".json", "") + urllpath = abspath.replace(mockdir, "") + urllpath = re.sub(".json$", "", urllpath) + urllpath = re.sub("/index$", "", urllpath) + if '?' in urllpath: + # Windows will be sad. We support dev on Windows. + raise Exception(f"use & instead of ? in path ${urllpath}") + urllpath = urllpath.replace('&', '?', 1) mocks.append((urllpath, f.read())) unittest.util._MAX_LENGTH = 30000 # type: ignore diff --git a/test_rest/mocks/v1/conversion/AUD/USD?amount=100&precision=2.json b/test_rest/mocks/v1/conversion/AUD/USD&amount=100&precision=2.json similarity index 100% rename from test_rest/mocks/v1/conversion/AUD/USD?amount=100&precision=2.json rename to test_rest/mocks/v1/conversion/AUD/USD&amount=100&precision=2.json diff --git a/test_rest/mocks/v1/open-close/AAPL/2005-04-01?adjusted=True.json b/test_rest/mocks/v1/open-close/AAPL/2005-04-01&adjusted=True.json similarity index 100% rename from test_rest/mocks/v1/open-close/AAPL/2005-04-01?adjusted=True.json rename to test_rest/mocks/v1/open-close/AAPL/2005-04-01&adjusted=True.json diff --git a/test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/2005-04-04?adjusted=True.json b/test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/2005-04-04&adjusted=True.json similarity index 100% rename from test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/2005-04-04?adjusted=True.json rename to test_rest/mocks/v2/aggs/grouped/locale/us/market/stocks/2005-04-04&adjusted=True.json diff --git a/test_rest/mocks/v2/reference/news?ticker=NFLX.json b/test_rest/mocks/v2/reference/news&ticker=NFLX.json similarity index 100% rename from test_rest/mocks/v2/reference/news?ticker=NFLX.json rename to test_rest/mocks/v2/reference/news&ticker=NFLX.json diff --git a/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/gainers?market.type=stocks.json b/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/gainers.json similarity index 100% rename from test_rest/mocks/v2/snapshot/locale/us/markets/stocks/gainers?market.type=stocks.json rename to test_rest/mocks/v2/snapshot/locale/us/markets/stocks/gainers.json diff --git a/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/AAPL?market.type=stocks.json b/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/AAPL.json similarity index 100% rename from test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/AAPL?market.type=stocks.json rename to test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/AAPL.json diff --git a/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers?market.type=stocks.json b/test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/index.json similarity index 100% rename from test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers?market.type=stocks.json rename to test_rest/mocks/v2/snapshot/locale/us/markets/stocks/tickers/index.json diff --git a/test_rest/mocks/v3/quotes/AAPL?cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json b/test_rest/mocks/v3/quotes/AAPL&cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json similarity index 100% rename from test_rest/mocks/v3/quotes/AAPL?cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json rename to test_rest/mocks/v3/quotes/AAPL&cursor=YXA9MTkyODgxNjYmYXM9JmxpbWl0PTEwJm9yZGVyPWRlc2Mmc29ydD10aW1lc3RhbXAmdGltZXN0YW1wLmx0ZT0yMDIyLTA1LTEwVDE0JTNBMTElM0ExMi42OTA2NjExODla.json diff --git a/test_rest/mocks/v3/reference/conditions?asset.class=stocks.json b/test_rest/mocks/v3/reference/conditions&asset_class=stocks.json similarity index 100% rename from test_rest/mocks/v3/reference/conditions?asset.class=stocks.json rename to test_rest/mocks/v3/reference/conditions&asset_class=stocks.json diff --git a/test_rest/mocks/v3/reference/tickers?cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json b/test_rest/mocks/v3/reference/tickers&cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json similarity index 100% rename from test_rest/mocks/v3/reference/tickers?cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json rename to test_rest/mocks/v3/reference/tickers&cursor=YWN0aXZlPXRydWUmZGF0ZT0yMDIyLTA0LTI3JmxpbWl0PTImb3JkZXI9YXNjJnBhZ2VfbWFya2VyPUFBJTdDZjEyMmJjYmY4YWQwNzRmZmJlMTZmNjkxOWQ0ZDc3NjZlMzA3MWNmNmU1Nzg3OGE0OGU1NjQ1YzQyM2U3NzJhOSZzb3J0PXRpY2tlcg.json diff --git a/test_rest/mocks/v3/trades/AAPL?limit=2.json b/test_rest/mocks/v3/trades/AAPL&limit=2.json similarity index 100% rename from test_rest/mocks/v3/trades/AAPL?limit=2.json rename to test_rest/mocks/v3/trades/AAPL&limit=2.json diff --git a/test_rest/test_snapshots.py b/test_rest/test_snapshots.py index e882ac4d..f620e6dd 100644 --- a/test_rest/test_snapshots.py +++ b/test_rest/test_snapshots.py @@ -16,7 +16,7 @@ class SnapshotsTest(BaseTest): def test_get_snapshot_all(self): - snapshots = self.c.get_snapshot_all() + snapshots = self.c.get_snapshot_all("stocks") expected = [ Snapshot( day=[ @@ -54,7 +54,7 @@ def test_get_snapshot_all(self): self.assertEqual(snapshots, expected) def test_get_snapshot_direction(self): - snapshots = self.c.get_snapshot_direction("gainers") + snapshots = self.c.get_snapshot_direction("stocks", "gainers") expected = [ Snapshot( day=[ @@ -124,7 +124,7 @@ def test_get_snapshot_direction(self): self.assertEqual(snapshots, expected) def test_get_snapshot_ticker(self): - snapshots = self.c.get_snapshot_ticker("AAPL") + snapshots = self.c.get_snapshot_ticker("stocks", "AAPL") expected = Snapshot( day=[ Agg( diff --git a/test_rest/test_tickers.py b/test_rest/test_tickers.py index 7e534c46..d8f84959 100644 --- a/test_rest/test_tickers.py +++ b/test_rest/test_tickers.py @@ -140,14 +140,13 @@ def test_list_ticker_news(self): image_url="https://images.mktw.net/im-533637/social", keywords=None, published_utc="2022-04-28T17:08:00Z", - publisher=[ - Publisher( + publisher=Publisher( favicon_url="https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico", homepage_url="https://www.marketwatch.com/", logo_url="https://s3.polygon.io/public/assets/news/logos/marketwatch.svg", name="MarketWatch", ) - ], + , tickers=["MSFT", "TSN", "NFLX", "AMZN"], title="Theres a big hole in the Feds theory of inflation—incomes are falling at a record 10.9 rate", ) From 5f364ddae02f3c2016eadb7cbaea031684597391 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 14:17:18 -0400 Subject: [PATCH 03/19] style --- polygon/rest/base.py | 11 ++++++++--- test_rest/base.py | 4 ++-- test_rest/test_tickers.py | 11 +++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/polygon/rest/base.py b/polygon/rest/base.py index 0dbb7519..40337aa5 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -101,7 +101,7 @@ def time_mult(timestamp_res: str) -> int: return 1 def _get_params( - self, fn, caller_locals: Dict[str, Any], datetime_res: str = "nanos" + self, fn, caller_locals: Dict[str, Any], datetime_res: str = "nanos" ): params = caller_locals["params"] if params is None: @@ -119,8 +119,13 @@ def _get_params( elif isinstance(val, datetime): val = int(val.timestamp() * self.time_mult(datetime_res)) if val is not None: - if argname.endswith('_lt') or argname.endswith('_lte') or argname.endswith('_gt') or argname.endswith('_gte'): - argname = argname.replace('_', '.') + if ( + argname.endswith("_lt") + or argname.endswith("_lte") + or argname.endswith("_gt") + or argname.endswith("_gte") + ): + argname = argname.replace("_", ".") params[argname] = val return params diff --git a/test_rest/base.py b/test_rest/base.py index ff1576a7..883e93f2 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -17,10 +17,10 @@ urllpath = abspath.replace(mockdir, "") urllpath = re.sub(".json$", "", urllpath) urllpath = re.sub("/index$", "", urllpath) - if '?' in urllpath: + if "?" in urllpath: # Windows will be sad. We support dev on Windows. raise Exception(f"use & instead of ? in path ${urllpath}") - urllpath = urllpath.replace('&', '?', 1) + urllpath = urllpath.replace("&", "?", 1) mocks.append((urllpath, f.read())) unittest.util._MAX_LENGTH = 30000 # type: ignore diff --git a/test_rest/test_tickers.py b/test_rest/test_tickers.py index d8f84959..b965753e 100644 --- a/test_rest/test_tickers.py +++ b/test_rest/test_tickers.py @@ -141,12 +141,11 @@ def test_list_ticker_news(self): keywords=None, published_utc="2022-04-28T17:08:00Z", publisher=Publisher( - favicon_url="https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico", - homepage_url="https://www.marketwatch.com/", - logo_url="https://s3.polygon.io/public/assets/news/logos/marketwatch.svg", - name="MarketWatch", - ) - , + favicon_url="https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico", + homepage_url="https://www.marketwatch.com/", + logo_url="https://s3.polygon.io/public/assets/news/logos/marketwatch.svg", + name="MarketWatch", + ), tickers=["MSFT", "TSN", "NFLX", "AMZN"], title="Theres a big hole in the Feds theory of inflation—incomes are falling at a record 10.9 rate", ) From 70526d3ae3d8c4ffd51835281e15aa9c214cea0c Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 14:18:03 -0400 Subject: [PATCH 04/19] only lint 3.10 --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index afb92d9c..76bc9a45 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.8', '3.9', '3.10'] + python-version: ['3.10'] name: Lint ${{ matrix.python-version }} steps: - uses: actions/checkout@v3 From 695097c289a1dfcfd260827e2a0237852e1aa4f6 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 14:20:20 -0400 Subject: [PATCH 05/19] remove mac --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 52f2471a..72cda691 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, windows-latest] python-version: ['3.8', '3.9', '3.10'] runs-on: ${{ matrix.os }} name: ${{ matrix.os }} Unit test ${{ matrix.python-version }} From 711c61e2da1d6a6f5fa1b8243453b52a51b97d51 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 14:27:47 -0400 Subject: [PATCH 06/19] replace : with ; --- test_rest/base.py | 5 ++++- .../markets/crypto/tickers/{X:BTCUSD => X;BTCUSD}/book.json | 0 ...O:AAPL230616C00150000.json => O;AAPL230616C00150000.json} | 0 3 files changed, 4 insertions(+), 1 deletion(-) rename test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/{X:BTCUSD => X;BTCUSD}/book.json (100%) rename test_rest/mocks/v3/snapshot/options/AAPL/{O:AAPL230616C00150000.json => O;AAPL230616C00150000.json} (100%) diff --git a/test_rest/base.py b/test_rest/base.py index 883e93f2..e0d0ec87 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -17,10 +17,13 @@ urllpath = abspath.replace(mockdir, "") urllpath = re.sub(".json$", "", urllpath) urllpath = re.sub("/index$", "", urllpath) + # Windows will be sad. We support dev on Windows. if "?" in urllpath: - # Windows will be sad. We support dev on Windows. raise Exception(f"use & instead of ? in path ${urllpath}") urllpath = urllpath.replace("&", "?", 1) + if ":" in urllpath: + raise Exception(f"use ; instead of : in path ${urllpath}") + urllpath = urllpath.replace(";", ":", 1) mocks.append((urllpath, f.read())) unittest.util._MAX_LENGTH = 30000 # type: ignore diff --git a/test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/X:BTCUSD/book.json b/test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/X;BTCUSD/book.json similarity index 100% rename from test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/X:BTCUSD/book.json rename to test_rest/mocks/v2/snapshot/locale/global/markets/crypto/tickers/X;BTCUSD/book.json diff --git a/test_rest/mocks/v3/snapshot/options/AAPL/O:AAPL230616C00150000.json b/test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json similarity index 100% rename from test_rest/mocks/v3/snapshot/options/AAPL/O:AAPL230616C00150000.json rename to test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json From c774709b56c03bdbfcee14eee6a58d40d5ad17f9 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 14:41:19 -0400 Subject: [PATCH 07/19] windows hack --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 72cda691..214275c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,8 @@ jobs: runs-on: ${{ matrix.os }} name: ${{ matrix.os }} Unit test ${{ matrix.python-version }} steps: + - name: Windows hack + run: git config --system core.longpaths true - uses: actions/checkout@v3 - name: Setup Python uses: actions/setup-python@v3 From d20b9655cc028cbc44429ce8ca35996ccdf3c736 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 14:58:15 -0400 Subject: [PATCH 08/19] debugging --- test_rest/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_rest/base.py b/test_rest/base.py index e0d0ec87..d00acd07 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -24,6 +24,7 @@ if ":" in urllpath: raise Exception(f"use ; instead of : in path ${urllpath}") urllpath = urllpath.replace(";", ":", 1) + print(urllpath) mocks.append((urllpath, f.read())) unittest.util._MAX_LENGTH = 30000 # type: ignore From 15f13e0f1543ff4a4844a9cf3cdccb93329acb9e Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:00:06 -0400 Subject: [PATCH 09/19] only hack on windows --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 214275c7..baecc7a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: steps: - name: Windows hack run: git config --system core.longpaths true + if: ${{ matrix.os == 'windows-latest' }} - uses: actions/checkout@v3 - name: Setup Python uses: actions/setup-python@v3 From 57ffc83b12e4443628b5c7454ecae6b3260bfc20 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:11:31 -0400 Subject: [PATCH 10/19] more windows hacks --- polygon/rest/models/tickers.py | 2 +- test_rest/base.py | 2 +- test_rest/test_tickers.py | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/polygon/rest/models/tickers.py b/polygon/rest/models/tickers.py index 35b1102b..ee4712b1 100644 --- a/polygon/rest/models/tickers.py +++ b/polygon/rest/models/tickers.py @@ -159,7 +159,7 @@ def from_dict(d): published_utc=d.get("published_utc", None), publisher=None if "publisher" not in d - else Publisher.from_dict(d["publisher"]), + else [Publisher.from_dict(d["publisher"])], tickers=d.get("tickers", None), title=d.get("title", None), ) diff --git a/test_rest/base.py b/test_rest/base.py index d00acd07..c3b37a53 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -23,7 +23,7 @@ urllpath = urllpath.replace("&", "?", 1) if ":" in urllpath: raise Exception(f"use ; instead of : in path ${urllpath}") - urllpath = urllpath.replace(";", ":", 1) + urllpath = urllpath.replace(";", "\\:", 1) print(urllpath) mocks.append((urllpath, f.read())) diff --git a/test_rest/test_tickers.py b/test_rest/test_tickers.py index b965753e..7e534c46 100644 --- a/test_rest/test_tickers.py +++ b/test_rest/test_tickers.py @@ -140,12 +140,14 @@ def test_list_ticker_news(self): image_url="https://images.mktw.net/im-533637/social", keywords=None, published_utc="2022-04-28T17:08:00Z", - publisher=Publisher( - favicon_url="https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico", - homepage_url="https://www.marketwatch.com/", - logo_url="https://s3.polygon.io/public/assets/news/logos/marketwatch.svg", - name="MarketWatch", - ), + publisher=[ + Publisher( + favicon_url="https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico", + homepage_url="https://www.marketwatch.com/", + logo_url="https://s3.polygon.io/public/assets/news/logos/marketwatch.svg", + name="MarketWatch", + ) + ], tickers=["MSFT", "TSN", "NFLX", "AMZN"], title="Theres a big hole in the Feds theory of inflation—incomes are falling at a record 10.9 rate", ) From c9a14000b2369c2a28415af14ec2c794daa4eb5e Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:28:53 -0400 Subject: [PATCH 11/19] pook --- poetry.lock | 167 +++++++++++++++++++++++++++++++++++++-- polygon/__init__.py | 2 +- polygon/rest/__init__.py | 8 +- pyproject.toml | 2 +- test_rest/base.py | 21 ++--- 5 files changed, 177 insertions(+), 23 deletions(-) diff --git a/poetry.lock b/poetry.lock index 8ffca2eb..02b9e054 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6,6 +6,20 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "attrs" +version = "21.4.0" +description = "Classes Without Boilerplate" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[package.extras] +dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] +docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] +tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] +tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"] + [[package]] name = "babel" version = "2.10.1" @@ -88,12 +102,16 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] -name = "httpretty" -version = "1.1.4" -description = "HTTP client mock for Python" +name = "furl" +version = "2.1.3" +description = "URL manipulation made simple." category = "dev" optional = false -python-versions = ">=3" +python-versions = "*" + +[package.dependencies] +orderedmultidict = ">=1.0.1" +six = ">=1.8.0" [[package]] name = "idna" @@ -128,6 +146,21 @@ docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] perf = ["ipython"] testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)", "importlib-resources (>=1.3)"] +[[package]] +name = "importlib-resources" +version = "5.7.1" +description = "Read resources from Python packages" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} + +[package.extras] +docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] +testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"] + [[package]] name = "jinja2" version = "3.1.2" @@ -142,6 +175,25 @@ MarkupSafe = ">=2.0" [package.extras] i18n = ["Babel (>=2.7)"] +[[package]] +name = "jsonschema" +version = "4.5.1" +description = "An implementation of JSON Schema validation for Python" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +attrs = ">=17.4.0" +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} +importlib-resources = {version = ">=1.4.0", markers = "python_version < \"3.9\""} +pyrsistent = ">=0.14.0,<0.17.0 || >0.17.0,<0.17.1 || >0.17.1,<0.17.2 || >0.17.2" +typing-extensions = {version = "*", markers = "python_version < \"3.8\""} + +[package.extras] +format = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3987", "uri-template", "webcolors (>=1.11)"] +format_nongpl = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3986-validator (>0.1.0)", "uri-template", "webcolors (>=1.11)"] + [[package]] name = "markupsafe" version = "2.1.1" @@ -177,6 +229,17 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "orderedmultidict" +version = "1.0.1" +description = "Ordered Multivalue Dictionary" +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +six = ">=1.8.0" + [[package]] name = "packaging" version = "21.3" @@ -208,6 +271,19 @@ python-versions = ">=3.7" docs = ["furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx-autodoc-typehints (>=1.12)", "sphinx (>=4)"] test = ["appdirs (==1.4.4)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)", "pytest (>=6)"] +[[package]] +name = "pook" +version = "1.0.2" +description = "HTTP traffic mocking and expectations made easy" +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +furl = ">=0.5.6" +jsonschema = ">=2.5.1" +xmltodict = ">=0.11.0" + [[package]] name = "pygments" version = "2.12.0" @@ -227,6 +303,14 @@ python-versions = ">=3.6.8" [package.extras] diagrams = ["railroad-diagrams", "jinja2"] +[[package]] +name = "pyrsistent" +version = "0.18.1" +description = "Persistent/Functional/Immutable data structures" +category = "dev" +optional = false +python-versions = ">=3.7" + [[package]] name = "pytz" version = "2022.1" @@ -253,6 +337,14 @@ urllib3 = ">=1.21.1,<1.27" socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"] +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" + [[package]] name = "snowballstemmer" version = "2.2.0" @@ -463,6 +555,14 @@ category = "main" optional = false python-versions = ">=3.7" +[[package]] +name = "xmltodict" +version = "0.13.0" +description = "Makes working with XML feel like you are working with JSON" +category = "dev" +optional = false +python-versions = ">=3.4" + [[package]] name = "zipp" version = "3.8.0" @@ -478,13 +578,17 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "d6e34b1cf2ee9c25cf7917f12cc312fc66b486a5d87821f575b906f843f14753" +content-hash = "dad901e5458d3102c0ccf11425ff6117a7a1991f45d1fca53787fac253c5d443" [metadata.files] alabaster = [ {file = "alabaster-0.7.12-py2.py3-none-any.whl", hash = "sha256:446438bdcca0e05bd45ea2de1668c1d9b032e1a9154c2c259092d77031ddd359"}, {file = "alabaster-0.7.12.tar.gz", hash = "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02"}, ] +attrs = [ + {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, + {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, +] babel = [ {file = "Babel-2.10.1-py3-none-any.whl", hash = "sha256:3f349e85ad3154559ac4930c3918247d319f21910d5ce4b25d439ed8693b98d2"}, {file = "Babel-2.10.1.tar.gz", hash = "sha256:98aeaca086133efb3e1e2aad0396987490c8425929ddbcfe0550184fdc54cd13"}, @@ -534,8 +638,9 @@ docutils = [ {file = "docutils-0.17.1-py2.py3-none-any.whl", hash = "sha256:cf316c8370a737a022b72b56874f6602acf974a37a9fba42ec2876387549fc61"}, {file = "docutils-0.17.1.tar.gz", hash = "sha256:686577d2e4c32380bb50cbb22f575ed742d58168cee37e99117a854bcd88f125"}, ] -httpretty = [ - {file = "httpretty-1.1.4.tar.gz", hash = "sha256:20de0e5dd5a18292d36d928cc3d6e52f8b2ac73daec40d41eb62dee154933b68"}, +furl = [ + {file = "furl-2.1.3-py2.py3-none-any.whl", hash = "sha256:9ab425062c4217f9802508e45feb4a83e54324273ac4b202f1850363309666c0"}, + {file = "furl-2.1.3.tar.gz", hash = "sha256:5a6188fe2666c484a12159c18be97a1977a71d632ef5bb867ef15f54af39cc4e"}, ] idna = [ {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, @@ -549,10 +654,18 @@ importlib-metadata = [ {file = "importlib_metadata-4.11.3-py3-none-any.whl", hash = "sha256:1208431ca90a8cca1a6b8af391bb53c1a2db74e5d1cef6ddced95d4b2062edc6"}, {file = "importlib_metadata-4.11.3.tar.gz", hash = "sha256:ea4c597ebf37142f827b8f39299579e31685c31d3a438b59f469406afd0f2539"}, ] +importlib-resources = [ + {file = "importlib_resources-5.7.1-py3-none-any.whl", hash = "sha256:e447dc01619b1e951286f3929be820029d48c75eb25d265c28b92a16548212b8"}, + {file = "importlib_resources-5.7.1.tar.gz", hash = "sha256:b6062987dfc51f0fcb809187cffbd60f35df7acb4589091f154214af6d0d49d3"}, +] jinja2 = [ {file = "Jinja2-3.1.2-py3-none-any.whl", hash = "sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61"}, {file = "Jinja2-3.1.2.tar.gz", hash = "sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852"}, ] +jsonschema = [ + {file = "jsonschema-4.5.1-py3-none-any.whl", hash = "sha256:71b5e39324422543546572954ce71c67728922c104902cb7ce252e522235b33f"}, + {file = "jsonschema-4.5.1.tar.gz", hash = "sha256:7c6d882619340c3347a1bf7315e147e6d3dae439033ae6383d6acb908c101dfc"}, +] markupsafe = [ {file = "MarkupSafe-2.1.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:86b1f75c4e7c2ac2ccdaec2b9022845dbb81880ca318bb7a0a01fbf7813e3812"}, {file = "MarkupSafe-2.1.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f121a1420d4e173a5d96e47e9a0c0dcff965afdf1626d28de1460815f7c4ee7a"}, @@ -624,6 +737,10 @@ mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, ] +orderedmultidict = [ + {file = "orderedmultidict-1.0.1-py2.py3-none-any.whl", hash = "sha256:43c839a17ee3cdd62234c47deca1a8508a3f2ca1d0678a3bf791c87cf84adbf3"}, + {file = "orderedmultidict-1.0.1.tar.gz", hash = "sha256:04070bbb5e87291cc9bfa51df413677faf2141c73c61d2a5f7b26bea3cd882ad"}, +] packaging = [ {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, @@ -636,6 +753,11 @@ platformdirs = [ {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"}, {file = "platformdirs-2.5.2.tar.gz", hash = "sha256:58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"}, ] +pook = [ + {file = "pook-1.0.2-py2-none-any.whl", hash = "sha256:cd3cbfe280d544e672f41a5b9482883841ba247f865858b57fd59f729e37616a"}, + {file = "pook-1.0.2-py3-none-any.whl", hash = "sha256:2e16d231ec9fe071c14cad7fe41261f65b401f6cb30935a169cf6fc229bd0a1d"}, + {file = "pook-1.0.2.tar.gz", hash = "sha256:f28112db062d17db245b351c80f2bb5bf1e56ebfa93d3d75cc44f500c15c40eb"}, +] pygments = [ {file = "Pygments-2.12.0-py3-none-any.whl", hash = "sha256:dc9c10fb40944260f6ed4c688ece0cd2048414940f1cea51b8b226318411c519"}, {file = "Pygments-2.12.0.tar.gz", hash = "sha256:5eb116118f9612ff1ee89ac96437bb6b49e8f04d8a13b514ba26f620208e26eb"}, @@ -644,6 +766,29 @@ pyparsing = [ {file = "pyparsing-3.0.8-py3-none-any.whl", hash = "sha256:ef7b523f6356f763771559412c0d7134753f037822dad1b16945b7b846f7ad06"}, {file = "pyparsing-3.0.8.tar.gz", hash = "sha256:7bf433498c016c4314268d95df76c81b842a4cb2b276fa3312cfb1e1d85f6954"}, ] +pyrsistent = [ + {file = "pyrsistent-0.18.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:df46c854f490f81210870e509818b729db4488e1f30f2a1ce1698b2295a878d1"}, + {file = "pyrsistent-0.18.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5d45866ececf4a5fff8742c25722da6d4c9e180daa7b405dc0a2a2790d668c26"}, + {file = "pyrsistent-0.18.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4ed6784ceac462a7d6fcb7e9b663e93b9a6fb373b7f43594f9ff68875788e01e"}, + {file = "pyrsistent-0.18.1-cp310-cp310-win32.whl", hash = "sha256:e4f3149fd5eb9b285d6bfb54d2e5173f6a116fe19172686797c056672689daf6"}, + {file = "pyrsistent-0.18.1-cp310-cp310-win_amd64.whl", hash = "sha256:636ce2dc235046ccd3d8c56a7ad54e99d5c1cd0ef07d9ae847306c91d11b5fec"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:e92a52c166426efbe0d1ec1332ee9119b6d32fc1f0bbfd55d5c1088070e7fc1b"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d7a096646eab884bf8bed965bad63ea327e0d0c38989fc83c5ea7b8a87037bfc"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cdfd2c361b8a8e5d9499b9082b501c452ade8bbf42aef97ea04854f4a3f43b22"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-win32.whl", hash = "sha256:7ec335fc998faa4febe75cc5268a9eac0478b3f681602c1f27befaf2a1abe1d8"}, + {file = "pyrsistent-0.18.1-cp37-cp37m-win_amd64.whl", hash = "sha256:6455fc599df93d1f60e1c5c4fe471499f08d190d57eca040c0ea182301321286"}, + {file = "pyrsistent-0.18.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:fd8da6d0124efa2f67d86fa70c851022f87c98e205f0594e1fae044e7119a5a6"}, + {file = "pyrsistent-0.18.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7bfe2388663fd18bd8ce7db2c91c7400bf3e1a9e8bd7d63bf7e77d39051b85ec"}, + {file = "pyrsistent-0.18.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0e3e1fcc45199df76053026a51cc59ab2ea3fc7c094c6627e93b7b44cdae2c8c"}, + {file = "pyrsistent-0.18.1-cp38-cp38-win32.whl", hash = "sha256:b568f35ad53a7b07ed9b1b2bae09eb15cdd671a5ba5d2c66caee40dbf91c68ca"}, + {file = "pyrsistent-0.18.1-cp38-cp38-win_amd64.whl", hash = "sha256:d1b96547410f76078eaf66d282ddca2e4baae8964364abb4f4dcdde855cd123a"}, + {file = "pyrsistent-0.18.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:f87cc2863ef33c709e237d4b5f4502a62a00fab450c9e020892e8e2ede5847f5"}, + {file = "pyrsistent-0.18.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6bc66318fb7ee012071b2792024564973ecc80e9522842eb4e17743604b5e045"}, + {file = "pyrsistent-0.18.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:914474c9f1d93080338ace89cb2acee74f4f666fb0424896fcfb8d86058bf17c"}, + {file = "pyrsistent-0.18.1-cp39-cp39-win32.whl", hash = "sha256:1b34eedd6812bf4d33814fca1b66005805d3640ce53140ab8bbb1e2651b0d9bc"}, + {file = "pyrsistent-0.18.1-cp39-cp39-win_amd64.whl", hash = "sha256:e24a828f57e0c337c8d8bb9f6b12f09dfdf0273da25fda9e314f0b684b415a07"}, + {file = "pyrsistent-0.18.1.tar.gz", hash = "sha256:d4d61f8b993a7255ba714df3aca52700f8125289f84f704cf80916517c46eb96"}, +] pytz = [ {file = "pytz-2022.1-py2.py3-none-any.whl", hash = "sha256:e68985985296d9a66a881eb3193b0906246245294a881e7c8afe623866ac6a5c"}, {file = "pytz-2022.1.tar.gz", hash = "sha256:1e760e2fe6a8163bc0b3d9a19c4f84342afa0a2affebfaa84b01b978a02ecaa7"}, @@ -652,6 +797,10 @@ requests = [ {file = "requests-2.27.1-py2.py3-none-any.whl", hash = "sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"}, {file = "requests-2.27.1.tar.gz", hash = "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61"}, ] +six = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] snowballstemmer = [ {file = "snowballstemmer-2.2.0-py2.py3-none-any.whl", hash = "sha256:c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a"}, {file = "snowballstemmer-2.2.0.tar.gz", hash = "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1"}, @@ -792,6 +941,10 @@ websockets = [ {file = "websockets-10.3-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:3eda1cb7e9da1b22588cefff09f0951771d6ee9fa8dbe66f5ae04cc5f26b2b55"}, {file = "websockets-10.3.tar.gz", hash = "sha256:fc06cc8073c8e87072138ba1e431300e2d408f054b27047d047b549455066ff4"}, ] +xmltodict = [ + {file = "xmltodict-0.13.0-py2.py3-none-any.whl", hash = "sha256:aa89e8fd76320154a40d19a0df04a4695fb9dc5ba977cbb68ab3e4eb225e7852"}, + {file = "xmltodict-0.13.0.tar.gz", hash = "sha256:341595a488e3e01a85a9d8911d8912fd922ede5fecc4dce437eb4b6c8d037e56"}, +] zipp = [ {file = "zipp-3.8.0-py3-none-any.whl", hash = "sha256:c4f6e5bbf48e74f7a38e7cc5b0480ff42b0ae5178957d564d18932525d5cf099"}, {file = "zipp-3.8.0.tar.gz", hash = "sha256:56bf8aadb83c24db6c4b577e13de374ccfb67da2078beba1d037c17980bf43ad"}, diff --git a/polygon/__init__.py b/polygon/__init__.py index e4e0ced3..302bbc83 100644 --- a/polygon/__init__.py +++ b/polygon/__init__.py @@ -1,2 +1,2 @@ -from .rest import RESTClient +from .rest import RESTClient, BASE, ENV_KEY from .websocket import WebSocketClient, AuthError diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index b0c31594..5607cc46 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -15,8 +15,8 @@ import os -base = "https://api.polygon.io" -env_key = "POLYGON_API_KEY" +BASE = "https://api.polygon.io" +ENV_KEY = "POLYGON_API_KEY" class RESTClient( @@ -33,12 +33,12 @@ class RESTClient( ): def __init__( self, - api_key: Optional[str] = os.getenv(env_key), + api_key: Optional[str] = os.getenv(ENV_KEY), connect_timeout: float = 10.0, read_timeout: float = 10.0, num_pools: int = 10, retries: int = 3, - base: str = base, + base: str = BASE, verbose: bool = False, ): super().__init__( diff --git a/pyproject.toml b/pyproject.toml index 7e55dd56..77335064 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,13 +33,13 @@ certifi = "^2021.10.8" black = "^22.3.0" mypy = "^0.942" types-urllib3 = "^1.26.13" -httpretty = "^1.1.4" Sphinx = "^4.5.0" sphinx-rtd-theme = "^1.0.0" # keep this in sync with docs/requirements.txt for readthedocs.org sphinx-autodoc-typehints = "^1.18.1" types-certifi = "^2021.10.8" types-setuptools = "^57.4.14" +pook = "^1.0.2" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/test_rest/base.py b/test_rest/base.py index c3b37a53..ab2c7c3c 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -1,9 +1,9 @@ -from polygon import RESTClient +from polygon import RESTClient, BASE import os import re import unittest -import httpretty # type: ignore +import pook # mocks are stored in file tree mocks = [] @@ -23,20 +23,21 @@ urllpath = urllpath.replace("&", "?", 1) if ":" in urllpath: raise Exception(f"use ; instead of : in path ${urllpath}") - urllpath = urllpath.replace(";", "\\:", 1) - print(urllpath) + urllpath = urllpath.replace(";", ":", 1) + #print(abspath, urllpath) mocks.append((urllpath, f.read())) -unittest.util._MAX_LENGTH = 30000 # type: ignore +pook.on() +for m in mocks: + url = BASE + m[0] + # print('register', url) + pook.get(url, reply=200, response_body=m[1]) + +unittest.util._MAX_LENGTH = 30000 # type: ignore class BaseTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.maxDiff = None cls.c = RESTClient("", verbose=True) - httpretty.enable(verbose=True, allow_net_connect=False) - for m in mocks: - url = cls.c.BASE + m[0] - # print('register', url) - httpretty.register_uri(httpretty.GET, url, m[1], match_querystring=True) From f3a8bf0c736e25ae35a0fae2c63a80e8b3c2edaf Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:31:08 -0400 Subject: [PATCH 12/19] style --- test_rest/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_rest/base.py b/test_rest/base.py index ab2c7c3c..5b38a077 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -24,7 +24,7 @@ if ":" in urllpath: raise Exception(f"use ; instead of : in path ${urllpath}") urllpath = urllpath.replace(";", ":", 1) - #print(abspath, urllpath) + # print(abspath, urllpath) mocks.append((urllpath, f.read())) @@ -36,6 +36,7 @@ unittest.util._MAX_LENGTH = 30000 # type: ignore + class BaseTest(unittest.TestCase): @classmethod def setUpClass(cls): From c47333423d53e09a1cb23797c353ac5026bc5151 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:32:55 -0400 Subject: [PATCH 13/19] fix static --- test_rest/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_rest/base.py b/test_rest/base.py index 5b38a077..14faf0eb 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -3,7 +3,7 @@ import os import re import unittest -import pook +import pook # type: ignore # mocks are stored in file tree mocks = [] From 40a6777ff0692ae9810732d8738498f2b3873519 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:43:12 -0400 Subject: [PATCH 14/19] more hacking --- test_rest/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_rest/base.py b/test_rest/base.py index 14faf0eb..9d22093b 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -30,8 +30,8 @@ pook.on() for m in mocks: - url = BASE + m[0] - # print('register', url) + url = BASE + m[0].replace('\\', '/') + print('register', url) pook.get(url, reply=200, response_body=m[1]) unittest.util._MAX_LENGTH = 30000 # type: ignore From 58cd197a2c6d0fbe2d611976167efc0f0bd42e54 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:48:07 -0400 Subject: [PATCH 15/19] please pook --- test_rest/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test_rest/base.py b/test_rest/base.py index 9d22093b..652ef46d 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -28,11 +28,6 @@ mocks.append((urllpath, f.read())) -pook.on() -for m in mocks: - url = BASE + m[0].replace('\\', '/') - print('register', url) - pook.get(url, reply=200, response_body=m[1]) unittest.util._MAX_LENGTH = 30000 # type: ignore @@ -42,3 +37,8 @@ class BaseTest(unittest.TestCase): def setUpClass(cls): cls.maxDiff = None cls.c = RESTClient("", verbose=True) + pook.on() + for m in mocks: + url = BASE + m[0].replace('\\', '/') + print('register', url) + pook.get(url, reply=200, response_body=m[1]) From 2eb8593db3c2d66ee757f5b57e5a95bcacc1fe3f Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:53:13 -0400 Subject: [PATCH 16/19] windowsss --- test_rest/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_rest/base.py b/test_rest/base.py index 652ef46d..8ee9b693 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -16,7 +16,7 @@ with open(abspath, "r") as f: urllpath = abspath.replace(mockdir, "") urllpath = re.sub(".json$", "", urllpath) - urllpath = re.sub("/index$", "", urllpath) + urllpath = re.sub("[\\/]index$", "", urllpath) # Windows will be sad. We support dev on Windows. if "?" in urllpath: raise Exception(f"use & instead of ? in path ${urllpath}") From c6b172cc193445022c379b721aa232310d9b3cb6 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 15:58:30 -0400 Subject: [PATCH 17/19] style --- test_rest/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test_rest/base.py b/test_rest/base.py index 8ee9b693..f731c4d6 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -14,9 +14,9 @@ if fname.endswith(".json"): abspath = os.path.join(dname, fname) with open(abspath, "r") as f: - urllpath = abspath.replace(mockdir, "") + urllpath = abspath.replace(mockdir, "").replace('\\', '/') urllpath = re.sub(".json$", "", urllpath) - urllpath = re.sub("[\\/]index$", "", urllpath) + urllpath = re.sub("/index$", "", urllpath) # Windows will be sad. We support dev on Windows. if "?" in urllpath: raise Exception(f"use & instead of ? in path ${urllpath}") @@ -39,6 +39,6 @@ def setUpClass(cls): cls.c = RESTClient("", verbose=True) pook.on() for m in mocks: - url = BASE + m[0].replace('\\', '/') + url = BASE + m[0] print('register', url) pook.get(url, reply=200, response_body=m[1]) From 0891e1e0bea700618a2cb887073f7c19e67bf5cf Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 16:00:18 -0400 Subject: [PATCH 18/19] lint --- test_rest/base.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test_rest/base.py b/test_rest/base.py index f731c4d6..b2a29d04 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -3,7 +3,7 @@ import os import re import unittest -import pook # type: ignore +import pook # type: ignore # mocks are stored in file tree mocks = [] @@ -14,7 +14,7 @@ if fname.endswith(".json"): abspath = os.path.join(dname, fname) with open(abspath, "r") as f: - urllpath = abspath.replace(mockdir, "").replace('\\', '/') + urllpath = abspath.replace(mockdir, "").replace("\\", "/") urllpath = re.sub(".json$", "", urllpath) urllpath = re.sub("/index$", "", urllpath) # Windows will be sad. We support dev on Windows. @@ -28,7 +28,6 @@ mocks.append((urllpath, f.read())) - unittest.util._MAX_LENGTH = 30000 # type: ignore @@ -40,5 +39,5 @@ def setUpClass(cls): pook.on() for m in mocks: url = BASE + m[0] - print('register', url) + print("register", url) pook.get(url, reply=200, response_body=m[1]) From 1cdcda931ae278972c68ec2337bfb35910f886d2 Mon Sep 17 00:00:00 2001 From: zack <43246297+clickingbuttons@users.noreply.github.com> Date: Wed, 11 May 2022 16:08:56 -0400 Subject: [PATCH 19/19] remove base export --- polygon/__init__.py | 2 +- test_rest/base.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/polygon/__init__.py b/polygon/__init__.py index 78cc79cc..7fe320e3 100644 --- a/polygon/__init__.py +++ b/polygon/__init__.py @@ -1,3 +1,3 @@ -from .rest import RESTClient, BASE, ENV_KEY +from .rest import RESTClient from .rest.base import NoResults from .websocket import WebSocketClient, AuthError diff --git a/test_rest/base.py b/test_rest/base.py index b2a29d04..45aa168e 100644 --- a/test_rest/base.py +++ b/test_rest/base.py @@ -1,4 +1,4 @@ -from polygon import RESTClient, BASE +from polygon import RESTClient import os import re @@ -38,6 +38,6 @@ def setUpClass(cls): cls.c = RESTClient("", verbose=True) pook.on() for m in mocks: - url = BASE + m[0] - print("register", url) + url = cls.c.BASE + m[0] + # print("register", url) pook.get(url, reply=200, response_body=m[1])