2015-10-26 17:11:36 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import unittest
|
2015-10-27 14:53:33 +01:00
|
|
|
import os
|
2015-11-03 11:12:29 +01:00
|
|
|
import sys
|
2015-10-27 10:23:04 +01:00
|
|
|
|
|
|
|
from bin.specific import KittenGroomerSpec
|
2015-10-27 10:50:46 +01:00
|
|
|
from bin.pier9 import KittenGroomerPier9
|
|
|
|
from bin.generic import KittenGroomer
|
2015-11-03 11:54:38 +01:00
|
|
|
|
|
|
|
if sys.version_info.major == 2:
|
|
|
|
from bin.filecheck import KittenGroomerFileCheck
|
2015-10-26 17:11:36 +01:00
|
|
|
|
2015-10-27 14:10:56 +01:00
|
|
|
from kittengroomer import FileBase
|
|
|
|
|
2015-10-26 17:11:36 +01:00
|
|
|
|
|
|
|
class TestBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.maxDiff = None
|
2015-10-27 14:53:33 +01:00
|
|
|
self.curpath = os.getcwd()
|
2015-10-26 17:11:36 +01:00
|
|
|
|
2015-11-04 11:06:57 +01:00
|
|
|
def dump_logs(self, kg):
|
|
|
|
print(open(kg.log_processing, 'rb').read().decode("utf-8"))
|
|
|
|
if kg.debug:
|
|
|
|
if os.path.exists(kg.log_debug_err):
|
|
|
|
print(open(kg.log_debug_err, 'rb').read().decode("utf-8"))
|
|
|
|
if os.path.exists(kg.log_debug_out):
|
|
|
|
print(open(kg.log_debug_out, 'rb').read().decode("utf-8"))
|
2015-11-03 18:26:12 +01:00
|
|
|
|
2015-10-27 16:51:03 +01:00
|
|
|
def test_specific_valid(self):
|
|
|
|
src = os.path.join(self.curpath, 'tests/src2')
|
|
|
|
dst = os.path.join(self.curpath, 'tests/dst')
|
2015-11-04 11:06:57 +01:00
|
|
|
spec = KittenGroomerSpec(src, dst, debug=True)
|
2015-10-27 16:51:03 +01:00
|
|
|
spec.processdir()
|
2015-11-04 11:06:57 +01:00
|
|
|
self.dump_logs(spec)
|
2015-10-27 16:51:03 +01:00
|
|
|
|
|
|
|
def test_specific_invalid(self):
|
2015-10-27 14:53:33 +01:00
|
|
|
src = os.path.join(self.curpath, 'tests/src')
|
|
|
|
dst = os.path.join(self.curpath, 'tests/dst')
|
2015-11-04 11:06:57 +01:00
|
|
|
spec = KittenGroomerSpec(src, dst, debug=True)
|
2015-10-27 10:23:04 +01:00
|
|
|
spec.processdir()
|
2015-11-04 11:06:57 +01:00
|
|
|
self.dump_logs(spec)
|
2015-10-27 10:50:46 +01:00
|
|
|
|
|
|
|
def test_pier9(self):
|
2015-10-27 14:53:33 +01:00
|
|
|
src = os.path.join(self.curpath, 'tests/src')
|
|
|
|
dst = os.path.join(self.curpath, 'tests/dst')
|
2015-11-04 11:06:57 +01:00
|
|
|
spec = KittenGroomerPier9(src, dst, debug=True)
|
2015-10-27 10:50:46 +01:00
|
|
|
spec.processdir()
|
2015-11-04 11:06:57 +01:00
|
|
|
self.dump_logs(spec)
|
2015-10-27 10:50:46 +01:00
|
|
|
|
|
|
|
def test_generic(self):
|
2015-11-05 17:37:01 +01:00
|
|
|
src = os.path.join(self.curpath, 'tests/src2')
|
2015-10-27 14:53:33 +01:00
|
|
|
dst = os.path.join(self.curpath, 'tests/dst')
|
2015-11-04 11:06:57 +01:00
|
|
|
spec = KittenGroomer(src, dst, debug=True)
|
2015-10-27 10:50:46 +01:00
|
|
|
spec.processdir()
|
2015-11-04 11:06:57 +01:00
|
|
|
self.dump_logs(spec)
|
2015-10-27 14:10:56 +01:00
|
|
|
|
2015-11-03 11:12:29 +01:00
|
|
|
def test_filecheck(self):
|
|
|
|
if sys.version_info.major >= 3:
|
|
|
|
return
|
|
|
|
src = os.path.join(self.curpath, 'tests/src')
|
|
|
|
dst = os.path.join(self.curpath, 'tests/dst')
|
2015-11-04 11:06:57 +01:00
|
|
|
spec = KittenGroomerFileCheck(src, dst, debug=True)
|
2015-11-03 11:12:29 +01:00
|
|
|
spec.processdir()
|
2015-11-04 11:06:57 +01:00
|
|
|
self.dump_logs(spec)
|
2015-11-03 11:12:29 +01:00
|
|
|
|
2015-10-27 14:10:56 +01:00
|
|
|
def test_help_file(self):
|
|
|
|
f = FileBase('tests/src/blah.conf', 'tests/dst/blah.conf')
|
|
|
|
f.make_unknown()
|
|
|
|
f.make_binary()
|
|
|
|
f.make_unknown()
|
|
|
|
f.make_dangerous()
|
|
|
|
f.make_binary()
|
|
|
|
f.make_dangerous()
|