<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>.:: Marcos Dione/StyXman's glob ::. (Posts about pytest)</title><link>https://www.grulic.org.ar/~mdione/glob/</link><description></description><atom:link href="https://www.grulic.org.ar/~mdione/glob/categories/pytest.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2025 &lt;a href="mailto:mdione@grulic.org.ar"&gt;Marcos Dione&lt;/a&gt; </copyright><lastBuildDate>Thu, 29 May 2025 15:41:12 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Migrating from ikiwiki to nikola</title><link>https://www.grulic.org.ar/~mdione/glob/posts/migrating-from-ikiwiki-to-nikola/</link><dc:creator>Marcos Dione</dc:creator><description>&lt;p&gt;As I mentioned several times already, my &lt;code&gt;ikiwiki&lt;/code&gt; setup for this glob is falling apart in my machine. As it is written
in &lt;code&gt;perl&lt;/code&gt;, a language I haven't touched in &lt;em&gt;may&lt;/em&gt; &lt;strong&gt;many&lt;/strong&gt; years, and its community seems to have dwindled and almost
disappeared, I've been thinking of migrating to something else. As a pythonista, one obvious option is &lt;code&gt;nikola&lt;/code&gt;. Also
because I know the original developer :)&lt;/p&gt;
&lt;p&gt;But what would it take to do this? Well, my &lt;code&gt;ikiwiki&lt;/code&gt; posts are written in Markdown, and &lt;code&gt;nikola&lt;/code&gt; also reads that format.
At the beginning I thought of converting to reStructuredText because I have an issue: because of a bad command (probably
a &lt;code&gt;cp&lt;/code&gt; instead of &lt;code&gt;rsync&lt;/code&gt; or &lt;code&gt;tar&lt;/code&gt;), I lost the original file times. With reStructuredText, I can provide the date as a
directive, and I can recover the original dates from archive.org's snapshots of my glob. But then I read that the same
data can be put in a sidecar &lt;code&gt;.meta&lt;/code&gt; file, so I can keep my original file format. Also, many things I wanted work best
with Markdown, most notably footnotes, which, I don't know if you noticed, &lt;strong&gt;never&lt;/strong&gt; worked on this glob :) Thanks
&lt;code&gt;+ChrisWarrick#nikola@libera.chat&lt;/code&gt; for all the help!&lt;/p&gt;
&lt;p&gt;Still, &lt;code&gt;ikiwiki&lt;/code&gt; handles a few things not very Markdown'ly, including images, code snippets and tags. To be honest, the
last two are not really a part of Markdown, but it still means I have to convert one markup into another.&lt;/p&gt;
&lt;p&gt;I had used &lt;code&gt;pytest&lt;/code&gt; in the past, but not much really. I usually write a &lt;code&gt;test()&lt;/code&gt; function where I test with &lt;code&gt;assert&lt;/code&gt;
&lt;em&gt;everything&lt;/em&gt;, and once all tests pass, I call &lt;code&gt;main()&lt;/code&gt; at script start instead. This was another quick hack, but I wanted
to give it a spin. I started with some pure TDD, writing input and outputs in test functions and just
&lt;code&gt;assert f(input) == output&lt;/code&gt; and &lt;code&gt;pytest&lt;/code&gt; did everything else for me, including showing me a diff that points out to the
small errors I was making. The iteration pace was feverish.&lt;/p&gt;
&lt;p&gt;All in all, it took me 3 21-23h hackatons to mostly finish it. I wrote one function for each step (footnotes, tags,
images and code snippets), all of them looking all the input lines all over again, but it doesn't really matter, as I
have to import many files by hand to specify the original publishing date. I also tested each regexp&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/migrating-from-ikiwiki-to-nikola/#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt; individually,
like &lt;a href="https://en.osm.town/@mdione/111425064643362929"&gt;I was discussing the other day&lt;/a&gt;&lt;sup id="fnref:2"&gt;&lt;a class="footnote-ref" href="https://www.grulic.org.ar/~mdione/glob/posts/migrating-from-ikiwiki-to-nikola/#fn:2"&gt;2&lt;/a&gt;&lt;/sup&gt;. They were short enough not to
follow my first tip, but by $GOD I used the other two a lot. There are another four helper functions (convert slugs to
titles; convert &lt;code&gt;time.timezone&lt;/code&gt; format to UTC offset (for instance, &lt;code&gt;+0100&lt;/code&gt;); convert timestamps to a certain date
format; and convert another date format to the same one), all also well tested. Then one short function to write the
sidecar file, one that glues everything together, and one for parsing command line parameters. All that, tests and their
data and all, in 538 lines of very hacky Python :) I'll try to post the code some other day, but frankly I run out of
steam and I still have lots of posts to import by hand.&lt;/p&gt;
&lt;p&gt;And that's it! Hopefully this will be the first post in the new glob version. I imported a few old posts already and
it's working just fine. I expect a few tweaks in the future, as we're talking about ~300 posts and I can't promise the
very old ones follow the same format. I set the feed size to one and I'll grow for the next nine posts so I don't break
planets and feed readers. I hope I got that right :)&lt;/p&gt;
&lt;div class="footnote"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;Yes, of course this includes regexps! But thanks to testing them, it didn't become the proverbial extra problem. &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/migrating-from-ikiwiki-to-nikola/#fnref:1" title="Jump back to footnote 1 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:2"&gt;
&lt;p&gt;Are you also on mastodon? Come say hi! &lt;a class="footnote-backref" href="https://www.grulic.org.ar/~mdione/glob/posts/migrating-from-ikiwiki-to-nikola/#fnref:2" title="Jump back to footnote 2 in the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description><category>ikiwiki</category><category>nikola</category><category>pytest</category><category>python</category><category>regexps</category><category>tdd</category><category>testing</category><guid>https://www.grulic.org.ar/~mdione/glob/posts/migrating-from-ikiwiki-to-nikola/</guid><pubDate>Thu, 30 Nov 2023 20:38:19 GMT</pubDate></item></channel></rss>