Exemple #1
0
 def test_output_json(self):
     main(['eg/Ancient Llama Sightings.md', '--output-json'])
     data = json.loads(sys.stdout.getvalue())
     self.assertDictEqual(data, {
         u'documents': [
             {
                 u'filename': u'eg/Ancient Llama Sightings.md',
                 u'title': u'Ancient Llama Sightings',
                 u'preamble': u'',
                 u'properties': data['documents'][0]['properties'],
                 u'sections': data['documents'][0]['sections'],
             }
         ]
     })
     self.assertDictEqual(data['documents'][0]['properties'], {
         u'author': u'Alfred J. Prufrock',
         u'link-target-url': u'https://github.com/catseye/Feedmark/blob/master/eg/Ancient%20Llama%20Sightings.md',
         u'url': u'http://example.com/old_llama.xml'
     })
     self.assertEqual(data['documents'][0]['sections'], [
         {
             u'body': data['documents'][0]['sections'][0]['body'],
             u'images': [
                 {
                     u'description': u'photo of possible llama',
                     u'source': u'https://static.catseye.tc/images/screenshots/Kolakoski_Kurve.jpg',
                 }
             ],
             u'properties': {u'date': u'Jan 1 1984 12:00:00'},
             u'title': u'Maybe sighting the llama',
             u'anchor': u'maybe-sighting-the-llama',
         }
     ])
     self.assertIn(u'It was a possible llama sighting.\n\n', data['documents'][0]['sections'][0]['body'])
Exemple #2
0
 def test_output_refdex_with_overlap(self):
     # Both of these files contain an entry called "Llamas: It's Time to Spot Them".
     # The refdex is created with entries pointing to all files where the entry occurs.
     main(['eg/Recent Llama Sightings.md', 'eg/Referenced Llama Sightings.md', '--output-refdex'])
     data = json.loads(sys.stdout.getvalue())
     self.assertDictEqual(data, {
         "2 Llamas Spotted Near Mall": {
             "anchor": "2-llamas-spotted-near-mall",
             "filenames": [
                 "eg/Recent Llama Sightings.md",
             ]
         },
         "A Possible Llama Under the Bridge": {
             "anchor": "a-possible-llama-under-the-bridge",
             "filenames": [
                 "eg/Recent Llama Sightings.md",
             ],
         },
         "Llamas: It's Time to Spot Them": {
             "anchor": "llamas-its-time-to-spot-them",
             "filenames": [
                 "eg/Recent Llama Sightings.md",
                 "eg/Referenced Llama Sightings.md"
             ]
         },
     })
Exemple #3
0
 def test_atom_feed(self):
     main(["{}/eg/Recent Llama Sightings.md".format(self.prevdir), '--output-atom=feed.xml'])
     self.assert_file_contains('feed.xml', '<id>http://example.com/llama.xml/2 Llamas Spotted Near Mall</id>')
     self.assert_file_contains('feed.xml',
         'https://github.com/catseye/Feedmark/blob/master/eg/Recent%20Llama%20Sightings.md#2-llamas-spotted-near-mall'
     )
     os.unlink('feed.xml')
Exemple #4
0
 def test_schema_failure(self):
     with self.assertRaises(SystemExit):
         main(["eg/Ill-formed Llama Sightings.md", '--check-against=eg/schema/Llama sighting.md'])
     data = json.loads(sys.stdout.getvalue())
     self.assertEqual(data, [
         {
             u'document': u'Ill-formed Llama Sightings',
             u'result': [[u'extra', u'excuse'], [u'missing', u'date']],
             u'section': u'Definite llama sighting with no date'
         }
     ])
