Skip to content

Commit

Permalink
Applying pep8.
Browse files Browse the repository at this point in the history
  • Loading branch information
menegazzo committed Oct 10, 2014
1 parent 50938a5 commit 36b796c
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 174 deletions.
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
pep8maxlinelength = 100
pep8ignore =
docs/conf.py ALL
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def run_tests(self):
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: PyPy',
],

# tests
tests_require=['pytest'],
cmdclass = {'test': PyTest},
cmdclass={'test': PyTest},
)
113 changes: 98 additions & 15 deletions travispy/_tests/test_stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,109 @@
import pytest


#===================================================================================================
# Test
#===================================================================================================
class Test:

@pytest.mark.parametrize(
'state, color, expected_true_properties', [
(Stateful.CREATED, Stateful.YELLOW, (Stateful.CREATED, Stateful.YELLOW, 'pending')),
(Stateful.QUEUED, Stateful.YELLOW, (Stateful.CREATED, Stateful.QUEUED, Stateful.YELLOW, 'pending')),
(Stateful.STARTED, Stateful.YELLOW, (Stateful.CREATED, Stateful.QUEUED, Stateful.STARTED, Stateful.YELLOW, 'pending', 'running')),
(Stateful.PASSED, Stateful.GREEN, (Stateful.CREATED, Stateful.QUEUED, Stateful.STARTED, Stateful.PASSED, Stateful.GREEN, 'finished', 'successful')),
(Stateful.FAILED, Stateful.RED, (Stateful.CREATED, Stateful.QUEUED, Stateful.STARTED, Stateful.FAILED, Stateful.RED, 'finished', 'unsuccessful')),
(Stateful.ERRORED, Stateful.RED, (Stateful.CREATED, Stateful.QUEUED, Stateful.STARTED, Stateful.ERRORED, Stateful.RED, 'finished', 'unsuccessful')),
(Stateful.CANCELED, Stateful.RED, (Stateful.CREATED, Stateful.QUEUED, Stateful.STARTED, Stateful.CANCELED, Stateful.RED, 'finished', 'unsuccessful')),
(Stateful.READY, Stateful.GREEN, (Stateful.CREATED, Stateful.QUEUED, Stateful.STARTED, Stateful.READY, Stateful.GREEN, 'finished')),
])
(
Stateful.CREATED,
Stateful.YELLOW,
(
Stateful.CREATED,
Stateful.YELLOW,
'pending',
),
),
(
Stateful.QUEUED,
Stateful.YELLOW,
(
Stateful.CREATED,
Stateful.QUEUED,
Stateful.YELLOW,
'pending',
),
),
(
Stateful.STARTED,
Stateful.YELLOW,
(
Stateful.CREATED,
Stateful.QUEUED,
Stateful.STARTED,
Stateful.YELLOW,
'pending',
'running',
),
),
(
Stateful.PASSED,
Stateful.GREEN,
(
Stateful.CREATED,
Stateful.QUEUED,
Stateful.STARTED,
Stateful.PASSED,
Stateful.GREEN,
'finished',
'successful',
),
),
(
Stateful.FAILED,
Stateful.RED,
(
Stateful.CREATED,
Stateful.QUEUED,
Stateful.STARTED,
Stateful.FAILED,
Stateful.RED,
'finished',
'unsuccessful',
),
),
(
Stateful.ERRORED,
Stateful.RED,
(
Stateful.CREATED,
Stateful.QUEUED,
Stateful.STARTED,
Stateful.ERRORED,
Stateful.RED,
'finished',
'unsuccessful',
),
), (
Stateful.CANCELED,
Stateful.RED,
(
Stateful.CREATED,
Stateful.QUEUED,
Stateful.STARTED,
Stateful.CANCELED,
Stateful.RED,
'finished',
'unsuccessful',
),
), (
Stateful.READY,
Stateful.GREEN,
(
Stateful.CREATED,
Stateful.QUEUED,
Stateful.STARTED,
Stateful.READY,
Stateful.GREEN,
'finished',
),
),
],
)
def test_stateful(self, state, color, expected_true_properties):
stateful = Stateful(None)

assert hasattr(stateful, 'state') == False
assert hasattr(stateful, 'state') is False
with pytest.raises(AttributeError):
stateful.created

Expand All @@ -31,7 +114,7 @@ def test_stateful(self, state, color, expected_true_properties):

stateful.state = state
assert stateful.color == color

for prop in [
Stateful.CREATED,
Stateful.QUEUED,
Expand All @@ -49,5 +132,5 @@ def test_stateful(self, state, color, expected_true_properties):
'finished',
'successful',
'unsuccessful',
]:
]:
assert getattr(stateful, prop) == (prop in expected_true_properties)
57 changes: 20 additions & 37 deletions travispy/_tests/test_travispy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
import pytest



#===================================================================================================
# Test
#===================================================================================================
class Test:

def setup_method(self, method):
self._travis = TravisPy.github_auth(os.environ['TRAVISPY_GITHUB_ACCESS_TOKEN'])


@pytest.fixture
def python_version(self):
try:
Expand All @@ -26,7 +21,6 @@ def python_version(self):
sys.version_info[1],
)


