Beispiel #1
0
 def test_python_struct(self):
     assert evaluate_expression({'foo': 'bar'}, self.names) == (True, {
         'foo': 'bar'
     })
     assert evaluate_expression(['foo', 'bar'],
                                self.names) == (True, ['foo', 'bar'])
     assert evaluate_expression({}, self.names) == (False, {})
     assert evaluate_expression([], self.names) == (False, [])
Beispiel #2
0
 def test_in(self):
     assert evaluate_expression('$nonempty in "foobar"',
                                self.names) == (True, "foo")
     assert evaluate_expression('$nonempty2 in "foobar"',
                                self.names) == (True, "bar")
     assert evaluate_expression('$empty in "foobar"',
                                self.names) == (True, "")
     assert evaluate_expression('$nonempty in "FOOBAR"',
                                self.names) == (False, "foo")
Beispiel #3
0
 def test_shell(self):
     assert evaluate_expression("$(echo foobar)", self.names) == (True, "foobar")
     assert evaluate_expression("$(test -d /thoushaltnotexist)", self.names) == (False, '')
     assert evaluate_expression("$(false)", self.names) == (False, '')
     assert evaluate_expression("$(true)", self.names) == (True, '')
     # temporarily disabled
     #assert re.match(".*/foo/bar$",
     #               evaluate_expression("$(cd foo; cd bar; pwd; cd ../..)",
     #                                   self.names)[1])
     assert evaluate_expression('$(echo -e "foo\\nbar" | grep "bar")', self.names) == (True, "bar")
Beispiel #4
0
 def test_shell(self):
     assert evaluate_expression("$(echo foobar)",
                                self.names) == (True, "foobar")
     assert evaluate_expression("$(test -d /thoushaltnotexist)",
                                self.names) == (False, '')
     assert evaluate_expression("$(false)", self.names) == (False, '')
     assert evaluate_expression("$(true)", self.names) == (True, '')
     # temporarily disabled
     #assert re.match(".*/foo/bar$",
     #               evaluate_expression("$(cd foo; cd bar; pwd; cd ../..)",
     #                                   self.names)[1])
     assert evaluate_expression('$(echo -e "foo\\nbar" | grep "bar")',
                                self.names) == (True, "bar")
Beispiel #5
0
 def test_special_symbols_in_subshell_invocation(self):
     # before fixing this, special symbols inside shell invocation were
     # surrounded by spaces when parsed reconstructed by evaluate_expression
     # (e.g. backticks, colons, equal signs), e.g. the below command returned
     # (True, '` a : s = d `')
     assert evaluate_expression('$(echo \`a:s=d\`)',
                                {}) == (True, '`a:s=d`')
Beispiel #6
0
 def test_not(self):
     assert evaluate_expression("not $true", self.names) == (False, "")
     assert evaluate_expression("not $false", self.names) == (True, "")
     assert evaluate_expression("not $nonempty", self.names) == (False, "foo")
     assert evaluate_expression("not $empty", self.names) == (True, "")
Beispiel #7
0
 def test_env(self):
     res = evaluate_expression('$(echo $DEVASSISTANTTESTFOO)', {'DEVASSISTANTTESTFOO': 'foo'})
     assert res == (True, 'foo')
Beispiel #8
0
 def test_env(self):
     res = evaluate_expression('$(echo $DEVASSISTANTTESTFOO)',
                               {'DEVASSISTANTTESTFOO': 'foo'})
     assert res == (True, 'foo')
Beispiel #9
0
    def test_and(self):
        assert evaluate_expression("$true and $true", self.names) == (True, "")
        assert evaluate_expression("$true and $false", self.names) == (False, "")
        assert evaluate_expression("$false and $true", self.names) == (False, "")
        assert evaluate_expression("$false and $false", self.names) == (False, "")

        assert evaluate_expression("$nonempty and $nonempty2", self.names) == (True, "bar")
        assert evaluate_expression("$nonempty2 and $nonempty", self.names) == (True, "foo")

        assert evaluate_expression("$nonempty and $empty", self.names) == (False, "")
        assert evaluate_expression("$empty and $nonempty", self.names) == (False, "")

        assert evaluate_expression("$nonempty and $true", self.names) == (True, "")
        assert evaluate_expression("$true and $nonempty", self.names) == (True, "")

        assert evaluate_expression("$empty and $true", self.names) == (False, "")
        assert evaluate_expression("$true and $empty", self.names) == (False, "")

        assert evaluate_expression("$empty and $empty", self.names) == (False, "")

        assert evaluate_expression("$true and $nonempty and $nonempty2", self.names) == (True, "")
        assert evaluate_expression("$true and $nonempty and $empty", self.names) == (False, "")
