Skip to content

Commit

Permalink
Switch to using pytest instead of nose2
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwager committed Dec 12, 2018
1 parent 7d96f48 commit b8937c0
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ before_install:
install:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install -e .
script:
- flake8
- nose2 --with-coverage
- pytest --cov
after_success:
- coveralls
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ First, install development packages:

```
$ pip install -r requirements-dev.txt
$ pip install -e .
```

## Testing

```
$ nose2
$ pytest
```

## Linting
Expand All @@ -167,5 +168,5 @@ $ flake8
## Coverage

```
$ nose2 --with-coverage
$ pytest --cov
```
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
nose2==0.8.0
pytest==4.0.1
pytest-cov==2.6.0
flake8==3.6.0
coveralls==1.5.1
23 changes: 12 additions & 11 deletions tests/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import mock

import requests
import pytest

from gitem import analytics
from gitem import api
Expand Down Expand Up @@ -55,7 +56,7 @@ def test_get_organization_information(self):
('# of Public Repositories', 'pr1'),
])

self.assertEqual(result, expected)
assert result == expected

def test_get_organization_repositories(self):
return_value = [
Expand Down Expand Up @@ -98,7 +99,7 @@ def test_get_organization_repositories(self):
]),
]

self.assertEqual(result, expected)
assert result == expected

def test_get_organization_members(self):
return_value = [
Expand Down Expand Up @@ -140,7 +141,7 @@ def test_get_organization_members(self):
]),
]

self.assertEqual(result, expected)
assert result == expected

def test_get_repository_information(self):
return_value = (
Expand Down Expand Up @@ -183,7 +184,7 @@ def test_get_repository_information(self):
('Watchers', 'wc1'),
])

self.assertEqual(result, expected)
assert result == expected

def test_get_repository_contributors(self):
return_value = [
Expand Down Expand Up @@ -221,7 +222,7 @@ def test_get_repository_contributors(self):
]),
]

self.assertEqual(result, expected)
assert result == expected

def test_get_user_information(self):
return_value = (
Expand Down Expand Up @@ -258,7 +259,7 @@ def test_get_user_information(self):
('Updated', 'ua1'),
])

self.assertEqual(result, expected)
assert result == expected

def test_get_user_organization(self):
return_value = [
Expand Down Expand Up @@ -292,7 +293,7 @@ def test_get_user_organization(self):
]),
]

self.assertEqual(result, expected)
assert result == expected

def test_get_user_repositories(self):
return_value = [
Expand Down Expand Up @@ -323,7 +324,7 @@ def test_get_user_repositories(self):
])
]

self.assertEqual(result, expected)
assert result == expected

def test_get_repository_commit_emails_basic(self):
return_value = [
Expand All @@ -349,7 +350,7 @@ def test_get_repository_commit_emails_basic(self):

expected = {('username1', 'email1')}

self.assertEqual(result, expected)
assert result == expected

def test_get_repository_commit_emails_conflict(self):
def conflict_generator():
Expand All @@ -367,7 +368,7 @@ def conflict_generator():

expected = set()

self.assertEqual(result, expected)
assert result == expected

def test_get_repository_commit_emails_not_conflict(self):
def not_conflict_generator():
Expand All @@ -381,7 +382,7 @@ def not_conflict_generator():
return_value=return_value
)

with self.assertRaises(api.ApiCallException):
with pytest.raises(api.ApiCallException):
analytics.get_repository_commit_emails(ghapi, "unused", "unused")


Expand Down
49 changes: 25 additions & 24 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import mock

import requests
import pytest

from gitem import api

Expand All @@ -19,10 +20,10 @@
class TestApi(unittest.TestCase):

def assertOk(self, status_code):
self.assertEqual(status_code, requests.codes.OK)
assert status_code == requests.codes.OK

def assertEmpty(self, iterable):
self.assertEqual(len(iterable), 0)
assert len(iterable) == 0

@staticmethod
def api_will_return(json_return_value, status_code=requests.codes.OK, oauth2_token=None):
Expand Down Expand Up @@ -82,7 +83,7 @@ def test_ok(self):
)

self.assertOk(status_code)
self.assertEqual(result, expected)
assert result == expected

def test_invalid_json(self):
will_return = mocked_api_results.INVALID_JSON_RESULT
Expand All @@ -91,10 +92,10 @@ def test_invalid_json(self):

# The API call we make doesn't matter, it will return the same result
# no matter what
with self.assertRaises(api.ApiCallException) as e:
with pytest.raises(api.ApiCallException) as e:
mocked_api.get_public_organization("unused")

self.assertTrue(e.exception.bad_request)
assert e.value.bad_request

def test_invalid_json_argument_type(self):
will_return = mocked_api_results.BAD_JSON_VALUES_RESULT
Expand All @@ -103,10 +104,10 @@ def test_invalid_json_argument_type(self):

# The API call we make doesn't matter, it will return the same result
# no matter what
with self.assertRaises(api.ApiCallException) as e:
with pytest.raises(api.ApiCallException) as e:
mocked_api.get_public_organization("unused")

self.assertTrue(e.exception.bad_request)
assert e.value.bad_request

def test_invalid_json_field(self):
will_return = mocked_api_results.INVALID_FIELDS_RESULT
Expand All @@ -115,10 +116,10 @@ def test_invalid_json_field(self):

