newfol/test/testgit.py
brian m. carlson eb67121630
Test what files are checked in to git.
As well as testing that all files are checked into git when using git
transactions, test that the files actually checked in are exactly the
expected ones.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
2014-02-01 03:16:00 +00:00

43 lines
1.4 KiB
Python
Executable file

#!/usr/bin/python3
import newfol.database
import os
import subprocess
import tempfile
import unittest
class TestGitTransactions(unittest.TestCase):
def setUp(self):
self.tempdir = tempfile.TemporaryDirectory()
fp = open(self.tempdir.name + "/schema", "w")
print("fmt:0:newfol schema file", file=fp)
print("txn:git", file=fp)
fp.close()
def test_all_checked_in(self):
db = newfol.database.Database.load(self.tempdir.name)
db.store()
curdir = os.getcwd()
os.chdir(self.tempdir.name)
output = ""
with subprocess.Popen(["git", "status", "--porcelain"],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) as proc:
output = proc.stdout.read()
os.chdir(curdir)
self.assertEqual(output, b"")
def test_files_checked_in(self):
db = newfol.database.Database.load(self.tempdir.name)
db.store()
curdir = os.getcwd()
os.chdir(self.tempdir.name)
output = ""
with subprocess.Popen(["git", "ls-files"],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) as proc:
output = proc.stdout.read().decode()
os.chdir(curdir)
expected = "".join(map(lambda x: "%s\n" % x,
['dtb', 'dtb.checksum', 'schema']))
self.assertEqual(output, expected)
if __name__ == '__main__':
unittest.main()