# -*- coding: utf-8 -*-

from __future__ import absolute_import

import os

import pytest
from tests.support.case import ShellCase, SPMCase
from tests.support.helpers import slowTest


@pytest.mark.windows_whitelisted
class SPMTest(ShellCase, SPMCase):
    """
    Test spm script
    """

    @slowTest
    def test_spm_help(self):
        """
        test --help argument for spm
        """
        expected_args = ["--version", "--assume-yes", "--help"]
        output = self.run_spm("--help")
        for arg in expected_args:
            self.assertIn(arg, "".join(output))

    @slowTest
    def test_spm_bad_arg(self):
        """
        test correct output when bad argument passed
        """
        expected_args = ["--version", "--assume-yes", "--help"]
        output = self.run_spm("doesnotexist")
        for arg in expected_args:
            self.assertIn(arg, "".join(output))

    @slowTest
    def test_spm_assume_yes(self):
        """
        test spm install with -y arg
        """
        config = self._spm_config(assume_yes=False)
        self._spm_build_files(config)

        spm_file = os.path.join(config["spm_build_dir"], "apache-201506-2.spm")

        build = self.run_spm("build {0} -c {1}".format(self.formula_dir, self._tmp_spm))

        install = self.run_spm("install {0} -c {1} -y".format(spm_file, self._tmp_spm))

        self.assertTrue(
            os.path.exists(os.path.join(config["formula_path"], "apache", "apache.sls"))
        )

    @slowTest
    def test_spm_force(self):
        """
        test spm install with -f arg
        """
        config = self._spm_config(assume_yes=False)
        self._spm_build_files(config)

        spm_file = os.path.join(config["spm_build_dir"], "apache-201506-2.spm")

        build = self.run_spm("build {0} -c {1}".format(self.formula_dir, self._tmp_spm))

        install = self.run_spm("install {0} -c {1} -y".format(spm_file, self._tmp_spm))

        self.assertTrue(
            os.path.exists(os.path.join(config["formula_path"], "apache", "apache.sls"))
        )

        # check if it forces the install after its already been installed it
        install = self.run_spm(
            "install {0} -c {1} -y -f".format(spm_file, self._tmp_spm)
        )

        self.assertEqual(["... installing apache"], install)

@@ -1,69 +1,4 @@
-# -*- coding: utf-8 -*-%0A%0Afrom __future__ import absolute_import%0A%0A
 impo
@@ -1140,32 +1140,30 @@
 spm(%22build %7B
-0
 %7D -c %7B
-1
 %7D%22.format(se
@@ -1232,32 +1232,30 @@
 m(%22install %7B
-0
 %7D -c %7B
-1
 %7D -y%22.format
@@ -1721,24 +1721,22 @@
 %22build %7B
-0
 %7D -c %7B
-1
 %7D%22.forma
@@ -1809,32 +1809,30 @@
 m(%22install %7B
-0
 %7D -c %7B
-1
 %7D -y%22.format
@@ -2092,29 +2092,16 @@
 run_spm(
-%0A            
 %22install
@@ -2106,16 +2106,14 @@
 ll %7B
-0
 %7D -c %7B
-1
 %7D -y
@@ -2148,25 +2148,16 @@
 tmp_spm)
-%0A        
 )%0A%0A     

Drop Py2 and six on tests/integration/shell/test_spm.py