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_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"]]