test_prereqs.py 1.82 KB
Newer Older
1 2 3 4 5 6
import os
import unittest
from pavelib.prereqs import no_prereq_install


class TestPaverPrereqInstall(unittest.TestCase):
7 8 9 10
    """
    Test the status of the NO_PREREQ_INSTALL variable, its presence and how
    paver handles it.
    """
11
    def check_val(self, set_val, expected_val):
12 13 14 15 16 17 18
        """
        Verify that setting the variable to a certain value returns
        the expected boolean for it.

        As environment variables are only stored as strings, we have to cast
        whatever it's set at to a boolean that does not violate expectations.
        """
19 20 21 22 23 24 25 26 27 28 29 30 31 32
        _orig_environ = dict(os.environ)
        os.environ['NO_PREREQ_INSTALL'] = set_val
        self.assertEqual(
            no_prereq_install(),
            expected_val,
            'NO_PREREQ_INSTALL is set to {}, but we read it as {}'.format(
                set_val, expected_val),
        )

        # Reset Environment back to original state
        os.environ.clear()
        os.environ.update(_orig_environ)

    def test_no_prereq_install_true(self):
33 34 35
        """
        Ensure that 'true' will be True.
        """
36 37 38
        self.check_val('true', True)

    def test_no_prereq_install_false(self):
39 40 41
        """
        Ensure that 'false' will be False.
        """
42 43 44
        self.check_val('false', False)

    def test_no_prereq_install_True(self):
45 46 47
        """
        Ensure that 'True' will be True.
        """
48 49 50
        self.check_val('True', True)

    def test_no_prereq_install_False(self):
51 52 53
        """
        Ensure that 'False' will be False.
        """
54 55 56
        self.check_val('False', False)

    def test_no_prereq_install_0(self):
57 58 59
        """
        Ensure that '0' will be False.
        """
60 61 62
        self.check_val('0', False)

    def test_no_prereq_install_1(self):
63 64 65
        """
        Ensure that '1' will  be True.
        """
66
        self.check_val('1', True)