Exemple #1
0
    def test_handles_yaml_errors(self):
        """
        YAML errors are raised as exceptions.
        """
        fileobject = self.make_file_like(EXAMPLE_2)

        with self.assertRaises(ParserError):
            meta, body = separate_meta(fileobject)
Exemple #2
0
    def test_handles_lack_of_front_matter(self):
        """
        If no YAML section is present.
        """
        fileobject = self.make_file_like(EXAMPLE_3)

        meta, body = separate_meta(fileobject)

        self.assertIsNone(meta)
Exemple #3
0
    def test_converts_yaml_string_to_object(self):
        """
        The YAML string is converted into an object.
        """
        fileobject = self.make_file_like(EXAMPLE_1)

        meta, body = separate_meta(fileobject)

        self.assertIsInstance(meta, dict)
Exemple #4
0
    def test_separates_front_matter(self):
        """
        Simple separation of YAML section and body.
        """
        fileobject = self.make_file_like(EXAMPLE_1)

        meta, body = separate_meta(fileobject)

        self.assertTrue(meta)
        self.assertTrue(body)
Exemple #5
0
    def read_and_separate(self):
        """
        Read the file and cache the meta and body.

        :returns: (meta, body)
        :rtype: tuple
        """
        if not self._content_cache:
            with open(self.path) as fh:
                self._content_cache = separate_meta(fh)

        return self._content_cache