def test_braces(self): self.expectThat( evaluate("pre ${BAR} post", {"BAR": "quux"}, self.absent), Equals(("pre quux post", {}))) self.expectThat( evaluate("pre ${BAR} mid ${BAR} post", {"BAR": "quux"}, self.absent), Equals(("pre quux mid quux post", {})))
def test_error_implicit(self): expr = "pre " + self.cons('bar', '?', '') + " post" self.expectThat(evaluate(expr, {'bar': 'quux'}, self.absent), Equals(('pre quux post', {}))) if self.colon: expected = raises(EvaluationError("Variable 'bar' null or unset.")) else: expected = Eval(Equals(('pre post', {}))) self.expectThat(lambda: evaluate(expr, {'bar': ''}, self.absent), expected) if self.absent is EMPTY: expected = raises(EvaluationError("Variable 'bar' null or unset.")) else: expected = Eval(Equals((expr, {}))) self.expectThat(lambda: evaluate(expr, {}, self.absent), expected)
def test_simple_absent(self): if self.absent is EMPTY: result = "" else: result = "$BAR" self.expectThat(evaluate("pre $BAR post", {}, self.absent), Equals(("pre " + result + " post", {})))
def test_simple_absent(self): if self.absent is EMPTY: result = "" else: result = "$BAR" self.expectThat( evaluate("pre $BAR post", {}, self.absent), Equals(("pre " + result + " post", {})))
def test_error_explicit(self): expr = "pre " + self.cons('bar', '?', '$foo') + " post" self.expectThat( evaluate(expr, {'bar': 'quux'}, self.absent), Equals(('pre quux post', {}))) if self.colon: expected = raises(EvaluationError("baz")) else: expected = Eval(Equals(('pre post', {}))) self.expectThat( lambda: evaluate(expr, {'bar': '', 'foo': 'baz'}, self.absent), expected) if self.absent is EMPTY: expected = raises(EvaluationError("baz")) else: expected = Eval(Equals((expr, {}))) self.expectThat( lambda: evaluate(expr, {'foo': 'baz'}, self.absent), expected)
def test_alternative_values(self): expr = "pre " + self.cons('bar', '+', '${foo}') +" post" self.expectThat( evaluate(expr, {'bar': 'quux', 'foo': 'baz'}, self.absent), Equals(('pre baz post', {}))) if self.colon: expected = Equals(('pre post', {})) else: expected = Equals(('pre baz post', {})) self.expectThat( evaluate(expr, {'bar': '', 'foo': 'baz'}, self.absent), expected) if self.absent is EMPTY: expected = Equals(('pre post', {})) else: expected = Equals((expr, {})) self.expectThat( evaluate(expr, {'foo': 'baz'}, self.absent), expected)
def test_error_explicit(self): expr = "pre " + self.cons('bar', '?', '$foo') + " post" self.expectThat(evaluate(expr, {'bar': 'quux'}, self.absent), Equals(('pre quux post', {}))) if self.colon: expected = raises(EvaluationError("baz")) else: expected = Eval(Equals(('pre post', {}))) self.expectThat( lambda: evaluate(expr, { 'bar': '', 'foo': 'baz' }, self.absent), expected) if self.absent is EMPTY: expected = raises(EvaluationError("baz")) else: expected = Eval(Equals((expr, {}))) self.expectThat(lambda: evaluate(expr, {'foo': 'baz'}, self.absent), expected)
def test_error_implicit(self): expr = "pre " + self.cons('bar', '?', '') + " post" self.expectThat( evaluate(expr, {'bar': 'quux'}, self.absent), Equals(('pre quux post', {}))) if self.colon: expected = raises(EvaluationError("Variable 'bar' null or unset.")) else: expected = Eval(Equals(('pre post', {}))) self.expectThat( lambda: evaluate(expr, {'bar': ''}, self.absent), expected) if self.absent is EMPTY: expected = raises(EvaluationError("Variable 'bar' null or unset.")) else: expected = Eval(Equals((expr, {}))) self.expectThat( lambda: evaluate(expr, {}, self.absent), expected)
def test_alternative_values(self): expr = "pre " + self.cons('bar', '+', '${foo}') + " post" self.expectThat( evaluate(expr, { 'bar': 'quux', 'foo': 'baz' }, self.absent), Equals(('pre baz post', {}))) if self.colon: expected = Equals(('pre post', {})) else: expected = Equals(('pre baz post', {})) self.expectThat(evaluate(expr, { 'bar': '', 'foo': 'baz' }, self.absent), expected) if self.absent is EMPTY: expected = Equals(('pre post', {})) else: expected = Equals((expr, {})) self.expectThat(evaluate(expr, {'foo': 'baz'}, self.absent), expected)
def test_assign_default_values(self): expr = "pre " + self.cons('bar', '=', '${foo}') +" post" self.expectThat( evaluate(expr, {'bar': 'quux', 'foo': 'baz'}, self.absent), Equals(('pre quux post', {'bar': 'quux'}))) if self.colon: expected = Equals(('pre baz post', {'bar': 'baz'})) else: expected = Equals(('pre post', {'bar': ''})) self.expectThat( evaluate(expr, {'bar': '', 'foo': 'baz'}, self.absent), expected) if self.absent is EMPTY: expected = Equals(('pre baz post', {'bar': 'baz'})) else: expected = Equals((expr, {})) self.expectThat( evaluate(expr, {'foo': 'baz'}, self.absent), expected) # Nested assignments bubble up. inner = self.cons('bar', '=', 'baz') outer = self.cons('foo', '-', inner) if self.absent is EMPTY: expected = Equals(('baz', {'bar': 'baz'})) else: expected = Equals((outer, {})) self.expectThat( evaluate(outer, {}, self.absent), expected) # Assignments are honoured inline first = self.cons('foo', '=', 'bar') second = self.cons('foo', '-', 'baz') expr = first + second if self.absent is EMPTY: expected = Equals(('barbar', {'foo': 'bar'})) else: expected = Equals((expr, {})) self.expectThat( evaluate(expr, {}, self.absent), expected)
def test_assign_default_values(self): expr = "pre " + self.cons('bar', '=', '${foo}') + " post" self.expectThat( evaluate(expr, { 'bar': 'quux', 'foo': 'baz' }, self.absent), Equals(('pre quux post', { 'bar': 'quux' }))) if self.colon: expected = Equals(('pre baz post', {'bar': 'baz'})) else: expected = Equals(('pre post', {'bar': ''})) self.expectThat(evaluate(expr, { 'bar': '', 'foo': 'baz' }, self.absent), expected) if self.absent is EMPTY: expected = Equals(('pre baz post', {'bar': 'baz'})) else: expected = Equals((expr, {})) self.expectThat(evaluate(expr, {'foo': 'baz'}, self.absent), expected) # Nested assignments bubble up. inner = self.cons('bar', '=', 'baz') outer = self.cons('foo', '-', inner) if self.absent is EMPTY: expected = Equals(('baz', {'bar': 'baz'})) else: expected = Equals((outer, {})) self.expectThat(evaluate(outer, {}, self.absent), expected) # Assignments are honoured inline first = self.cons('foo', '=', 'bar') second = self.cons('foo', '-', 'baz') expr = first + second if self.absent is EMPTY: expected = Equals(('barbar', {'foo': 'bar'})) else: expected = Equals((expr, {})) self.expectThat(evaluate(expr, {}, self.absent), expected)
def test_nothing(self): self.expectThat(evaluate("", {}, self.absent), Equals(("", {})))
def test_hypothesis(self, a_string): evaluate(a_string, {}, self.absent)
def test_simple(self): self.expectThat( evaluate("pre $BAR post", {"BAR": "quux"}, self.absent), Equals(("pre quux post", {})))
def test_nothing(self): self.expectThat( evaluate("", {}, self.absent), Equals(("", {})))