Beispiel #1
0
 def test_load_save(self):
     """Verify text formatting is preserved."""
     item = Item(self.ITEM)
     item.load()
     item.save()
     text = common.read_text(self.ITEM)
     self.assertEqual(self.backup, text)
Beispiel #2
0
 def test_load_save(self):
     """Verify text formatting is preserved."""
     item = Item(self.ITEM)
     item.load()
     item.save()
     text = common.read_text(self.ITEM)
     self.assertEqual(self.backup, text)
Beispiel #3
0
 def test_lines_markdown_document(self):
     """Verify Markdown can be published from a document."""
     path = os.path.join(FILES, 'published.md')
     expected = common.read_text(path)
     # Act
     lines = core.publisher.publish_lines(self.document, '.md')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     if CHECK_PUBLISHED_CONTENT:
         self.assertEqual(expected, text)
     common.write_text(text, path)
Beispiel #4
0
 def test_lines_html_document_without_child_links(self):
     """Verify HTML can be published from a document w/o child links."""
     path = os.path.join(FILES, 'published2.html')
     expected = common.read_text(path)
     # Act
     lines = core.publisher.publish_lines(self.document, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     if CHECK_PUBLISHED_CONTENT:
         self.assertEqual(expected, text)
     common.write_text(text, path)
Beispiel #5
0
 def test_lines_markdown_document(self):
     """Verify Markdown can be published from a document."""
     path = os.path.join(FILES, 'published.md')
     expected = common.read_text(path)
     # Act
     lines = core.publisher.publish_lines(self.document, '.md')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     if CHECK_PUBLISHED_CONTENT:
         self.assertEqual(expected, text)
     common.write_text(text, path)
Beispiel #6
0
 def test_lines_html_document_without_child_links(self):
     """Verify HTML can be published from a document w/o child links."""
     path = os.path.join(FILES, 'published2.html')
     expected = common.read_text(path)
     # Act
     lines = core.publisher.publish_lines(self.document, '.html')
     text = ''.join(line + '\n' for line in lines)
     # Assert
     if CHECK_PUBLISHED_CONTENT:
         self.assertEqual(expected, text)
     common.write_text(text, path)
Beispiel #7
0
 def _reorder_from_index(document, path):
     """Reorder a document's item from the index."""
     # Load and parse index
     text = common.read_text(path)
     data = common.load_yaml(text, path)
     # Read updated values
     initial = data.get('initial', 1.0)
     outline = data.get('outline', [])
     # Update levels
     level = Level(initial)
     Document._reorder_section(outline, level, document)
Beispiel #8
0
 def _reorder_from_index(document, path):
     """Reorder a document's item from the index."""
     # Load and parse index
     text = common.read_text(path)
     data = common.load_yaml(text, path)
     # Read updated values
     initial = data.get('initial', 1.0)
     outline = data.get('outline', [])
     # Update levels
     level = Level(initial)
     Document._reorder_section(outline, level, document)
Beispiel #9
0
    def _read(self, path):  # pragma: no cover (integration test)
        """Read text from the object's file.

        :param path: path to a text file

        :return: contexts of text file

        """
        if not self._exists:
            msg = "cannot read from deleted: {}".format(self.path)
            raise DoorstopError(msg)
        return common.read_text(path)
Beispiel #10
0
 def test_import_file_with_map(self):
     """Verify 'doorstop import' can import a file using a custom map."""
     path = os.path.join(FILES, "exported-map.csv")
     dirpath = os.path.join(self.temp, "imported", "prefix")
     main(["create", "PREFIX", dirpath])
     # Act
     self.assertIs(None, main(["import", path, "PREFIX", "--map", "{'mylevel': 'level'}"]))
     # Assert
     path = os.path.join(dirpath, "REQ001.yml")
     self.assertTrue(os.path.isfile(path))
     text = common.read_text(path)
     self.assertIn("\nlevel: 1.2.3", text)
Beispiel #11
0
 def test_import_file_with_map(self):
     """Verify 'doorstop import' can import a file using a custom map."""
     path = os.path.join(FILES, 'exported-map.csv')
     dirpath = os.path.join(self.temp, 'imported', 'prefix')
     main(['create', 'PREFIX', dirpath])
     # Act
     self.assertIs(None, main(['import', path, 'PREFIX',
                               '--map', "{'mylevel': 'level'}"]))
     # Assert
     path = os.path.join(dirpath, 'REQ001.yml')
     self.assertTrue(os.path.isfile(path))
     text = common.read_text(path)
     self.assertIn('\nlevel: 1.2.3', text)
Beispiel #12
0
 def test_import_file_with_map(self):
     """Verify 'doorstop import' can import a file using a custom map."""
     path = os.path.join(FILES, 'exported-map.csv')
     dirpath = os.path.join(self.temp, 'imported', 'prefix')
     main(['create', 'PREFIX', dirpath])
     # Act
     self.assertIs(None, main(['import', path, 'PREFIX',
                               '--map', "{'mylevel': 'level'}"]))
     # Assert
     path = os.path.join(dirpath, 'REQ001.yml')
     self.assertTrue(os.path.isfile(path))
     text = common.read_text(path)
     self.assertIn('\nlevel: 1.2.3', text)
Beispiel #13
0
 def test_lines_html_document_with_header(self):
     """Verify HTML can be published from a document with headers and child links contain header"""
     path = os.path.join(FILES_BETA, 'published3.html')
     expected = common.read_text(path)
     beta_features_tree = core.build(cwd=FILES_BETA, root=FILES_BETA)
     document_with_header = beta_features_tree.find_document('REQHEADER')
     # Act
     lines = core.publisher.publish_lines(document_with_header, '.html',
                                          linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     if CHECK_PUBLISHED_CONTENT:
         self.assertEqual(expected, text)
     common.write_text(text, path)
Beispiel #14
0
 def test_lines_html_document_with_header(self):
     """Verify HTML can be published from a document with headers and child links contain header"""
     path = os.path.join(FILES_BETA, 'published3.html')
     expected = common.read_text(path)
     beta_features_tree = core.build(cwd=FILES_BETA, root=FILES_BETA)
     document_with_header = beta_features_tree.find_document('REQHEADER')
     # Act
     lines = core.publisher.publish_lines(document_with_header,
                                          '.html',
                                          linkify=True)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     if CHECK_PUBLISHED_CONTENT:
         self.assertEqual(expected, text)
     common.write_text(text, path)
Beispiel #15
0
def _file_yml(path, document, **_):
    """Import items from a YAML export to a document.

    :param path: input file location
    :param document: document to import items

    """
    # Parse the file
    log.info("reading items in {}...".format(path))
    text = common.read_text(path)
    # Load the YAML data
    data = common.load_yaml(text, path)
    # Add items
    for uid, attrs in data.items():
        try:
            item = document.find_item(uid)
        except DoorstopError:
            pass  # no matching item
        else:
            item.delete()
        add_item(document.prefix, uid, attrs=attrs, document=document)
Beispiel #16
0
def _file_yml(path, document, **_):
    """Import items from a YAML export to a document.

    :param path: input file location
    :param document: document to import items

    """
    # Parse the file
    log.info("reading items in {}...".format(path))
    text = common.read_text(path)
    # Load the YAML data
    data = common.load_yaml(text, path)
    # Add items
    for uid, attrs in data.items():
        try:
            item = document.find_item(uid)
        except DoorstopError:
            pass  # no matching item
        else:
            item.delete()
        add_item(document.prefix, uid, attrs=attrs, document=document)
Beispiel #17
0
 def setUp(self):
     self.backup = common.read_text(self.ITEM)
     main(['link', 'tut3', 'req2'])  # create a temporary link
Beispiel #18
0
 def setUp(self):
     self.backup = common.read_text(self.ITEM)
     with patch("doorstop.settings.ADDREMOVE_FILES", False):
         main(["link", "tut3", "req2"])  # create a temporary link
Beispiel #19
0
 def setUp(self):
     self.path = os.path.join(FILES, 'REQ001.yml')
     self.backup = common.read_text(self.path)
     self.item = core.Item(self.path)
     self.item.tree = Mock()
     self.item.tree.vcs = mockvcs.WorkingCopy(EMPTY)
Beispiel #20
0
 def setUp(self):
     self.path = os.path.join(FILES, 'REQ001.yml')
     self.backup = common.read_text(self.path)
     self.item = core.Item(self.path)
     self.tree = core.Tree(core.Document(SYS))
     self.tree._place(core.Document(FILES))  # pylint: disable=W0212
Beispiel #21
0
def read_yml(path):
    """Return a dictionary of items from a YAML file."""
    text = common.read_text(path)
    data = yaml.load(text)
    return data
Beispiel #22
0
 def setUp(self):
     self.backup = common.read_text(self.ITEM)
     with patch('doorstop.settings.ADDREMOVE_FILES', False):
         main(['link', 'tut3', 'req2'])  # create a temporary link
Beispiel #23
0
 def setUp(self):
     self.backup = common.read_text(self.ITEM)
     with patch('doorstop.settings.ADDREMOVE_FILES', False):
         main(['link', 'tut3', 'req2'])  # create a temporary link
Beispiel #24
0
 def setUp(self):
     self.path = os.path.join(FILES, 'REQ001.yml')
     self.backup = common.read_text(self.path)
     self.item = core.Item(self.path)
     self.item.tree = Mock()
     self.item.tree.vcs = mockvcs.WorkingCopy(EMPTY)
Beispiel #25
0
 def setUp(self):
     self.path = os.path.join(FILES, 'REQ001.yml')
     self.backup = common.read_text(self.path)
     self.item = core.Item(self.path)
     self.tree = core.Tree(core.Document(SYS))
     self.tree._place(core.Document(FILES))
Beispiel #26
0
 def setUp(self):
     self.backup = common.read_text(self.ITEM)
Beispiel #27
0
 def setUp(self):
     self.path = os.path.join(FILES, 'REQ001.yml')
     self.backup = common.read_text(self.path)
     self.item = core.Item(self.path)
Beispiel #28
0
def read_yml(path):
    """Return a dictionary of items from a YAML file."""
    text = common.read_text(path)
    data = yaml.load(text)
    return data
Beispiel #29
0
 def setUp(self):
     self.backup = common.read_text(self.ITEM)
Beispiel #30
0
 def setUp(self):
     self.backup = common.read_text(self.ITEM)
     main(['link', 'tut3', 'req2'])  # create a temporary link