Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install pypi deps
run: poetry install
- name: Style lint
run: poetry run black --check polygon
run: make style
- name: Static lint
run: poetry run mypy polygon
run: make static
if: always()
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: unittest
on:
push:
tags:
- v*
branches:
- v1
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
name: Lint ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Setup Poetry
uses: abatilo/actions-poetry@v2.0.0
- name: Install pypi deps
run: poetry install
- name: Unit tests
run: make test
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.DEFAULT_GOAL := help
TARGET_MAX_CHAR_NUM := 20

GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)

.PHONY: help lint style static test

## Show help
help:
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

## Check code style
style:
poetry run black polygon

## Check static types
static:
poetry run mypy polygon

## Check code style and static types
lint: style static

## Run unit tests
test:
poetry run python -m unittest discover -s tests

13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ urllib3 = "^1.26.9"
black = "^22.3.0"
mypy = "^0.942"
types-urllib3 = "^1.26.13"
httpretty = "^1.1.4"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
22 changes: 22 additions & 0 deletions tests/mocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from polygon import RESTClient
import unittest
import httpretty

mocks = [
(
"/v2/aggs/ticker/AAPL/range/1/day/2005-04-01/2005-04-04",
'{"ticker":"AAPL","queryCount":2,"resultsCount":2,"adjusted":true,"results":[{"v":6.42646396e+08,"vw":1.469,"o":1.5032,"c":1.4604,"h":1.5064,"l":1.4489,"t":1112331600000,"n":82132},{"v":5.78172308e+08,"vw":1.4589,"o":1.4639,"c":1.4675,"h":1.4754,"l":1.4343,"t":1112587200000,"n":65543}],"status":"OK","request_id":"12afda77aab3b1936c5fb6ef4241ae42","count":2}'
)
]

class BaseTest(unittest.TestCase):
setup = False
def setUp(self):
if self.setup:
return
httpretty.enable(verbose=True, allow_net_connect=False)
c = RESTClient("")
for m in mocks:
httpretty.register_uri(httpretty.GET, c.BASE + m[0], m[1])
self.setup = True

11 changes: 11 additions & 0 deletions tests/test_aggs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from polygon import RESTClient
from polygon.rest.models import Agg
from mocks import BaseTest

class AggsTest(BaseTest):
def test_get_aggs(self):
c = RESTClient("")
aggs = c.get_aggs("AAPL", 1, "day", "2005-04-01", "2005-04-04")
expected = [Agg(open=1.5032, high=1.5064, low=1.4489, close=1.4604, volume=642646396.0, vwap=1.469, timestamp=1112331600000, transactions=82132), Agg(open=1.4639, high=1.4754, low=1.4343, close=1.4675, volume=578172308.0, vwap=1.4589, timestamp=1112587200000, transactions=65543)]
self.assertEqual(aggs, expected)