def test_add_period(self): assert Text().endswith(('.', '!', '?')) == False assert textutils.is_terminated(Text()) == False assert unicode(Text().add_period()) == '' text = Text("That's all, folks") assert unicode(text.add_period()) == "That's all, folks."
def test_add_period(self): assert Text().endswith(('.', '!', '?')) == False assert textutils.is_terminated(Text()) == False assert six.text_type(Text().add_period()) == '' text = Text("That's all, folks") assert six.text_type(text.add_period()) == "That's all, folks."
def test_add_period(self): assert not Protected().endswith(('.', '!', '?')) assert not textutils.is_terminated(Protected()) assert Protected().add_period().render_as('latex') == '{}' text = Protected("That's all, folks") assert text.add_period().render_as('latex') == "{That's all, folks.}"
def add_period(self, period='.'): """ Add a period to the end of text, if the last character is not ".", "!" or "?". >>> text = Text("That's all, folks") >>> print(six.text_type(text.add_period())) That's all, folks. >>> text = Text("That's all, folks!") >>> print(six.text_type(text.add_period())) That's all, folks! """ if self and not textutils.is_terminated(self): return self.append(period) else: return self
def add_period(self, period='.'): """ Add a period to the end of text, if the last character is not ".", "!" or "?". >>> text = Text("That's all, folks") >>> print unicode(text.add_period()) That's all, folks. >>> text = Text("That's all, folks!") >>> print unicode(text.add_period()) That's all, folks! """ if self and not textutils.is_terminated(self): return self.append(period) else: return self
def add_period(self, period='.'): """Add a period to the end of text, if necessary. >>> import pybtex.backends.html >>> html = pybtex.backends.html.Backend() >>> text = Text("That's all, folks") >>> print text.add_period().plaintext() That's all, folks. >>> text = Tag('emph', Text("That's all, folks")) >>> print text.add_period().render(html) <em>That's all, folks.</em> >>> print text.add_period().add_period().render(html) <em>That's all, folks.</em> >>> text = Text("That's all, ", Tag('emph', 'folks')) >>> print text.add_period().render(html) That's all, <em>folks</em>. >>> print text.add_period().add_period().render(html) That's all, <em>folks</em>. >>> text = Text("That's all, ", Tag('emph', 'folks.')) >>> print text.add_period().render(html) That's all, <em>folks.</em> >>> text = Text("That's all, ", Tag('emph', 'folks')) >>> print text.add_period('!').render(html) That's all, <em>folks</em>! >>> print text.add_period('!').add_period('.').render(html) That's all, <em>folks</em>! """ end = self.get_end() if end and not textutils.is_terminated(end): return self + period else: return self