Exemple #1
0
 def test_should_return_line_by_line(self):
     """ Scenario: return lines """
     # Arrange
     lines = "line1\nline2\nline3"
     obj = LineSource(lines)
     # Act
     for i, line in enumerate(lines.split("\n")):
         result = obj.get_line()
         # Assert
         assert result == line
         assert obj.line_number == i + 1
Exemple #2
0
 def test_should_return_line_by_line(self):
     """ Scenario: return lines """
     # Arrange
     lines = 'line1\nline2\nline3'
     obj = LineSource(lines)
     # Act
     for i, line in enumerate(lines.split('\n')):
         result = obj.get_line()
         # Assert
         self.assertEqual(result, line)
         self.assertEqual(obj.line_number, i + 1)
Exemple #3
0
 def test_should_return_line_by_line(self):
     """ Scenario: return lines """
     # Arrange
     lines = "line1\nline2\nline3"
     obj = LineSource(lines)
     # Act
     for i, line in enumerate(lines.split("\n")):
         result = obj.get_line()
         # Assert
         assert result == line
         assert obj.line_number == i + 1
Exemple #4
0
 def test_should_return_line_by_line(self):
     """ Scenario: return lines """
     # Arrange
     lines = 'line1\nline2\nline3'
     obj = LineSource(lines)
     # Act
     for i, line in enumerate(lines.split('\n')):
         result = obj.get_line()
         # Assert
         self.assertEqual(result, line)
         self.assertEqual(obj.line_number, i + 1)
Exemple #5
0
 def test_should_return_true_if_docstring(self):
     """ Scenario: docstring """
     # Arrange
     lines = '"""\nline1\nline2\n"""'
     line_source = LineSource(lines)
     obj = DocStringParser(line_source)
     line = line_source.get_line()
     # Act
     result = obj.parse(line)
     # Assert
     self.assertTrue(result)
     self.assertEqual(obj.payload, 'line1\nline2')
Exemple #6
0
 def test_should_return_true_if_docstring(self):
     """ Scenario: docstring """
     # Arrange
     lines = '"""\nline1\nline2\n"""'
     line_source = LineSource(lines)
     obj = DocStringParser(line_source)
     line = line_source.get_line()
     # Act
     result = obj.parse(line)
     # Assert
     assert result
     assert obj.payload == "line1\nline2"
Exemple #7
0
 def test_should_return_true_if_indented_docstring(self):
     """ Scenario: indented docstring """
     # Arrange
     test_data = [
         ('   """\n   line1\n   line2\n   """', 'line1\nline2'),
         ('   """\n     line1\n   line2\n   """', '  line1\nline2'),
     ]
     for lines, expected in test_data:
         line_source = LineSource(lines)
         obj = DocStringParser(line_source)
         line = line_source.get_line()
         # Act
         result = obj.parse(line)
         # Assert
         self.assertTrue(result)
         self.assertEqual(obj.payload, expected)
Exemple #8
0
 def test_should_return_true_if_indented_docstring(self):
     """ Scenario: indented docstring """
     # Arrange
     test_data = [
         ('   """\n   line1\n   line2\n   """', "line1\nline2"),
         ('   """\n     line1\n   line2\n   """', "  line1\nline2"),
     ]
     for lines, expected in test_data:
         line_source = LineSource(lines)
         obj = DocStringParser(line_source)
         line = line_source.get_line()
         # Act
         result = obj.parse(line)
         # Assert
         assert result
         assert obj.payload == expected
Exemple #9
0
 def test_should_raise_stop_iteration_if_no_text(self):
     """ Scenario: no text """
     # Arrange
     obj = LineSource("")
     # Act
     # Assert
     self.assertRaises(StopIteration, obj.get_line)