Ejemplo n.º 1
0
 def test_lines_text_item(self):
     """Verify text can be published from an item."""
     with patch.object(self.item5, 'find_ref',
                       Mock(return_value=('path/to/mock/file', 42))):
         lines = publisher.publish_lines(self.item5, '.txt')
         text = ''.join(line + '\n' for line in lines)
     self.assertIn("Reference: path/to/mock/file (line 42)", text)
Ejemplo n.º 2
0
 def test_lines_html_item_without_child_links(self):
     """Verify HTML can be published from an item w/o child links."""
     # Act
     lines = publisher.publish_lines(self.item2, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertNotIn("Child links", text)
Ejemplo n.º 3
0
 def test_lines_markdown_item_with_child_links(self):
     """Verify Markdown can be published from an item w/ child links."""
     # Act
     lines = publisher.publish_lines(self.item2, '.md')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertIn("Child links: tst1", text)
Ejemplo n.º 4
0
 def test_lines_markdown_item(self):
     """Verify Markdown can be published from an item."""
     with patch.object(self.item5, 'find_ref',
                       Mock(return_value=('path/to/mock/file', 42))):
         lines = publisher.publish_lines(self.item5, '.md')
         text = ''.join(line + '\n' for line in lines)
     self.assertIn("> `path/to/mock/file` (line 42)", text)
Ejemplo n.º 5
0
 def test_lines_markdown_item(self):
     """Verify Markdown can be published from an item."""
     with patch.object(self.item5, 'find_ref',
                       Mock(return_value=('path/to/mock/file', 42))):
         lines = publisher.publish_lines(self.item5, '.md')
         text = ''.join(line + '\n' for line in lines)
     self.assertIn("> `path/to/mock/file` (line 42)", text)
Ejemplo n.º 6
0
 def test_lines_markdown_item_with_child_links(self):
     """Verify Markdown can be published from an item w/ child links."""
     # Act
     lines = publisher.publish_lines(self.item2, '.md')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertIn("Child links: tst1", text)
Ejemplo n.º 7
0
 def test_lines_text_item_with_child_links(self):
     """Verify text can be published with child links."""
     # Act
     lines = publisher.publish_lines(self.item2, '.txt')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertIn("Child links: tst1", text)
Ejemplo n.º 8
0
 def test_lines_text_item(self):
     """Verify text can be published from an item."""
     with patch.object(self.item5, 'find_ref',
                       Mock(return_value=('path/to/mock/file', 42))):
         lines = publisher.publish_lines(self.item5, '.txt')
         text = ''.join(line + '\n' for line in lines)
     self.assertIn("Reference: path/to/mock/file (line 42)", text)
Ejemplo n.º 9
0
 def test_lines_text_item_with_child_links(self):
     """Verify text can be published with child links."""
     # Act
     lines = publisher.publish_lines(self.item2, '.txt')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertIn("Child links: tst1", text)
Ejemplo n.º 10
0
 def test_lines_html_item_without_child_links(self):
     """Verify HTML can be published from an item w/o child links."""
     # Act
     lines = publisher.publish_lines(self.item2, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertNotIn("Child links", text)
Ejemplo n.º 11
0
 def test_lines_markdown_item_heading(self):
     """Verify Markdown can be published from an item (heading)."""
     expected = "## 1.1 Heading {#req3 }\n\n"
     # Act
     lines = publisher.publish_lines(self.item, '.md', linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 12
0
 def test_lines_markdown_item_heading_no_heading_levels(self):
     """Verify an item heading level can be ommitted."""
     expected = "## Heading {#req3 }\n\n"
     # Act
     lines = publisher.publish_lines(self.item, '.md', linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 13
0
 def test_lines_markdown_item_heading(self):
     """Verify Markdown can be published from an item (heading)."""
     expected = "## 1.1 Heading {: #req3 }\n\n"
     # Act
     lines = publisher.publish_lines(self.item, '.md', linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 14
0
 def test_lines_html_item(self):
     """Verify HTML can be published from an item."""
     expected = '<h2>1.1 Heading</h2>\n'
     # Act
     lines = publisher.publish_lines(self.item, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 15
0
 def test_lines_html_item_no_heading_levels(self):
     """Verify an item heading level can be ommitted."""
     expected = '<section class="section2" id="req3"><h2>Heading</h2>\n</section>\n'
     # Act
     lines = publisher.publish_lines(self.item, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 16
0
 def test_lines_html_item(self):
     """Verify HTML can be published from an item."""
     expected = '<h2>1.1 Heading</h2>\n'
     # Act
     lines = publisher.publish_lines(self.item, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 17
0
 def test_lines_html_item_linkify(self):
     """Verify HTML (hyper) can be published from an item."""
     expected = '<h2 id="req3">1.1 Heading</h2>\n'
     # Act
     lines = publisher.publish_lines(self.item, '.html', linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 18
0
 def test_lines_markdown_item_heading_no_heading_levels(self):
     """Verify an item heading level can be ommitted."""
     expected = "## Heading {#req3 }\n\n"
     # Act
     lines = publisher.publish_lines(self.item, '.md', linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 19
0
 def test_single_line_heading_to_markdown(self):
     """Verify a single line heading is published as a heading with an attribute equal to the item id"""
     expected = "## 1.1 Heading {#req3 }\n\n"
     lines = publisher.publish_lines(self.item, '.md', linkify=True)
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 20
0
 def test_lines_text_item_heading(self):
     """Verify text can be published from an item (heading)."""
     expected = "1.1     Heading\n\n"
     lines = publisher.publish_lines(self.item, '.txt')
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 21
0
 def test_lines_html_item_with_child_links_linkify(self):
     """Verify HTML (hyper) can be published from an item w/ child links."""
     # Act
     lines = publisher.publish_lines(self.item2, '.html', linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertIn("Child links:", text)
     self.assertIn("tst.html#tst1", text)
Ejemplo n.º 22
0
 def test_lines_text_item_heading(self):
     """Verify text can be published from an item (heading)."""
     expected = "1.1     Heading\n\n"
     lines = publisher.publish_lines(self.item, '.txt')
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 23
0
 def test_lines_text_item_heading_no_heading_levels(self):
     """Verify an item heading level can be ommitted."""
     expected = "Heading\n\n"
     lines = publisher.publish_lines(self.item, '.txt')
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 24
0
 def test_single_line_heading_to_markdown(self):
     """Verify a single line heading is published as a heading with an attribute equal to the item id"""
     expected = "## 1.1 Heading {#req3 }\n\n"
     lines = publisher.publish_lines(self.item, '.md', linkify=True)
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 25
0
 def test_lines_html_item_linkify(self):
     """Verify HTML (hyper) can be published from an item."""
     expected = '<section class="section2" id="req3"><h2>1.1 Heading</h2>\n</section>\n'
     # Act
     lines = publisher.publish_lines(self.item, '.html', linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 26
0
 def test_lines_text_item_heading_no_heading_levels(self):
     """Verify an item heading level can be ommitted."""
     expected = "Heading\n\n"
     lines = publisher.publish_lines(self.item, '.txt')
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 27
0
 def test_lines_html_item_no_heading_levels(self):
     """Verify an item heading level can be ommitted."""
     expected = '<h2 id="req3">Heading</h2>\n'
     # Act
     lines = publisher.publish_lines(self.item, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 28
0
 def test_lines_html_item_with_child_links_linkify(self):
     """Verify HTML (hyper) can be published from an item w/ child links."""
     # Act
     lines = publisher.publish_lines(self.item2, '.html', linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertIn("Child links:", text)
     self.assertIn("tst.html#tst1", text)
Ejemplo n.º 29
0
def run_publish(args, cwd, error, catch=True):
    """Process arguments and run the `doorstop publish` subcommand.

    :param args: Namespace of CLI arguments
    :param cwd: current working directory
    :param error: function to call for CLI errors
    :param catch: catch and log :class:`~doorstop.common.DoorstopError`

    """
    whole_tree = args.prefix == 'all'
    ext = utilities.get_ext(args, error, '.txt', '.html', whole_tree)

    # Get the tree or document
    with utilities.capture(catch=catch) as success:

        publisher.check(ext)
        tree = _get_tree(args, cwd, load=whole_tree)
        if not whole_tree:
            document = tree.find_document(args.prefix)

    if not success:
        return False

    # Set publishing arguments
    kwargs = {}
    if args.width:
        kwargs['width'] = args.width

    # Write to output file(s)
    if args.path:
        path = os.path.abspath(os.path.join(cwd, args.path))
        if whole_tree:
            msg = "publishing tree to '{}'...".format(path)
            utilities.show(msg, flush=True)
            published_path = publisher.publish(tree,
                                               path,
                                               ext,
                                               template=args.template,
                                               **kwargs)
        else:
            msg = "publishing document {} to '{}'...".format(document, path)
            utilities.show(msg, flush=True)
            published_path = publisher.publish(document,
                                               path,
                                               ext,
                                               template=args.template,
                                               **kwargs)
        if published_path:
            utilities.show("published: {}".format(published_path))

    # Or, display to standard output
    else:
        if whole_tree:
            error("only single documents can be displayed")
        for line in publisher.publish_lines(document, ext, **kwargs):
            utilities.show(line)

    return True
Ejemplo n.º 30
0
 def test_lines_text_item_references(self):
     """Verify references can be published to a text file from an item."""
     mock_value = [('path/to/mock/file1', 3), ('path/to/mock/file2', None)]
     with patch.object(self.item6, 'find_references',
                       Mock(return_value=mock_value)):
         lines = publisher.publish_lines(self.item6, '.txt')
         text = ''.join(line + '\n' for line in lines)
     self.assertIn(
         "Reference: path/to/mock/file1 (line 3), path/to/mock/file2", text)
Ejemplo n.º 31
0
 def test_lines_text_item_no_ref(self):
     """Verify text can be published without checking references."""
     self.item.ref = 'abc123'
     self.item.heading = False
     # Act
     lines = publisher.publish_lines(self.item, '.txt')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertIn("Reference: 'abc123'", text)
Ejemplo n.º 32
0
 def test_lines_html_item(self):
     """Verify HTML can be published from an item."""
     expected = (
         '<section class="section2" id="req3"><h2>1.1 Heading</h2>\n</section>\n'
     )
     # Act
     lines = publisher.publish_lines(self.item, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 33
0
 def test_lines_markdown_item_without_body_levels(self):
     """Verify Markdown can be published from an item (no body levels)."""
     expected = ("## req4" + '\n\n'
                 "This shall..." + '\n\n'
                 "> `Doorstop.sublime-project`" + '\n\n'
                 "*Links: sys4*" + '\n\n')
     # Act
     lines = publisher.publish_lines(self.item3, '.md', linkify=False)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 34
0
 def test_lines_text_item_normative(self):
     """Verify text can be published from an item (normative)."""
     expected = ("1.2     req4" + '\n\n'
                 "        This shall..." + '\n\n'
                 "        Reference: Doorstop.sublime-project" + '\n\n'
                 "        Links: sys4" + '\n\n')
     lines = publisher.publish_lines(self.item3, '.txt')
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 35
0
 def test_lines_markdown_item_without_body_levels(self):
     """Verify Markdown can be published from an item (no body levels)."""
     expected = ("## req4 {#req4 }" + '\n\n'
                 "This shall..." + '\n\n'
                 "> `Doorstop.sublime-project`" + '\n\n'
                 "*Links: sys4*" + '\n\n')
     # Act
     lines = publisher.publish_lines(self.item3, '.md', linkify=False)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 36
0
    def test_lines_markdown_item_references(self):
        """Verify Markdown can be published from an item."""
        references_mock = [('path/to/mock/file1', 3),
                           ('path/to/mock/file2', None)]

        with patch.object(self.item6, 'find_references',
                          Mock(return_value=references_mock)):
            lines = publisher.publish_lines(self.item6, '.md')
            text = ''.join(line + '\n' for line in lines)
        self.assertIn(
            "> `path/to/mock/file1` (line 3)\n> `path/to/mock/file2`", text)
Ejemplo n.º 37
0
 def test_lines_markdown_item_normative(self):
     """Verify Markdown can be published from an item (normative)."""
     expected = ("## 1.2 req4" + '\n\n'
                 "This shall..." + '\n\n'
                 "Reference: Doorstop.sublime-project (line None)" + '\n\n'
                 "*Links: sys4*" + '\n\n')
     # Act
     lines = publisher.publish_lines(self.item3, '.md', linkify=False)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 38
0
 def test_lines_text_item_normative(self):
     """Verify text can be published from an item (normative)."""
     expected = ("1.2     req4" + '\n\n'
                 "        This shall..." + '\n\n'
                 "        Reference: Doorstop.sublime-project" + '\n\n'
                 "        Links: sys4" + '\n\n')
     lines = publisher.publish_lines(self.item3, '.txt')
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 39
0
def run_publish(args, cwd, error, catch=True):
    """Process arguments and run the `doorstop publish` subcommand.

    :param args: Namespace of CLI arguments
    :param cwd: current working directory
    :param error: function to call for CLI errors
    :param catch: catch and log :class:`~doorstop.common.DoorstopError`

    """
    whole_tree = args.prefix == 'all'
    ext = utilities.get_ext(args, error, '.txt', '.html', whole_tree)

    # Get the tree or document
    with utilities.capture(catch=catch) as success:

        publisher.check(ext)
        tree = _get_tree(args, cwd, load=whole_tree)
        if not whole_tree:
            document = tree.find_document(args.prefix)

    if not success:
        return False

    # Set publishing arguments
    kwargs = {}
    if args.width:
        kwargs['width'] = args.width

    # Write to output file(s)
    if args.path:
        path = os.path.abspath(os.path.join(cwd, args.path))
        if whole_tree:
            msg = "publishing tree to '{}'...".format(path)
            utilities.show(msg, flush=True)
            published_path = publisher.publish(tree, path, ext,
                                               template=args.template, **kwargs)
        else:
            msg = "publishing document {} to '{}'...".format(document,
                                                             path)
            utilities.show(msg, flush=True)
            published_path = publisher.publish(document, path, ext,
                                               template=args.template, **kwargs)
        if published_path:
            utilities.show("published: {}".format(published_path))

    # Or, display to standard output
    else:
        if whole_tree:
            error("only single documents can be displayed")
        for line in publisher.publish_lines(document, ext, **kwargs):
            utilities.show(line)

    return True
Ejemplo n.º 40
0
 def test_multi_line_heading_to_markdown_no_heading_levels(self):
     """Verify a multi line heading is published as a heading, without level, with an attribute equal to the item id"""
     item = MockItemAndVCS('path/to/req3.yml',
                           _file=("links: [sys3]" + '\n'
                                  "text: 'Heading\n\nThis section describes publishing.'" + '\n'
                                  "level: 1.1.0" + '\n'
                                  "normative: false"))
     expected = "## Heading {#req3 }\nThis section describes publishing.\n\n"
     lines = publisher.publish_lines(item, '.md', linkify=True)
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 41
0
 def test_multi_line_heading_to_markdown(self):
     """Verify a multi line heading is published as a heading with an attribute equal to the item id"""
     item = MockItemAndVCS(
         'path/to/req3.yml',
         _file=("links: [sys3]" + '\n'
                "text: 'Heading\n\nThis section describes publishing.'" +
                '\n'
                "level: 1.1.0" + '\n'
                "normative: false"))
     expected = "## 1.1 Heading {#req3 }\nThis section describes publishing.\n\n"
     lines = publisher.publish_lines(item, '.md', linkify=True)
     # Act
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Ejemplo n.º 42
0
def run_publish(args, cwd, error, catch=True):
    """Process arguments and run the `doorstop publish` subcommand.

    :param args: Namespace of CLI arguments
    :param cwd: current working directory
    :param error: function to call for CLI errors
    :param catch: catch and log :class:`~doorstop.common.DoorstopError`

    """
    # Parse arguments
    whole_tree = args.prefix == 'all'
    ext = utilities.get_ext(args, '.txt', '.html', whole_tree, error)

    # Publish documents
    with utilities.capture(catch=catch) as success:
        publisher.check(ext)
        tree = build(cwd=cwd, root=args.project)
        if not whole_tree:
            document = tree.find_document(args.prefix)
    if not success:
        return False

    # Set publishing arguments
    kwargs = {}
    if args.width:
        kwargs['width'] = args.width

    # Write to output file(s)
    if args.path:
        if whole_tree:
            show("publishing tree to '{}'...".format(args.path), flush=True)
            path = publisher.publish(tree, args.path, ext, **kwargs)
        else:
            msg = "publishing document {} to '{}'...".format(document,
                                                             args.path)
            show(msg, flush=True)
            path = publisher.publish(document, args.path, ext, **kwargs)
        if path:
            show("published: {}".format(path))

    # Display to standard output
    else:
        if whole_tree:
            error("only single documents can be displayed")
        for line in publisher.publish_lines(document, ext, **kwargs):
            show(line)

    return True
Ejemplo n.º 43
0
 def test_lines_unknown(self):
     """Verify an exception is raised when iterating an unknown format."""
     # Act
     gen = publisher.publish_lines(self.document, '.a')
     # Assert
     self.assertRaises(DoorstopError, list, gen)
Ejemplo n.º 44
0
 def test_lines_markdown_item_no_ref(self):
     """Verify Markdown can be published without checking references."""
     lines = publisher.publish_lines(self.item5, '.md')
     text = ''.join(line + '\n' for line in lines)
     self.assertIn("> 'abc123'", text)
Ejemplo n.º 45
0
 def test_lines_text_item_no_ref(self):
     """Verify text can be published without checking references."""
     lines = publisher.publish_lines(self.item5, '.txt')
     text = ''.join(line + '\n' for line in lines)
     self.assertIn("Reference: 'abc123'", text)
Ejemplo n.º 46
0
 def test_lines_text_item_no_ref(self):
     """Verify text can be published without checking references."""
     lines = publisher.publish_lines(self.item5, '.txt')
     text = ''.join(line + '\n' for line in lines)
     self.assertIn("Reference: 'abc123'", text)
Ejemplo n.º 47
0
 def test_lines_markdown_item_no_ref(self):
     """Verify Markdown can be published without checking references."""
     lines = publisher.publish_lines(self.item5, '.md')
     text = ''.join(line + '\n' for line in lines)
     self.assertIn("> 'abc123'", text)
Ejemplo n.º 48
0
 def test_lines_unknown(self):
     """Verify an exception is raised when iterating an unknown format."""
     # Act
     gen = publisher.publish_lines(self.document, '.a')
     # Assert
     self.assertRaises(DoorstopError, list, gen)