@pytest.fixture
def repo_slug(self):
try:
Expand All @@ -39,11 +33,9 @@ def repo_slug(self):
sys.version_info[1],
)


def test_github_auth(self):
assert TravisPy.github_auth('invalid') is None


def test_accounts(self):
accounts = self._travis.accounts()
assert len(accounts) == 1
Expand All @@ -54,12 +46,11 @@ def test_accounts(self):
assert account.login == 'travispy'
assert account.type == 'user'
assert account.repos_count == 6
assert not hasattr(account, 'subscribed') # Only for Pro and Enterprise
assert not hasattr(account, 'subscribed') # Only for Pro and Enterprise

account = self._travis.account(123)
assert account is None


def test_branches(self, python_version, repo_slug):
pytest.raises(RuntimeError, self._travis.branches)

Expand All @@ -71,7 +62,7 @@ def test_branches(self, python_version, repo_slug):
assert branch.id == branches[-1].id
assert branch.repository_id == repo.id
assert branch.number == '1'
assert branch.pull_request == False
assert branch.pull_request is False
assert branch.config == {
'.result': 'configured',
'os': 'linux',
Expand All @@ -95,7 +86,7 @@ def test_branches(self, python_version, repo_slug):
assert repository == branch.repository

branch.repository_id = -1
assert branch.repository == None
assert branch.repository is None

jobs = branch.jobs
assert isinstance(jobs, list)
Expand All @@ -108,12 +99,10 @@ def test_branches(self, python_version, repo_slug):
assert branch.job_ids == job_ids
assert jobs == branch.jobs


def test_broadcasts(self):
broadcasts = self._travis.broadcasts()
assert len(broadcasts) == 0


def test_builds(self, python_version, repo_slug):
pytest.raises(RuntimeError, self._travis.builds)

Expand All @@ -126,9 +115,9 @@ def test_builds(self, python_version, repo_slug):
assert build.id == build_id
assert build.repository_id == repo.id
assert build.number == '2'
assert build.pull_request == False
assert build.pull_request_title == None
assert build.pull_request_number == None
assert build.pull_request is False
assert build.pull_request_title is None
assert build.pull_request_number is None
assert build.config == {
'.result': 'configured',
'os': 'linux',
Expand All @@ -143,19 +132,19 @@ def test_builds(self, python_version, repo_slug):
assert hasattr(build, 'duration')
assert hasattr(build, 'job_ids')
assert hasattr(build, 'commit')

assert build.commit_id == build.commit.id

assert build.restart() == True
assert build.cancel() == True
assert build.restart() is True
assert build.cancel() is True

repository = build.repository
assert isinstance(repository, Repo)
assert build.repository_id == repository.id
assert repository == build.repository

build.repository_id = -1
assert build.repository == None
assert build.repository is None

jobs = build.jobs
assert isinstance(jobs, list)
Expand All @@ -167,8 +156,7 @@ def test_builds(self, python_version, repo_slug):

assert build.job_ids == job_ids
assert jobs == build.jobs



def test_commit(self, repo_slug):
builds = self._travis.builds(slug=repo_slug)

Expand All @@ -189,12 +177,10 @@ def test_commit(self, repo_slug):
assert hasattr(commit, 'tag')
assert hasattr(commit, 'pull_request_number')


def test_hooks(self):
hooks = self._travis.hooks()
assert len(hooks) == 6


def test_jobs(self, python_version, repo_slug):
pytest.raises(RuntimeError, self._travis.jobs)

Expand Down Expand Up @@ -223,39 +209,38 @@ def test_jobs(self, python_version, repo_slug):
assert hasattr(job, 'started_at')
assert hasattr(job, 'finished_at')
assert job.queue == 'builds.linux'
assert job.allow_failure == False
assert job.allow_failure is False
assert job.annotation_ids == []
assert hasattr(job, 'commit')

assert job.commit_id == job.commit.id

assert job.restart() == True
assert job.cancel() == True
assert job.restart() is True
assert job.cancel() is True

build = job.build
assert isinstance(build, Build)
assert job.build_id == build.id
assert build == job.build

job.build_id = -1
assert job.build == None
assert job.build is None

repository = job.repository
assert isinstance(repository, Repo)
assert job.repository_id == repository.id
assert repository == job.repository

job.repository_id = -1
assert job.repository == None
assert job.repository is None

log = job.log
assert isinstance(log, Log)
assert job.log_id == log.id
assert log == job.log

job.log_id = -1
assert job.log == None

assert job.log is None

def test_log(self):
log = self._travis.log(15928905)
Expand All @@ -269,8 +254,7 @@ def test_log(self):
assert job == log.job

log.job_id = -1
assert log.job == None

assert log.job is None

def test_repos(self, repo_slug):
repos = self._travis.repos()
Expand Down Expand Up @@ -301,12 +285,11 @@ def test_repos(self, repo_slug):
assert last_build == repo.last_build

repo.last_build_id = -1
assert repo.last_build == None

assert repo.last_build is None

def test_user(self):
user = self._travis.user()
assert isinstance(user, User) == True
assert isinstance(user, User) is True

# Accessing values using __getitem__
assert user['login'] == 'travispy'
Expand Down
Loading

0 comments on commit 36b796c

Please sign in to comment.