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)
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)
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)
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)
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