Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 9c2ec31

Browse files
committed
tests: add some basic tests for URN equivalence
1 parent 4130230 commit 9c2ec31

File tree

5 files changed

+142
-20
lines changed

5 files changed

+142
-20
lines changed

.github/workflows/python.yaml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,31 @@ jobs:
4949
run: |
5050
poetry run cicd/custom_style_check.py
5151
52-
# test:
53-
# name: Run the tests
54-
# runs-on: ubuntu-latest
55-
# strategy:
56-
# matrix:
57-
# python-version: [ 3.7, 3.8, 3.9 ]
58-
59-
# steps:
60-
# - uses: actions/checkout@v2
61-
# - name: Set up Python ${{ matrix.python-version }}
62-
# uses: actions/setup-python@v2
63-
# with:
64-
# python-version: ${{ matrix.python-version }}
65-
# - name: Run image
66-
# uses: abatilo/[email protected]
67-
# - name: Run pytest
68-
# run: |
69-
# poetry run pytest -vv
52+
test:
53+
name: Run the tests
54+
runs-on: ubuntu-latest
55+
strategy:
56+
matrix:
57+
python-version: [ 3.7, 3.8, 3.9 ]
58+
59+
steps:
60+
- uses: actions/checkout@v2
61+
- name: Set up Python ${{ matrix.python-version }}
62+
uses: actions/setup-python@v2
63+
with:
64+
python-version: ${{ matrix.python-version }}
65+
- name: Run image
66+
uses: abatilo/[email protected]
67+
- name: Install dependencies
68+
run: |
69+
poetry install
70+
- name: Run pytest
71+
run: |
72+
poetry run pytest -vv
73+
poetry run pytest -vv > pytest-coverage.txt
74+
- name: Comment coverage
75+
uses: coroo/[email protected]
76+
if: ${{ matrix.python-version == '3.9' && github.event_name == 'pull_request' && github.event.action == 'created' }}
7077

7178
build:
7279
name: Build linkedin_messaging
@@ -90,7 +97,7 @@ jobs:
9097
deploy:
9198
name: Deploy to pypi
9299
runs-on: ubuntu-latest
93-
needs: [lint, build]
100+
needs: [lint, test, build]
94101
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
95102

96103
steps:

linkedin_messaging/api_objects.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def __str__(self):
3535
),
3636
)
3737

38+
def __eq__(self, other: Any):
39+
if not isinstance(other, URN):
40+
return False
41+
return self.id_parts == other.id_parts
42+
3843
def __repr__(self):
3944
return f"URN('{str(self)}')"
4045

poetry.lock

Lines changed: 86 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ jedi = "^0.17.2"
4141
mypy = "^0.782"
4242
pytest = "^6.2.4"
4343
termcolor = "^1.1.0"
44+
pytest-cov = "^2.12.1"
45+
46+
[tool.pytest.ini_options]
47+
addopts = """
48+
-vvv
49+
--doctest-modules
50+
--ignore-glob='examples/*'
51+
--ignore-glob='cicd/*'
52+
--cov=linkedin_messaging
53+
--cov-report html
54+
--cov-report term
55+
"""
4456

4557
[build-system]
4658
requires = ["poetry>=0.12"]

tests/test_urn.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from linkedin_messaging import URN
2+
3+
4+
def test_urn_equivalence():
5+
assert URN("urn:123") == URN("123")
6+
assert URN("urn:(123,456)") == URN("urn:test:(123,456)")
7+
8+
9+
def test_urn_equivalence_in_tuple():
10+
assert (URN("urn:123"), URN("urn:(123,456)")) == (
11+
URN("123"),
12+
URN("urn:test:(123,456)"),
13+
)

0 commit comments

Comments
 (0)