def test_is_sentence(self): from certbot_nginx._internal.parser_obj import Sentence self.assertFalse(Sentence.should_parse([])) self.assertTrue(Sentence.should_parse([''])) self.assertTrue(Sentence.should_parse(['word'])) self.assertTrue(Sentence.should_parse(['two', 'words'])) self.assertFalse(Sentence.should_parse([[]])) self.assertFalse(Sentence.should_parse(['word', []]))
def setUp(self): from certbot_nginx._internal.parser_obj import Sentence self.sentence = Sentence(None)
class SentenceTest(unittest.TestCase): def setUp(self): from certbot_nginx._internal.parser_obj import Sentence self.sentence = Sentence(None) def test_parse_bad_sentence_raises_error(self): from certbot import errors self.assertRaises(errors.MisconfigurationError, self.sentence.parse, 'lol') self.assertRaises(errors.MisconfigurationError, self.sentence.parse, [[]]) self.assertRaises(errors.MisconfigurationError, self.sentence.parse, [5]) def test_parse_sentence_words_hides_spaces(self): og_sentence = [ '\r\n', 'hello', ' ', ' ', '\t\n ', 'lol', ' ', 'spaces' ] self.sentence.parse(og_sentence) self.assertEqual(self.sentence.words, ['hello', 'lol', 'spaces']) self.assertEqual(self.sentence.dump(), ['hello', 'lol', 'spaces']) self.assertEqual(self.sentence.dump(True), og_sentence) def test_parse_sentence_with_add_spaces(self): self.sentence.parse(['hi', 'there'], add_spaces=True) self.assertEqual(self.sentence.dump(True), ['hi', ' ', 'there']) self.sentence.parse(['one', ' ', 'space', 'none'], add_spaces=True) self.assertEqual(self.sentence.dump(True), ['one', ' ', 'space', ' ', 'none']) def test_iterate(self): expected = [['1', '2', '3']] self.sentence.parse(['1', ' ', '2', ' ', '3']) for i, sentence in enumerate(self.sentence.iterate()): self.assertEqual(sentence.dump(), expected[i]) def test_set_tabs(self): self.sentence.parse(['tabs', 'pls'], add_spaces=True) self.sentence.set_tabs() self.assertEqual(self.sentence.dump(True)[0], '\n ') self.sentence.parse(['tabs', 'pls'], add_spaces=True) def test_get_tabs(self): self.sentence.parse(['no', 'tabs']) self.assertEqual(self.sentence.get_tabs(), '') self.sentence.parse(['\n \n ', 'tabs']) self.assertEqual(self.sentence.get_tabs(), ' ') self.sentence.parse(['\n\t ', 'tabs']) self.assertEqual(self.sentence.get_tabs(), '\t ') self.sentence.parse(['\n\t \n', 'tabs']) self.assertEqual(self.sentence.get_tabs(), '')