Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Rename TestContext to BuildContext and TestRunner to BuildRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Sep 29, 2016
1 parent 7e67a15 commit c3fe6c7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
16 changes: 8 additions & 8 deletions badwolf/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
logger = logging.getLogger(__name__)


class TestContext(object):
"""Test context"""
class BuildContext(object):
"""Badwolf build context"""
def __init__(self, repository, actor, type, message, source,
target=None, rebuild=False, pr_id=None, cleanup_lint=False,
nocache=False, clone_depth=50):
Expand All @@ -49,8 +49,8 @@ def __init__(self, repository, actor, type, message, source,
self.source['repository'] = {'full_name': repository}


class TestRunner(object):
"""Badwolf test runner"""
class BuildRunner(object):
"""Badwolf build runner"""

def __init__(self, context, docker_version='auto'):
self.context = context
Expand Down Expand Up @@ -193,14 +193,15 @@ def clone_repository(self):

def validate_settings(self):
conf_file = os.path.join(self.clone_path, current_app.config['BADWOLF_PROJECT_CONF'])
if not os.path.exists(conf_file):
try:
self.spec = spec = Specification.parse_file(conf_file)
except OSError:
logger.warning(
'No project configuration file found for repo: %s',
self.repo_full_name
)
return False

self.spec = spec = Specification.parse_file(conf_file)
if self.context.type == 'commit' and spec.branch and self.branch not in spec.branch:
logger.info(
'Ignore tests since branch %s test is not enabled. Allowed branches: %s',
Expand Down Expand Up @@ -335,8 +336,7 @@ def send_notifications(self, context):

# Save log html
log_dir = os.path.join(current_app.config['BADWOLF_LOG_DIR'], self.commit_hash)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
os.makedirs(log_dir, exist_ok=True)
log_file = os.path.join(log_dir, 'build.html')
with open(log_file, 'wb') as f:
f.write(to_binary(html))
Expand Down
4 changes: 2 additions & 2 deletions badwolf/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def delay(*args, **kwargs):

@async_task
def run_test(context):
from badwolf.runner import TestRunner
from badwolf.runner import BuildRunner

runner = TestRunner(context)
runner = BuildRunner(context)
runner.run()
10 changes: 5 additions & 5 deletions badwolf/webhook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from flask import Blueprint, request, current_app, url_for

from badwolf.runner import TestContext
from badwolf.runner import BuildContext
from badwolf.tasks import run_test
from badwolf.extensions import bitbucket
from badwolf.bitbucket import BitbucketAPIError, PullRequest, BuildStatus
Expand Down Expand Up @@ -77,7 +77,7 @@ def handle_repo_push(payload):

repo_name = repo['full_name']

context = TestContext(
context = BuildContext(
repo_name,
payload['actor'],
'commit',
Expand Down Expand Up @@ -119,7 +119,7 @@ def handle_pull_request(payload):
source = pr['source']
target = pr['destination']

context = TestContext(
context = BuildContext(
repo['full_name'],
payload['actor'],
'pullrequest',
Expand Down Expand Up @@ -197,7 +197,7 @@ def handle_repo_commit_comment(payload):
repo = payload['repository']
repo_name = repo['full_name']

context = TestContext(
context = BuildContext(
repo_name,
payload['actor'],
'commit',
Expand Down Expand Up @@ -236,7 +236,7 @@ def handle_pull_request_comment(payload):
source = pr['source']
target = pr['destination']

context = TestContext(
context = BuildContext(
repo['full_name'],
payload['actor'],
'pullrequest',
Expand Down
40 changes: 20 additions & 20 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from unidiff import PatchSet

from badwolf.spec import Specification
from badwolf.runner import TestContext
from badwolf.runner import BuildContext
from badwolf.lint.processor import LintProcessor
from badwolf.utils import ObjectDict

Expand All @@ -19,7 +19,7 @@


def test_no_linters_ignore(app):
context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand All @@ -36,7 +36,7 @@ def test_no_linters_ignore(app):


def test_load_changes_failed_ignore(app, caplog):
context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_no_changed_files_ignore(app, caplog):
-This file will be removed.
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_flake8_lint_a_py(app, caplog):
+ return a+ b
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_jscs_lint_a_js(app, caplog):
+if(foo === 'bar') {}
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_eslint_lint_a_js(app, caplog):
+console.log("bar")
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_pep8_lint_a_py(app, caplog):
+ return a+ b
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -293,7 +293,7 @@ def test_jsonlint_a_json(app, caplog):
+{"a": 1,}
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_shellcheck_a_sh(app, caplog):
+$foo=42
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -374,7 +374,7 @@ def test_csslint_a_css(app, caplog):
+.a {}
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -419,7 +419,7 @@ def test_flake8_lint_a_py_with_custom_glob_pattern(app, caplog):
+ return a+ b
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -464,7 +464,7 @@ def test_flake8_lint_a_py_with_custom_regex_pattern(app, caplog):
+ return a+ b
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -506,7 +506,7 @@ def test_yamllint_a_yml(app, caplog):
+a: 2
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -551,7 +551,7 @@ def test_flake8_lint_a_py_with_multi_custom_glob_patterns(app, caplog):
+ return a+ b
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -594,7 +594,7 @@ def test_bandit_lint_a_py(app, caplog):
+ pass
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -636,7 +636,7 @@ def test_rstlint_a_rst(app, caplog):
+====
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -681,7 +681,7 @@ def test_pylint_lint_a_py(app, caplog):
+ return a+ b
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -722,7 +722,7 @@ def test_sasslint_lint_a_scss(app, caplog):
+}
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down Expand Up @@ -761,7 +761,7 @@ def test_stylelint_lint_a_scss(app, caplog):
+a[id="foo"] { content: "x"; }
"""

context = TestContext(
context = BuildContext(
'deepanalyzer/badwolf',
None,
'pullrequest',
Expand Down
6 changes: 3 additions & 3 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import git
import pytest

from badwolf.runner import TestContext, TestRunner
from badwolf.runner import BuildContext, BuildRunner
from badwolf.bitbucket import PullRequest, Changesets


@pytest.fixture(scope='function')
def push_context():
return TestContext(
return BuildContext(
'deepanalyzer/badwolf',
{},
'commit',
Expand All @@ -31,7 +31,7 @@ def push_context():

@pytest.fixture(scope='function')
def push_runner(push_context):
runner = TestRunner(push_context, docker_version=None)
runner = BuildRunner(push_context, docker_version=None)
runner.clone_path = os.path.join(
tempfile.gettempdir(),
'badwolf',
Expand Down

0 comments on commit c3fe6c7

Please sign in to comment.