Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ var/
# tests artifacts
.cache
.pytest_cache

# editor files
*~
.#*
\#*#
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
language: python
python:
- "2.6"
- "2.7"
- "3.4"
- "3.5"
- "3.5-dev" # 3.5 development branch
- "3.5"
- "3.6"
- "3.6-dev" # 3.6 development branch
- "3.6" # 3.6 development branch
- "3.7-dev" # 3.7 development branch
- "3.8-dev" # 3.7 development branch
- "nightly" # currently points to 3.7-dev
before_install:
- pip install --upgrade pytest
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ publish-test: clean build

publish: clean build
@twine upload --repository pypi dist/*

test:
python -m nose
7 changes: 7 additions & 0 deletions arnparse/arnparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def __init__(self, partition, service, region, account_id, resource_type, resour
self.resource_type = resource_type
self.resource = resource

def __str__(self):
if self.resource_type is None:
rtype_part = ""
else:
rtype_part = self.resource_type + "/"
return "arn:" + ":".join(["" if x is None else x for x in [self.partition, self.service, self.region, self.account_id]]) + ":" + rtype_part + self.resource


def arnparse(arn_str):
if not arn_str.startswith('arn:'):
Expand Down
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest
pytest-mock
hypothesis
22 changes: 22 additions & 0 deletions tests/test_arngenerate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from hypothesis import given
from hypothesis.strategies import sampled_from

from arnparse import arnparse

# ARN examples from https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md
# under Apache2 license

arn_examples = (
"arn:aws:serverlessrepo:us-east-1:012345678901:applications/my-application",
"arn:aws:sns:us-east-1:123456789012:my_topic",
"arn:aws:kinesis:us-east-1:123456789012:stream/my-stream",
"arn:aws:dynamodb:us-east-1:123456789012:table/TestTable/stream/2016-08-11T21:21:33.291",
"arn:aws:sqs:us-west-2:012345678901:my-queu",
"arn:aws:serverlessrepo:us-east-1:012345678901:applications/my-application",
"arn:aws:iam::123456789012:role/S3Access",
"arn:aws:s3:::my-bucket/*",
)

@given(sampled_from(arn_examples))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can achieve the same kind of functionality using pytest's parametrize without the need to involve a new testing library.

def test_arn_to_string(arn):
assert str(arnparse(arn)) == arn