Beispiel #10
0
 def test_special_symbols_in_subshell_invocation(self):
     # before fixing this, special symbols inside shell invocation were
     # surrounded by spaces when parsed reconstructed by evaluate_expression
     # (e.g. backticks, colons, equal signs), e.g. the below command returned
     # (True, '` a : s = d `')
     assert evaluate_expression('$(echo \`a:s=d\`)', {}) == (True, '`a:s=d`')
Beispiel #11
0
    def test_or(self):
        assert evaluate_expression("$true or $true", self.names) == (True, "")
        assert evaluate_expression("$true or $false", self.names) == (True, "")
        assert evaluate_expression("$false or $true", self.names) == (True, "")
        assert evaluate_expression("$false or $false",
                                   self.names) == (False, "")

        assert evaluate_expression("$nonempty or $nonempty2",
                                   self.names) == (True, "foo")
        assert evaluate_expression("$nonempty2 or $nonempty",
                                   self.names) == (True, "bar")

        assert evaluate_expression("$nonempty or $empty",
                                   self.names) == (True, "foo")
        assert evaluate_expression("$empty or $nonempty",
                                   self.names) == (True, "foo")

        assert evaluate_expression("$nonempty or $true",
                                   self.names) == (True, "foo")
        assert evaluate_expression("$true or $nonempty",
                                   self.names) == (True, "foo")

        assert evaluate_expression("$empty or $true", self.names) == (True, "")
        assert evaluate_expression("$true or $empty", self.names) == (True, "")

        assert evaluate_expression("$empty or $empty",
                                   self.names) == (False, "")

        assert evaluate_expression("$true or $nonempty or $nonempty2",
                                   self.names) == (True, "foo")
        assert evaluate_expression("$false or $nonempty or $empty",
                                   self.names) == (True, "foo")
Beispiel #12
0
 def test_variable(self):
     assert evaluate_expression("$true", self.names) == (True, "")
     assert evaluate_expression("$false", self.names) == (False, "")
     assert evaluate_expression("$nonempty", self.names) == (True, "foo")
     assert evaluate_expression("$empty", self.names) == (False, "")
Beispiel #13
0
 def test_complex_expression(self):
     assert evaluate_expression(
         'defined $empty or $empty and \
                                 $(echo -e foo bar "and also baz") or "else $nonempty"',
         self.names) == (True, 'else foo')
Beispiel #14
0
 def test_variable_substitution(self):
     assert evaluate_expression('"$nonempty"', self.names) == (True, "foo")
     assert evaluate_expression('"$empty"', self.names) == (False, "")
     assert evaluate_expression('"$true"', self.names) == (True, "True")
Beispiel #15
0
 def test_literal(self):
     assert evaluate_expression('"foobar"', self.names) == (True, "foobar")
     assert evaluate_expression("'foobar'", self.names) == (True, "foobar")
     assert evaluate_expression('""', self.names) == (False, "")
Beispiel #16
0
 def test_variable(self):
     assert evaluate_expression("$true", self.names) == (True, "")
     assert evaluate_expression("$false", self.names) == (False, "")
     assert evaluate_expression("$nonempty", self.names) == (True, "foo")
     assert evaluate_expression("$empty", self.names) == (False, "")
Beispiel #17
0
 def test_defined(self):
     assert evaluate_expression("defined $nonempty",
                                self.names) == (True, "foo")
     assert evaluate_expression("defined $empty", self.names) == (True, "")
     assert evaluate_expression("defined $notdefined",
                                self.names) == (False, "")
Beispiel #18
0
 def test_in(self):
     assert evaluate_expression('$nonempty in "foobar"', self.names) == (True, "foo")
     assert evaluate_expression('$nonempty2 in "foobar"', self.names) == (True, "bar")
     assert evaluate_expression('$empty in "foobar"', self.names) == (True, "")
     assert evaluate_expression('$nonempty in "FOOBAR"', self.names) == (False, "foo")
Beispiel #19
0
 def test_defined(self):
     assert evaluate_expression("defined $nonempty", self.names) == (True, "foo")
     assert evaluate_expression("defined $empty", self.names) == (True, "")
     assert evaluate_expression("defined $notdefined", self.names) == (False, "")
Beispiel #20
0
 def test_literal(self):
     assert evaluate_expression('"foobar"', self.names) == (True, "foobar")
     assert evaluate_expression("'foobar'", self.names) == (True, "foobar")
     assert evaluate_expression('""', self.names) == (False, "")
Beispiel #21
0
 def test_complex_expression(self):
     assert evaluate_expression('defined $empty or $empty and \
                                 $(echo -e foo bar "and also baz") or "else $nonempty"',
                                 self.names) == (True, 'else foo')
