def test_settings(self): """ Expectation with settings. """ exps = list( get_expectations( dedent(''' Title 1 ======= .. plugin-settings:: a = 1 b = 2 .. expectation:: :from: 01 :to: 02 Output'''))) self.assertEqual(1, len(exps)) self.assertEqual(Expectation((1, 2), { 'a': '1', 'b': '2' }, u'Output'), exps[0])
def test_settings_at_distance(self): """ If settings are separated by other non structural nodes. """ exps = list( get_expectations( dedent(''' Title 1 ======= .. plugin-settings:: a = 1 b = 2 Paragraph 1 Paragraph 2 .. expectation:: :from: 01 :to: 02 Output'''))) self.assertEqual(Expectation((1, 2), { 'a': '1', 'b': '2' }, u'Output'), exps[0])
def test_multiple_expectations(self): """ More than one expectation. """ exps = list(get_expectations(dedent(''' Title 1 ======= .. plugin-settings:: a = 1 .. expectation:: :from: 01 :to: 02 Output 1 Title 2 ======= .. plugin-settings:: a = 1 .. expectation:: :from: 02 :to: 03 Output 2'''))) self.assertEqual([ Expectation((1, 2), {'a': '1'}, u'Output 1'), Expectation((2, 3), {'a': '1'}, u'Output 2')], exps)
def test_settings_at_distance(self): """ If settings are separated by other non structural nodes. """ exps = list(get_expectations(dedent(''' Title 1 ======= .. plugin-settings:: a = 1 b = 2 Paragraph 1 Paragraph 2 .. expectation:: :from: 01 :to: 02 Output'''))) self.assertEqual( Expectation((1, 2), {'a': '1', 'b': '2'}, u'Output'), exps[0])
def test_missing_arguments(self): """ Expectation directives have two options. """ with self.assertRaises(ExpectationParsingError) as ec: list(get_expectations(dedent(''' .. expectation:: Line 1 '''))) self.assertIn( 'expectation directive requires `to` and `from` arguments', str(ec.exception))
def test_missing_arguments(self): """ Expectation directives have two options. """ with self.assertRaises(ExpectationParsingError) as ec: list( get_expectations( dedent(''' .. expectation:: Line 1 '''))) self.assertIn( 'expectation directive requires `to` and `from` arguments', str(ec.exception))
def test_non_integer_arguments(self): """ Expectation directives have two required arguments. """ with self.assertRaises(ExpectationParsingError) as ec: list( get_expectations( dedent(''' .. expectation:: :to: a :from: b Line 1 '''))) self.assertIn('Error in "expectation" directive', str(ec.exception)) # And it's warning us about not being able to convert to an integer self.assertIn('invalid literal for int()', str(ec.exception))
def test_expectation_no_settings(self): """ Expectation with no accompanying settings. """ exps = list(get_expectations(dedent(''' Title 1 ======= .. expectation:: :from: 01 :to: 02 Output'''))) self.assertEqual(1, len(exps)) self.assertEqual( Expectation(range=(1, 2), settings=None, output=u'Output'), exps[0])
def test_expectation_no_settings(self): """ Expectation with no accompanying settings. """ exps = list( get_expectations( dedent(''' Title 1 ======= .. expectation:: :from: 01 :to: 02 Output'''))) self.assertEqual(1, len(exps)) self.assertEqual( Expectation(range=(1, 2), settings=None, output=u'Output'), exps[0])
def test_non_integer_arguments(self): """ Expectation directives have two required arguments. """ with self.assertRaises(ExpectationParsingError) as ec: list(get_expectations(dedent(''' .. expectation:: :to: a :from: b Line 1 '''))) self.assertIn( 'Error in "expectation" directive', str(ec.exception)) # And it's warning us about not being able to convert to an integer self.assertIn( 'invalid literal for int()', str(ec.exception))
def test_settings(self): """ Expectation with settings. """ exps = list(get_expectations(dedent(''' Title 1 ======= .. plugin-settings:: a = 1 b = 2 .. expectation:: :from: 01 :to: 02 Output'''))) self.assertEqual(1, len(exps)) self.assertEqual( Expectation((1, 2), {'a': '1', 'b': '2'}, u'Output'), exps[0])
def test_multiple_expectations(self): """ More than one expectation. """ exps = list( get_expectations( dedent(''' Title 1 ======= .. plugin-settings:: a = 1 .. expectation:: :from: 01 :to: 02 Output 1 Title 2 ======= .. plugin-settings:: a = 1 .. expectation:: :from: 02 :to: 03 Output 2'''))) self.assertEqual([ Expectation((1, 2), {'a': '1'}, u'Output 1'), Expectation((2, 3), {'a': '1'}, u'Output 2') ], exps)