Example #1
0
    def test_unclaimed_works(self):
        # a test manuel
        CLASS = re.compile(r'^\s+:class:',re.MULTILINE)
        class Block(object):
            def __init__(self,source): self.source = source
        def find_class_blocks(document):
            for region in document.find_regions(CLASS):
                region.parsed = Block(region.source)
                document.claim_region(region)
        def Test():
            return Manuel(parsers=[find_class_blocks])

        # now our test
        d = Document("""

.. topic:: something-else
 :class: not-a-file
  line 1
  line 2
  line 3

""")
        d.parse_with(Files('td')+Test())
        # now check FileBlock didn't mask class block
        compare([
                None,
                C(Block,
                  source=' :class:\n'),
                None,
                ],[r.parsed for r in d])
Example #2
0
    def test_file_followed_by_text(self):
        d = Document("""

.. topic:: file.txt
 :class: write-file

  .. code-block:: python

  print "hello"
  out = 'there'

  foo = 'bar'

This is just some normal text!
""")
        d.parse_with(Files('td'))
        compare([
                None,
                C(FileBlock,
                  path='file.txt',
                  content='.. code-block:: python\n\nprint "hello"'
                          '\nout = \'there\'\n\nfoo = \'bar\'\n',
                  action='write'),
                None,
                ],[r.parsed for r in d])
Example #3
0
    def test_multiple_files(self):
        d = Document("""

.. topic:: file.txt
 :class: write-file

  line 1

  line 2
  line 3

.. topic:: file2.txt
 :class: read-file


  line 4

  line 5
  line 6

""")
        d.parse_with(Files('td'))
        compare([
                None,
                C(FileBlock,
                  path='file.txt',
                  content="line 1\n\nline 2\nline 3\n",
                  action='write'),
                C(FileBlock,
                  path='file2.txt',
                  content='line 4\n\nline 5\nline 6\n',
                  action='read'),
                ],[r.parsed for r in d])
Example #4
0
    def test_file_followed_by_text(self):
        d = Document("""

.. topic:: file.txt
 :class: write-file

  .. code-block:: python

  print "hello"
  out = 'there'

  foo = 'bar'

This is just some normal text!
""")
        d.parse_with(Files('td'))
        compare([
                None,
                C(FileBlock,
                  path='file.txt',
                  content='.. code-block:: python\n\nprint "hello"'
                          '\nout = \'there\'\n\nfoo = \'bar\'\n',
                  action='write'),
                None,
                ],[r.parsed for r in d])
Example #5
0
    def test_multiple_files(self):
        d = Document("""

.. topic:: file.txt
 :class: write-file

  line 1

  line 2
  line 3

.. topic:: file2.txt
 :class: read-file


  line 4

  line 5
  line 6

""")
        d.parse_with(Files('td'))
        compare([
                None,
                C(FileBlock,
                  path='file.txt',
                  content="line 1\n\nline 2\nline 3\n",
                  action='write'),
                C(FileBlock,
                  path='file2.txt',
                  content='line 4\n\nline 5\nline 6\n',
                  action='read'),
                ],[r.parsed for r in d])
Example #6
0
    def test_unclaimed_works(self):
        # a test manuel
        CLASS = re.compile(r'^\s+:class:',re.MULTILINE)
        class Block(object):
            def __init__(self,source): self.source = source
        def find_class_blocks(document):
            for region in document.find_regions(CLASS):
                region.parsed = Block(region.source)
                document.claim_region(region)
        def Test():
            return Manuel(parsers=[find_class_blocks])

        # now our test
        d = Document("""

.. topic:: something-else
 :class: not-a-file
  line 1
  line 2
  line 3

""")
        d.parse_with(Files('td')+Test())
        # now check FileBlock didn't mask class block
        compare([
                None,
                C(Block,
                  source=' :class:\n'),
                None,
                ],[r.parsed for r in d])
Example #7
0
    def test_no_class(self):
        d = Document("""
.. topic:: file.txt

  print "hello"
  out = 'there'

""")
        d.parse_with(Files('td'))
        compare([r.parsed for r in d],[None])
Example #8
0
    def test_no_class(self):
        d = Document("""
.. topic:: file.txt

  print "hello"
  out = 'there'

""")
        d.parse_with(Files('td'))
        compare([r.parsed for r in d],[None])
Example #9
0
    def test_red_herring(self):
        d = Document("""
.. topic:: file.txt
 :class: not-a-file

  print "hello"
  out = 'there'

""")
        d.parse_with(Files('td'))
        compare([r.parsed for r in d],[None])
Example #10
0
    def test_red_herring(self):
        d = Document("""
.. topic:: file.txt
 :class: not-a-file

  print "hello"
  out = 'there'

""")
        d.parse_with(Files('td'))
        compare([r.parsed for r in d],[None])
Example #11
0
 def test_ignore_literal_blocking(self):
     d = Document(
         '\n.. topic:: file.txt\n :class: write-file\n\n  ::\n\n    line 1\n\n    line 2\n    line 3\n'
     )
     d.parse_with(Files('td'))
     compare([
         None,
         C(FileBlock,
           path='file.txt',
           content='line 1\n\nline 2\nline 3\n',
           action='write')
     ], [r.parsed for r in d])
Example #12
0
    def test_ignore_literal_blocking(self):
        d = Document("""
.. topic:: file.txt
 :class: write-file

  ::

    line 1

    line 2
    line 3
""")
        d.parse_with(Files('td'))
        compare([
                None,
                C(FileBlock,
                  path='file.txt',
                  content="line 1\n\nline 2\nline 3\n",
                  action='write'),
                ],[r.parsed for r in d])
Example #13
0
    def test_ignore_literal_blocking(self):
        d = Document("""
.. topic:: file.txt
 :class: write-file

  ::

    line 1

    line 2
    line 3
""")
        d.parse_with(Files('td'))
        compare([
                None,
                C(FileBlock,
                  path='file.txt',
                  content="line 1\n\nline 2\nline 3\n",
                  action='write'),
                ],[r.parsed for r in d])
Example #14
0
    def test_unclaimed_works(self):
        CLASS = re.compile('^\\s+:class:', re.MULTILINE)

        class Block(object):
            def __init__(self, source):
                self.source = source

        def find_class_blocks(document):
            for region in document.find_regions(CLASS):
                region.parsed = Block(region.source)
                document.claim_region(region)

        def Test():
            return Manuel(parsers=[find_class_blocks])

        d = Document(
            '\n\n.. topic:: something-else\n :class: not-a-file\n  line 1\n  line 2\n  line 3\n\n'
        )
        d.parse_with(Files('td') + Test())
        compare([None, C(Block, source=' :class:\n'), None],
                [r.parsed for r in d])
Example #15
0
 def test_no_class(self):
     d = Document(
         '\n.. topic:: file.txt\n\n  print "hello"\n  out = \'there\'\n\n')
     d.parse_with(Files('td'))
     compare([r.parsed for r in d], [None])