2020-02-12 15:24:51 +00:00
|
|
|
#!/usr/bin/env python3
|
2019-05-13 15:00:38 +02:00
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
import os
|
|
|
|
|
import tempfile
|
|
|
|
|
import shutil
|
|
|
|
|
import sys
|
|
|
|
|
|
2024-08-04 11:51:04 +02:00
|
|
|
from format_fortran import main
|
2019-05-13 15:00:38 +02:00
|
|
|
from prettify_cp2k import selftest
|
|
|
|
|
|
2019-09-18 15:33:39 +02:00
|
|
|
|
2019-05-13 15:00:38 +02:00
|
|
|
class TestSingleFileFolder(unittest.TestCase):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.tempdir = tempfile.mkdtemp()
|
|
|
|
|
self.fname = os.path.join(self.tempdir, "prettify_selftest.F")
|
|
|
|
|
|
|
|
|
|
# create temporary file with example code
|
2020-10-19 10:30:35 +02:00
|
|
|
with open(self.fname, "w", encoding="utf8") as fhandle:
|
2019-05-13 15:00:38 +02:00
|
|
|
fhandle.write(selftest.content)
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
shutil.rmtree(self.tempdir)
|
|
|
|
|
|
|
|
|
|
def test_prettify(self):
|
|
|
|
|
# call prettify, the return value should be 0 (OK)
|
2019-09-18 15:33:39 +02:00
|
|
|
self.assertEqual(main([self.fname]), 0)
|
2019-05-13 15:00:38 +02:00
|
|
|
|
|
|
|
|
# check if file was altered (it shouldn't)
|
2020-10-19 10:30:35 +02:00
|
|
|
with open(self.fname, encoding="utf8") as fhandle:
|
2019-05-13 15:00:38 +02:00
|
|
|
result = fhandle.read()
|
|
|
|
|
|
|
|
|
|
self.assertEqual(result.splitlines(), selftest.content.splitlines())
|
|
|
|
|
|
2019-09-18 15:33:39 +02:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-05-13 15:00:38 +02:00
|
|
|
unittest.main()
|