Skip to content

Commit

Permalink
Merge pull request #71 from seddonym/maintests
Browse files Browse the repository at this point in the history
Refactor main functional tests
  • Loading branch information
seddonym authored Oct 15, 2018
2 parents 5d98c82 + 655f2fb commit f15742c
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions tests/functional/test_main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import sys

from layer_linter.cmdline import _main
from layer_linter.report import VERBOSITY_QUIET, VERBOSITY_NORMAL, VERBOSITY_HIGH
from layer_linter.cmdline import _main, EXIT_STATUS_SUCCESS, EXIT_STATUS_ERROR

import pytest

Expand All @@ -20,38 +19,40 @@
)
class TestMain:
def test_success(self, verbosity_count, is_quiet, should_always_fail):
path = os.path.join(assets_path, 'successpackage')
os.chdir(path)
sys.path.append(path)
package_name = 'successpackage'
self._chdir_and_add_to_system_path(package_name)

result = _main('successpackage', verbosity_count=verbosity_count, is_quiet=is_quiet)
result = _main(package_name, verbosity_count=verbosity_count, is_quiet=is_quiet)

if should_always_fail:
assert result == 1
assert result == EXIT_STATUS_ERROR
else:
assert result == 0
assert result == EXIT_STATUS_SUCCESS

def test_failure(self, verbosity_count, is_quiet, should_always_fail):
path = os.path.join(assets_path, 'failurepackage')
os.chdir(path)
sys.path.append(path)
package_name = 'failurepackage'
self._chdir_and_add_to_system_path(package_name)

result = _main('failurepackage', verbosity_count=verbosity_count, is_quiet=is_quiet)
assert result == 1
result = _main(package_name, verbosity_count=verbosity_count, is_quiet=is_quiet)

def test_specify_config_file(self, verbosity_count, is_quiet, should_always_fail):
path = os.path.join(assets_path, 'successpackage')
os.chdir(path)
sys.path.append(path)
assert result == EXIT_STATUS_ERROR

def test_specify_config_file(self, verbosity_count, is_quiet, should_always_fail):
package_name = 'successpackage'
self._chdir_and_add_to_system_path(package_name)

result = _main(
'successpackage',
package_name,
config_filename='layers_alternative.yml',
verbosity_count=verbosity_count,
is_quiet=is_quiet)

if should_always_fail:
assert result == 1
assert result == EXIT_STATUS_ERROR
else:
assert result == 0
assert result == EXIT_STATUS_SUCCESS

def _chdir_and_add_to_system_path(self, package_name):
path = os.path.join(assets_path, package_name)
sys.path.append(path)
os.chdir(path)

0 comments on commit f15742c

Please sign in to comment.