nasg/tests.py
Peter Molnar a8e403ae04 After long discussions, mainly listening and reading, I'm giving up on GPL licencing and moving to Apache 2.0.
The short summary is that while I still sort of believe in what GPL stands for, reality is not that simple to immediately open source everything.

Because GPL is scary, many people avoid it, and one of the main achievements of open source should be that nobody has to reinvent the wheel.
2018-12-03 10:36:10 +00:00

80 lines
2.4 KiB
Python

__author__ = "Peter Molnar"
__copyright__ = "Copyright 2017-2018, Peter Molnar"
__license__ = "apache-2.0"
__maintainer__ = "Peter Molnar"
__email__ = "mail@petermolnar.net"
import unittest
import pandoc
import exiftool
import nasg
import os
import json
class TestNASG(unittest.TestCase):
def test_url2slug(self):
i = 'http://boffosocko.com/2017/10/28/content-bloat-privacy-archives-peter-molnar/'
o = 'boffosockocom20171028content-bloat-privacy-archives-peter-molnar'
self.assertEqual(nasg.url2slug(i), o)
class TestSingular(unittest.TestCase):
singular = nasg.Singular('tests/index.md')
# TODO: WTF?
#def test_category(self):
#print(self.singular.category)
#self.assertEqual(self.singular.category, 'tests')
#def test_files(self):
#self.assertEqual(
#self.singular.files,
#['/home/pemolnar/Projects/petermolnar.net/nasg/tests/tests.jpg']
def test_is_photo(self):
self.assertTrue(self.singular.is_photo)
def test_is_front(self):
self.assertFalse(self.singular.is_front)
def test_singular_tags(self):
self.assertEqual(
self.singular.tags,
[
'Llyn Idwal',
'winter',
'spring',
'cloudy',
'Snowdonia',
'mountain',
'clouds',
'lake',
'mountains',
'snow',
'Wales',
'water'
]
)
class TestExiftool(unittest.TestCase):
def test_exiftool(self):
if os.path.exists('tests/.Exif.tests.jpg.json'):
os.unlink('tests/.Exif.tests.jpg.json')
with open('tests/tests.jpg.json', 'rt') as expected:
o = json.loads(expected.read())
self.assertEqual(exiftool.Exif('tests/tests.jpg'), o)
self.assertTrue(os.path.exists('tests/.Exif.tests.jpg.json'))
self.assertTrue(
os.path.getmtime('tests/.Exif.tests.jpg.json') >
os.path.getmtime('tests/tests.jpg.json')
)
class TestPandoc(unittest.TestCase):
def test_pandoc(self):
i = '_this_ is a **test** string for [pandoc](https://pandoc.org)'
o = '<p><em>this</em> is a <strong>test</strong> string for <a href="https://pandoc.org">pandoc</a></p>'
self.assertEqual(pandoc.Pandoc(i), o)
if __name__ == '__main__':
unittest.main()