Exemple #5
0
    def test_rewrite_markdown(self):
        with open('foo.md', 'w') as f:
            f.write("""# Document

### Entry

Have you heard, [2 Llamas Spotted Near Mall]()?

[2 Llamas Spotted Near Mall]: TK
""")
        main(["foo.md", "--input-refdex={}/eg/refdex.json".format(self.prevdir), '--rewrite-markdown'])
        self.assert_file_contains('foo.md', '[2 Llamas Spotted Near Mall]: eg/Recent%20Llama%20Sightings.md#2-llamas-spotted-near-mall')
        os.unlink('foo.md')
Exemple #6
0
 def test_output_json_with_multiple_images_and_linked_images(self):
     main(['eg/Recent Llama Sightings.md', '--output-json'])
     data = json.loads(sys.stdout.getvalue())
     self.assertEqual(data['documents'][0]['sections'][1]['images'], [
         {
             u'description': u'photo of possible llama',
             u'source': u'https://static.catseye.tc/images/screenshots/Heronsis_hermnonicii.jpg',
             u'link': u'https://catseye.tc/article/Gewgaws.md',
         },
         {
             u'description': u'another possible photo',
             u'source': u'https://static.catseye.tc/images/screenshots/A_Non-Random_Walk.jpg',
         },
     ])
Exemple #7
0
 def test_output_ordered_json(self):
     main(['eg/Referenced Llama Sightings.md', '--output-json', '--ordered-json'])
     data = json.loads(sys.stdout.getvalue())
     self.assertEqual(data['documents'][0]['properties'], [
         [u'author', u'Alfred J. Prufrock'],
         [u'url', u'http://example.com/refllama.xml'],
         [u'link-target-url', u'https://github.com/catseye/Feedmark/blob/master/eg/Referenced%20Llama%20Sightings.md'],
         [u'hopper', u'[Stephen](https://en.wikipedia.org/wiki/Stephen_Hopper)'],
         [u'spotted', [u'[the mall][]', u'[the beach](beach.html)']],
     ])
     self.assertEqual(data['documents'][0]['sections'][0]['properties'], [
         [u'date', u'Nov 1 2016 09:00:00'],
         [u'hopper', u'[Grace](https://en.wikipedia.org/wiki/Grace_Hopper)'],
         [u'spotted', [u'[the mall][]', u'[the lumberyard](lumberyard.html)']]
     ])
Exemple #8
0
 def test_output_links(self):
     main(['eg/Ill-formed Llama Sightings.md', '--output-links'])
     data = json.loads(sys.stdout.getvalue())
     self.assertEqual(data, [
         {
             u'document': u'Ill-formed Llama Sightings',
             u'name': u'2 Llamas Spotted Near Mall',
             u'section': u'Definite llama sighting with no date',
             u'url': u'TK'
         },
         {
             u'document': u'Ill-formed Llama Sightings',
             u'section': u'Definite llama sighting with no date',
             u'url': u'https://tcrf.net/The_Cutting_Room_Floor'
         }
     ])
Exemple #9
0
 def test_output_refdex_with_overlap_forcing_single_filename(self):
     # Both of these files contain an entry called "Llamas: It's Time to Spot Them"
     # The refdex is created pointing only to the file that was mentioned last.
     main(['eg/Recent Llama Sightings.md', 'eg/Referenced Llama Sightings.md', '--output-refdex', '--output-refdex-single-filename'])
     data = json.loads(sys.stdout.getvalue())
     self.assertDictEqual(data, {
         "2 Llamas Spotted Near Mall": {
             "anchor": "2-llamas-spotted-near-mall",
             "filename": "eg/Recent Llama Sightings.md",
         },
         "A Possible Llama Under the Bridge": {
             "anchor": "a-possible-llama-under-the-bridge",
             "filename": "eg/Recent Llama Sightings.md",
         },
         "Llamas: It's Time to Spot Them": {
             "anchor": "llamas-its-time-to-spot-them",
             "filename": "eg/Referenced Llama Sightings.md",
         },
     })