Beispiel #22
0
 def test_not(self):
     assert evaluate_expression("not $true", self.names) == (False, "")
     assert evaluate_expression("not $false", self.names) == (True, "")
     assert evaluate_expression("not $nonempty",
                                self.names) == (False, "foo")
     assert evaluate_expression("not $empty", self.names) == (True, "")
Beispiel #23
0
 def test_variable_substitution(self):
     assert evaluate_expression('"$nonempty"', self.names) == (True, "foo")
     assert evaluate_expression('"$empty"', self.names) == (False, "")
     assert evaluate_expression('"$true"', self.names) == (True, "True")
Beispiel #24
0
 def test_variables_in_subshell_invocation(self):
     assert evaluate_expression('$(echo $exists $doesnt)',
                                {'exists': 'X'}) == (True, 'X')
     assert evaluate_expression('$(echo ${exists} ${doesnt})',
                                {'exists': 'X'}) == (True, 'X')
Beispiel #25
0
 def test_python_struct(self):
     assert evaluate_expression({'foo': 'bar'}, self.names) == (True, {'foo': 'bar'})
     assert evaluate_expression(['foo', 'bar'], self.names) == (True, ['foo', 'bar'])
     assert evaluate_expression({}, self.names) == (False, {})
     assert evaluate_expression([], self.names) == (False, [])
Beispiel #26
0
    def test_and(self):
        assert evaluate_expression("$true and $true", self.names) == (True, "")
        assert evaluate_expression("$true and $false",
                                   self.names) == (False, "")
        assert evaluate_expression("$false and $true",
                                   self.names) == (False, "")
        assert evaluate_expression("$false and $false",
                                   self.names) == (False, "")

        assert evaluate_expression("$nonempty and $nonempty2",
                                   self.names) == (True, "bar")
        assert evaluate_expression("$nonempty2 and $nonempty",
                                   self.names) == (True, "foo")

        assert evaluate_expression("$nonempty and $empty",
                                   self.names) == (False, "")
        assert evaluate_expression("$empty and $nonempty",
                                   self.names) == (False, "")

        assert evaluate_expression("$nonempty and $true",
                                   self.names) == (True, "")
        assert evaluate_expression("$true and $nonempty",
                                   self.names) == (True, "")

        assert evaluate_expression("$empty and $true",
                                   self.names) == (False, "")
        assert evaluate_expression("$true and $empty",
                                   self.names) == (False, "")

        assert evaluate_expression("$empty and $empty",
                                   self.names) == (False, "")

        assert evaluate_expression("$true and $nonempty and $nonempty2",
                                   self.names) == (True, "")
        assert evaluate_expression("$true and $nonempty and $empty",
                                   self.names) == (False, "")
Beispiel #27
0
 def test_variables_in_subshell_invocation(self):
     assert evaluate_expression('$(echo $exists $doesnt)', {'exists': 'X'}) == (True, 'X')
     assert evaluate_expression('$(echo ${exists} ${doesnt})', {'exists': 'X'}) == (True, 'X')
Beispiel #28
0
 def test_workaround_for_more_special_symbols(self):
     # see https://github.com/devassistant/devassistant/issues/271
     assert evaluate_expression('$("echo +-")', {}) == (True, '+-')
     assert evaluate_expression("$('echo +-')", {}) == (True, '+-')
Beispiel #29
0
    def test_or(self):
        assert evaluate_expression("$true or $true", self.names) == (True, "")
        assert evaluate_expression("$true or $false", self.names) == (True, "")
        assert evaluate_expression("$false or $true", self.names) == (True, "")
        assert evaluate_expression("$false or $false", self.names) == (False, "")

        assert evaluate_expression("$nonempty or $nonempty2", self.names) == (True, "foo")
        assert evaluate_expression("$nonempty2 or $nonempty", self.names) == (True, "bar")

        assert evaluate_expression("$nonempty or $empty", self.names) == (True, "foo")
        assert evaluate_expression("$empty or $nonempty", self.names) == (True, "foo")

        assert evaluate_expression("$nonempty or $true", self.names) == (True, "foo")
        assert evaluate_expression("$true or $nonempty", self.names) == (True, "foo")

        assert evaluate_expression("$empty or $true", self.names) == (True, "")
        assert evaluate_expression("$true or $empty", self.names) == (True, "")

        assert evaluate_expression("$empty or $empty", self.names) == (False, "")

        assert evaluate_expression("$true or $nonempty or $nonempty2", self.names) == (True, "foo")
        assert evaluate_expression("$false or $nonempty or $empty", self.names) == (True, "foo")
Beispiel #30
0
 def test_workaround_for_more_special_symbols(self):
     # see https://github.com/devassistant/devassistant/issues/271
     assert evaluate_expression('$("echo +-")', {}) == (True, '+-')
     assert evaluate_expression("$('echo +-')", {}) == (True, '+-')