コード例 #1
0
 def test_str_nin_str_list(self):
     """Testing string not in string list."""
     assert_that(
         Condition.evaluate('"apple" not in ["apple", "banana", "kiwi"]'),
         equal_to(False))
     assert_that(Condition.evaluate('"apple" not in ["banana", "kiwi"]'),
                 equal_to(True))
コード例 #2
0
 def test_num_eq_num(self):
     """Comparing two strings; environment variable with a constant."""
     # compact version (env variables)
     assert_that(Condition.is_valid(
         '{{ variables.cpu_count }} == 1'), equal_to(True))
     # more spaces around are allowed (env variables)
     assert_that(Condition.is_valid(
         '  {{ variables.cpu_count }}  ==  1  '), equal_to(True))
コード例 #3
0
    def test_str_equal_str(self):
        """Testing two strings to be equal."""
        assert_that(Condition.evaluate('"hello" == "hello"'), equal_to(True))
        assert_that(Condition.evaluate('  "hello"  ==  "hello"  '),
                    equal_to(True))

        # not equal
        assert_that(Condition.evaluate('"hello" == "hallo"'), equal_to(False))
        # wrong format
        assert_that(Condition.evaluate('"hello" == hello'), equal_to(False))
コード例 #4
0
 def test_str_not_in_str_list(self):
     """Testing format for checking string to be in a list of strings."""
     # compact ver sion (env variables)
     assert_that(Condition.is_valid(
         '"{{ env.BRANCH_NAME }}" not in ["dev", "prod"]'), equal_to(True))
     # more spaces around are allowed (env variables)
     assert_that(Condition.is_valid(
         '  "{{ env.BRANCH_NAME }}"  not in  [ "dev",  "prod" ] '), equal_to(True))
     # compact version (task variables)
     assert_that(Condition.is_valid(
         '"{{ variables.cpu_count }}" not in ["1", "2"]'), equal_to(True))
コード例 #5
0
 def test_str_not_equal_str(self):
     """Comparing two strings to be not equal."""
     # compact version
     assert_that(Condition.is_valid(
         'not "{{ env.BRANCH_NAME }}" == "master"'), equal_to(True))
     # more spaces around are allowed
     assert_that(Condition.is_valid(
         ' not  "{{ env.BRANCH_NAME }}"  ==  "master" '), equal_to(True))
     # compact version
     assert_that(Condition.is_valid(
         'not "{{ variables.BRANCH_NAME }}" == "master"'), equal_to(True))
     # more spaces around are allowed
     assert_that(Condition.is_valid(
         ' not  "{{ variables.BRANCH_NAME }}"  ==  "master" '), equal_to(True))
コード例 #6
0
 def test_str_eq_str(self):
     """Comparing two strings; environment variable with a constant."""
     # compact version (env variables)
     assert_that(Condition.is_valid(
         '"{{ env.BRANCH_NAME }}" == "master"'), equal_to(True))
     # more spaces around are allowed (env variables)
     assert_that(Condition.is_valid(
         ' "{{ env.BRANCH_NAME }}"  ==  "master" '), equal_to(True))
     # compact version (tasks variables)
     assert_that(Condition.is_valid(
         '"{{ variables.cpu_count }}" == "6"'), equal_to(True))
     # more spaces around are allowed (tasks variables)
     assert_that(Condition.is_valid(
         ' "{{ variables.cpu_count }}"  ==  "6" '), equal_to(True))
コード例 #7
0
ファイル: tasks.py プロジェクト: jbenden/pipeline
    def can_process_shell(self, entry):
        """:return: True when shell can be executed."""
        count = 0
        condition = render(entry['when'],
                           variables=self.pipeline.variables,
                           model=self.pipeline.model,
                           env=self.get_merged_env(include_os=True))

        if Condition.evaluate("" if condition is None else condition):
            if len(self.pipeline.options.tags) == 0:
                return True

            if 'tags' in entry:
                for tag in self.pipeline.options.tags:
                    if tag in entry['tags']:
                        count += 1

        return count > 0
コード例 #8
0
 def test_invalid(self):
     """Testing invalid conditions."""
     # expect str == str - comparison but quotes are missing on the right side
     assert_that(Condition.is_valid(
         '"{{ env.BRANCH_NAME }}" == master'), equal_to(False))
     # expect str == str - comparison but quotes are missing on the left side
     assert_that(Condition.is_valid(
         '{{ env.BRANCH_NAME }} == "master"'), equal_to(False))
     # expect not str == str - comparison but quotes are missing on the right side
     assert_that(Condition.is_valid(
         'not "{{ env.BRANCH_NAME }}" == master'), equal_to(False))
     # currently "env" and "variables" are supported only
     assert_that(Condition.is_valid(
         '"{{ foo.BRANCH_NAME }}" == master'), equal_to(False))
     # strings search in a list of integer doesn't work
     assert_that(Condition.is_valid(
         '"{{ variables.cpu_count }}" in [1, 2]'), equal_to(False))
     # mixed types are now allowed
     assert_that(Condition.is_valid(
         '"{{ variables.cpu_count }}" in [1, "2"]'), equal_to(False))
コード例 #9
0
 def test_empty_condition(self):
     """An empty condition is valid."""
     assert_that(Condition.is_valid(''), equal_to(True))
コード例 #10
0
 def test_special(self):
     """Mainly covers special cases like nested lists."""
     assert_that(Condition.evaluate('2 in [2, [3, 4]]'), equal_to(False))
     assert_that(Condition.evaluate('2 3 4 5'), equal_to(False))
     assert_that(Condition.evaluate('2 in []'), equal_to(False))
コード例 #11
0
 def test_num_lte_num(self):
     """Testing integer less or equal than another integer."""
     assert_that(Condition.evaluate('2 <= 3'), equal_to(True))
     assert_that(Condition.evaluate('2 <= 2'), equal_to(True))
     assert_that(Condition.evaluate('2 <= 1'), equal_to(False))
コード例 #12
0
 def test_empty_condition(self):
     """An empty condition evaluates to True."""
     assert_that(Condition.evaluate(''), equal_to(True))
コード例 #13
0
 def test_num_gte_num(self):
     """Testing integer greater or equal than another integer."""
     assert_that(Condition.evaluate('3 >= 2'), equal_to(True))
     assert_that(Condition.evaluate('2 >= 2'), equal_to(True))
     assert_that(Condition.evaluate('1 >= 2'), equal_to(False))
コード例 #14
0
 def test_num_nin_num_list(self):
     """Testing integer not in integer list."""
     assert_that(Condition.evaluate('2 not in [2, 4, 6, 8]'),
                 equal_to(False))
     assert_that(Condition.evaluate('2 not in [3, 5, 7, 9]'),
                 equal_to(True))
コード例 #15
0
 def test_num_not_equal_num(self):
     """Testing two integer to be not equal."""
     assert_that(Condition.evaluate('not 2 == 2'), equal_to(False))
     assert_that(Condition.evaluate('not 2 == 3'), equal_to(True))