# The API call we make doesn't matter, it will return the same result
# no matter what
with self.assertRaises(api.ApiCallException) as e:
with pytest.raises(api.ApiCallException) as e:
mocked_api.get_public_organization("unused")

self.assertTrue(e.exception.unprocessable_entity)
assert e.value.unprocessable_entity

def test_bad_credentials(self):
will_return = mocked_api_results.BAD_CREDENTIALS_RESULT
Expand All @@ -127,10 +128,10 @@ def test_bad_credentials(self):

# The API call we make doesn't matter, it will return the same result
# no matter what
with self.assertRaises(api.ApiCallException) as e:
with pytest.raises(api.ApiCallException) as e:
mocked_api.get_public_organization("unused")

self.assertTrue(e.exception.unauthorized)
assert e.value.unauthorized

def test_maximum_bad_credentials(self):
will_return = mocked_api_results.MAXIMUM_BAD_CREDENTIALS_RESULT
Expand All @@ -139,10 +140,10 @@ def test_maximum_bad_credentials(self):

# The API call we make doesn't matter, it will return the same result
# no matter what
with self.assertRaises(api.ApiCallException) as e:
with pytest.raises(api.ApiCallException) as e:
mocked_api.get_public_organization("unused")

self.assertTrue(e.exception.forbidden)
assert e.value.forbidden

def test_not_found(self):
will_return = mocked_api_results.NOT_FOUND_RESULT
Expand All @@ -151,10 +152,10 @@ def test_not_found(self):

# The API call we make doesn't matter, it will return the same result
# no matter what
with self.assertRaises(api.ApiCallException) as e:
with pytest.raises(api.ApiCallException) as e:
mocked_api.get_public_organization("unused")

self.assertTrue(e.exception.not_found)
assert e.value.not_found

def test_authenticated_endpoint_ok(self):
will_return = mocked_api_results.STANDARD_API_RESULT
Expand All @@ -171,7 +172,7 @@ def test_authenticated_endpoint_ok(self):
)

self.assertOk(status_code)
self.assertEqual(result, expected)
assert result == expected

def test_authenticated_endpoint_missing_token(self):
will_return = mocked_api_results.STANDARD_API_RESULT
Expand All @@ -181,7 +182,7 @@ def test_authenticated_endpoint_missing_token(self):
oauth2_token=None
)

with self.assertRaises(api.AuthenticationRequiredException):
with pytest.raises(api.AuthenticationRequiredException):
mocked_api.get_organization("unused")

def test_paged_ok(self):
Expand All @@ -203,7 +204,7 @@ def test_paged_ok(self):
)

self.assertOk(status_code)
self.assertEqual(result, expected)
assert result == expected

def test_paged_pep_479(self):
mocked_json_values = [
Expand All @@ -225,35 +226,35 @@ def test_get_users_public_repositories_bad_type(self):
type_ = ""
ghapi = api.Api()

with self.assertRaises(ValueError):
with pytest.raises(ValueError):
ghapi.get_users_public_repositories("UNUSED", type_=type_)

def test_get_users_public_repositories_bad_sort(self):
sort = ""
ghapi = api.Api()

with self.assertRaises(ValueError):
with pytest.raises(ValueError):
ghapi.get_users_public_repositories("UNUSED", sort=sort)

def test_get_users_public_repositories_bad_direction(self):
direction = ""
ghapi = api.Api()

with self.assertRaises(ValueError):
with pytest.raises(ValueError):
ghapi.get_users_public_repositories("UNUSED", direction=direction)

def test_get_organizations_public_repositories_bad_type(self):
type_ = ""
ghapi = api.Api()

with self.assertRaises(ValueError):
with pytest.raises(ValueError):
ghapi.get_organizations_public_repositories("UNUSED", type_=type_)

def test_get_repository_contributors_bad_anon(self):
anon = ""
ghapi = api.Api()

with self.assertRaises(ValueError):
with pytest.raises(ValueError):
ghapi.get_repository_contributors("UNUSED", "UNUSED", anon=anon)

def test_get_repository_contributors_ok(self):
Expand All @@ -275,7 +276,7 @@ def test_get_repository_contributors_ok(self):
)

self.assertOk(status_code)
self.assertEqual(result, expected)
assert result == expected


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions tests/test_output/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_basic(self):
{"key":"value"}
''')

self.assertEqual(result, expected)
assert result == expected

def test_list(self):
data = collections.OrderedDict([
Expand All @@ -46,7 +46,7 @@ def test_list(self):
{"key1":{"key2":["value1","value2"]}}
''')

self.assertEqual(result, expected)
assert result == expected

def test_recurse(self):
data = collections.OrderedDict([
Expand All @@ -65,7 +65,7 @@ def test_recurse(self):
{"key1":"value1","key2":{"key3":"value2"}}
''')

self.assertEqual(result, expected)
assert result == expected

def test_multi(self):
data1 = collections.OrderedDict([
Expand All @@ -86,7 +86,7 @@ def test_multi(self):
{"key2":"value2"}
''')

self.assertEqual(result, expected)
assert result == expected


if __name__ == "__main__":
Expand Down

0 comments on commit b8937c0

Please sign in to comment.