Exemple #10
0
 def test_output_refdex(self):
     main(['eg/Recent Llama Sightings.md', 'eg/Ancient Llama Sightings.md', '--output-refdex'])
     data = json.loads(sys.stdout.getvalue())
     self.assertDictEqual(data, {
         "2 Llamas Spotted Near Mall": {
             "anchor": "2-llamas-spotted-near-mall",
             "filenames": ["eg/Recent Llama Sightings.md"],
         },
         "A Possible Llama Under the Bridge": {
             "anchor": "a-possible-llama-under-the-bridge",
             "filenames": ["eg/Recent Llama Sightings.md"],
         },
         "Llamas: It's Time to Spot Them": {
             "anchor": "llamas-its-time-to-spot-them",
             "filenames": ["eg/Recent Llama Sightings.md"],
         },
         "Maybe sighting the llama": {
             "anchor": "maybe-sighting-the-llama",
             "filenames": ["eg/Ancient Llama Sightings.md"],
         }
     })
Exemple #11
0
 def test_output_htmlized_json(self):
     main(['eg/Referenced Llama Sightings.md', '--output-json', '--htmlized-json'])
     data = json.loads(sys.stdout.getvalue())
     self.assertDictEqual(data, {
         u'documents': [
             {
                 u'filename': u'eg/Referenced Llama Sightings.md',
                 u'title': u'Referenced Llama Sightings',
                 u'preamble': u'<p>Some <strong>llamas</strong> have been <a href="spotted.html">spotted</a> recently.</p>',
                 u'properties': data['documents'][0]['properties'],
                 u'sections': data['documents'][0]['sections'],
             }
         ]
     })
     self.assertEqual(
         data['documents'][0]['sections'][0]['body'],
         u"<p>I have strong opinions about this.  It's a <em>shame</em> more llamas aren't\nbeing spotted.  "
          "Sometimes they are <strong>striped</strong>, it's true, but<br />\nwhen<br />\nthey are, "
          "<a href=\"https://daringfireball.net/projects/markdown/\">Markdown</a>\ncan be used.</p>\n"
          "<p>To <a href=\"https://en.wikipedia.org/wiki/Site\">site</a> them.</p>\n<p>Sight them, sigh.</p>"
     )
     # note that property values are bare HTML fragments: there is no surrounding <p></p> or other element
     self.assertEqual(
         data['documents'][0]['properties']['hopper'],
         '<a href="https://en.wikipedia.org/wiki/Stephen_Hopper">Stephen</a>'
     )
     self.assertEqual(
         data['documents'][0]['properties']['spotted'],
         [u'<a href="mall.html">the mall</a>', u'<a href="beach.html">the beach</a>']
     )
     self.assertEqual(
         data['documents'][0]['sections'][0]['properties']['hopper'],
         '<a href="https://en.wikipedia.org/wiki/Grace_Hopper">Grace</a>'
     )
     self.assertEqual(
         data['documents'][0]['sections'][0]['properties']['spotted'],
         [u'<a href="mall.html">the mall</a>', u'<a href="lumberyard.html">the lumberyard</a>']
     )
Exemple #12
0
 def test_output_html(self):
     main(["eg/Recent Llama Sightings.md", "--output-html"])
     output = sys.stdout.getvalue()
     self.assertIn('<h3 id="a-possible-llama-under-the-bridge">A Possible Llama Under the Bridge</h3>', output)
Exemple #13
0
 def test_schema(self):
     main(["eg/Recent Llama Sightings.md", "eg/Ancient Llama Sightings.md", '--check-against=eg/schema/Llama sighting.md'])
     output = sys.stdout.getvalue()
     self.assertEqual(output, '')
Exemple #14
0
 def test_input_refdex_output_markdown(self):
     main(['eg/Ill-formed Llama Sightings.md', '--input-refdex', 'eg/refdex.json', '--output-markdown'])
     output = sys.stdout.getvalue()
     self.assertIn('[2 Llamas Spotted Near Mall]: eg/Recent%20Llama%20Sightings.md#2-llamas-spotted-near-mall', output)