-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prettify: factor out selftest to separate _TEST.py file
- Loading branch information
Showing
3 changed files
with
41 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
|
||
from __future__ import absolute_import | ||
|
||
import unittest | ||
import os | ||
import tempfile | ||
import shutil | ||
import sys | ||
|
||
from prettify import main | ||
from prettify_cp2k import selftest | ||
|
||
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 | ||
with open(self.fname, "w") as fhandle: | ||
fhandle.write(selftest.content) | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.tempdir) | ||
|
||
def test_prettify(self): | ||
|
||
# call prettify, the return value should be 0 (OK) | ||
self.assertEqual(main([sys.argv[0], self.fname]), 0) | ||
|
||
# check if file was altered (it shouldn't) | ||
with open(self.fname) as fhandle: | ||
result = fhandle.read() | ||
|
||
self.assertEqual(result.splitlines(), selftest.content.splitlines()) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |