def test_accepts_only_with_message(self): items = ["a", "b"] items_failing = ["a", "b", 1] message = "There should be only strings." Guard.accepts_only(items, [str], message) self.assertRaisesEx(ValueError, Guard.accepts_only, items_failing, [str], message, exc_pattern=re.compile(message))
def test_accepts_only_without_message(self): items = ["a", "b"] items_failing = ["a", "b", 1] message = u"All arguments in the given collection should be of type\(s\) \[str\] and at least one of them isn't." Guard.accepts_only(items, [str]) self.assertRaisesEx(ValueError, Guard.accepts_only, items_failing, [str], exc_pattern=re.compile(message))
def select(self, *cols): empty_message = "Selecting with no fields is not valid. " \ + "When using From(provider).select method, " \ + "please provide a list of expressions or strings as fields." Guard.against_empty(cols, empty_message) for col in cols: Guard.against_empty(col, empty_message) Guard.accepts_only(cols, [str, Expression], "Selecting with invalid type. " \ + "When using From(provider).select method, " \ + "please provide a list of expressions or strings as fields.") return self.provider.parse(self, action=Actions.Select, cols=cols)