def test_commands_are_correct(self): options = Mock() options.get_global_opts.return_value = [] case1 = Mock(role=Mock(directory="/foo"), scenario=Mock(name="s1")) case2 = Mock(role=Mock(directory="/bar"), scenario=Mock(name="s1")) case3 = Mock(role=Mock(directory="/bar"), scenario=Mock(name="s2")) bummer = ToxLintCase([]) tc = ToxLintCase([case1, case2, case3, bummer]) cmds = tc.get_commands(options) expected = [ [ "bash", "-c", "cd {} && molecule lint -s {}".format(case1.role.directory, case1.scenario.name) ], [ "bash", "-c", "cd {} && molecule lint -s {}".format(case2.role.directory, case2.scenario.name) ], [ "bash", "-c", "cd {} && molecule lint -s {}".format(case3.role.directory, case3.scenario.name) ], ] self.assertEqual(expected, cmds)
def test_names_are_correct(mocker): tc = ToxLintCase([]) deps = set(["ansible-lint", "flake8", "yamllint", "ansible"]) mocker.patch( "tox_ansible.tox_lint_case.Tox.toxinidir", new_callable=mocker.PropertyMock, return_value="/home", ) assert tc.get_name() == "lint_all" assert tc.get_working_dir() == "/home" assert tc.get_dependencies() == deps
def test_commands_are_correct(mocker): options = Mock() options.get_global_opts.return_value = [] options.ansible_lint = None options.yamllint = None case1 = Mock(scenario=Scenario("molecule/s1")) case2 = Mock(scenario=Scenario("something/roles/r1/molecule/s2")) case3 = Mock(scenario=Scenario("roles/r2/molecule/s3")) bummer = ToxLintCase([]) mocker.patch("tox_ansible.tox_lint_case.Tox.toxinidir", "") tc = ToxLintCase([case1, case2, case3, bummer]) cmds = tc.get_commands(options) expected = [["ansible-lint", "-R"], ["yamllint", "."], ["flake8", "."]] assert expected == cmds
def test_lint_options_correct(mocker): options = mocker.Mock() options.get_global_opts.return_value = [] options.ansible_lint = "some/path" options.yamllint = "some/yaml.path" bummer = ToxLintCase([]) mocker.patch("tox_ansible.tox_lint_case.Tox.toxinidir", "") tc = ToxLintCase([bummer]) cmds = tc.get_commands(options) expected = [ ["ansible-lint", "-R", "-c", "some/path"], ["yamllint", "-c", "some/yaml.path", "."], ["flake8", "."], ] assert expected == cmds
def test_commands_are_correct(mocker, no_precommit, precommit): options = Mock() options.global_opts = [] options.ansible_lint = None options.yamllint = None case1 = Mock(scenario=Scenario("molecule/s1")) case2 = Mock(scenario=Scenario("something/roles/r1/molecule/s2")) case3 = Mock(scenario=Scenario("roles/r2/molecule/s3")) bummer = ToxLintCase([]) mocker.patch( "tox_ansible.tox_lint_case.Tox.toxinidir", new_callable=mocker.PropertyMock, return_value=no_precommit, ) tc = ToxLintCase([case1, case2, case3, bummer]) cmds = tc.get_commands(options) expected = [["ansible-lint", "-R"], ["flake8", "."]] assert expected == cmds mocker.patch( "tox_ansible.tox_lint_case.Tox.toxinidir", new_callable=mocker.PropertyMock, return_value=precommit, ) assert tc.get_commands(options) == [["pre-commit", "run", "--all"]]
def test_pre_commit_is_correct(mocker, precommit, no_precommit): tc = ToxLintCase([]) deps = set(["pre-commit"]) mocker.patch( "tox_ansible.tox_lint_case.Tox.toxinidir", new_callable=mocker.PropertyMock, return_value=precommit, ) assert tc.is_precommit assert tc.dependencies == deps mocker.patch( "tox_ansible.tox_lint_case.Tox.toxinidir", new_callable=mocker.PropertyMock, return_value=no_precommit, ) assert not tc.is_precommit
def test_names_are_correct(self): tc = ToxLintCase([]) deps = set(["molecule", "ansible-lint", "flake8", "yamllint"]) self.assertEqual(tc.get_name(), "lint_all") self.assertEqual(tc.get_working_dir(), "{toxinidir}") self.assertEqual(tc.get_dependencies(), deps)
def test_expand_ansible(self): tc = ToxLintCase([]) out = tc.expand_ansible("2.10") self.assertEqual(out.get_name(), "ansible210-lint_all")
def test_expand_python(self): tc = ToxLintCase([]) out = tc.expand_python("2.7") self.assertEqual(out.get_name(), "py27-lint_all")
def test_matrix_leaves_out_bare_lint_all(self): matrix = Matrix() matrix.add_axis(PythonAxis(["2.7", "3.8"])) cases = [ToxLintCase([])] expanded = matrix.expand(cases) self.assertEqual(2, len(expanded))
def test_empty_matrix(self): cases = [ToxTestCase(mock.Mock(), mock.Mock()), ToxLintCase([])] original = copy(cases) matrix = Matrix() after_cases = matrix.expand(cases) self.assertEqual(after_cases, original)
def test_expand_ansible(): tc = ToxLintCase([]) out = tc.expand_ansible("2.10") assert out.get_name() == "ansible210-lint_all"
def test_expand_python(): tc = ToxLintCase([]) out = tc.expand_python("2.7") assert out.get_name() == "py27-lint_all"