mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-16 21:24:10 +00:00
adding binaries in tests
This commit is contained in:
@@ -36,13 +36,19 @@ def get_tempfolder():
|
|||||||
return tempfile.mkdtemp(suffix=TMPSUFFIX)
|
return tempfile.mkdtemp(suffix=TMPSUFFIX)
|
||||||
|
|
||||||
|
|
||||||
def create_random_file(folder, content=None):
|
def create_random_file(folder, content=None, binary=False):
|
||||||
'''Create a new file in folder with random content.'''
|
'''Create a new file in folder with random content.'''
|
||||||
fname = get_string(8)
|
fname = get_string(8)
|
||||||
|
mode = 'w'
|
||||||
|
if binary:
|
||||||
|
mode = 'wb'
|
||||||
if content is None:
|
if content is None:
|
||||||
|
if binary:
|
||||||
|
content = bytes(get_string(100), 'ascii')
|
||||||
|
else:
|
||||||
content = get_string(100)
|
content = get_string(100)
|
||||||
path = os.path.join(folder, fname)
|
path = os.path.join(folder, fname)
|
||||||
with open(path, 'w') as f:
|
with open(path, mode) as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
return path, content
|
return path, content
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,11 @@ class TestCompare(unittest.TestCase):
|
|||||||
results[path] = diffval
|
results[path] = diffval
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def edit_content(self, path, newcontent):
|
def edit_content(self, path, newcontent, binary=False):
|
||||||
with open(path, 'w') as f:
|
mode = 'w'
|
||||||
|
if binary:
|
||||||
|
mode = 'wb'
|
||||||
|
with open(path, mode) as f:
|
||||||
f.write(newcontent)
|
f.write(newcontent)
|
||||||
|
|
||||||
def test_compare(self):
|
def test_compare(self):
|
||||||
@@ -74,6 +77,8 @@ class TestCompare(unittest.TestCase):
|
|||||||
self.addCleanup(clean, d2)
|
self.addCleanup(clean, d2)
|
||||||
d3, c3 = create_random_file(fold_tmp)
|
d3, c3 = create_random_file(fold_tmp)
|
||||||
self.addCleanup(clean, d3)
|
self.addCleanup(clean, d3)
|
||||||
|
d4, c4 = create_random_file(fold_tmp, binary=True)
|
||||||
|
self.addCleanup(clean, d4)
|
||||||
|
|
||||||
# create the config file
|
# create the config file
|
||||||
profile = get_string(5)
|
profile = get_string(5)
|
||||||
@@ -84,27 +89,33 @@ class TestCompare(unittest.TestCase):
|
|||||||
create=self.CONFIG_CREATE)
|
create=self.CONFIG_CREATE)
|
||||||
self.assertTrue(os.path.exists(confpath))
|
self.assertTrue(os.path.exists(confpath))
|
||||||
conf, opts = load_config(confpath, self.CONFIG_DOTPATH, profile)
|
conf, opts = load_config(confpath, self.CONFIG_DOTPATH, profile)
|
||||||
dfiles = [d1, d2, d3]
|
dfiles = [d1, d2, d3, d4]
|
||||||
|
|
||||||
# import the files
|
# import the files
|
||||||
importer(opts, conf, dfiles)
|
importer(opts, conf, dfiles)
|
||||||
conf, opts = load_config(confpath, self.CONFIG_DOTPATH, profile)
|
conf, opts = load_config(confpath, self.CONFIG_DOTPATH, profile)
|
||||||
|
|
||||||
# compare the files
|
# compare the files
|
||||||
expected = {d1: True, d2: True, d3: True}
|
expected = {d1: True, d2: True, d3: True, d4: True}
|
||||||
results = self.compare(opts, conf, tmp, len(dfiles))
|
results = self.compare(opts, conf, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify file
|
# modify file
|
||||||
self.edit_content(d1, get_string(20))
|
self.edit_content(d1, get_string(20))
|
||||||
expected = {d1: False, d2: True, d3: True}
|
expected = {d1: False, d2: True, d3: True, d4: True}
|
||||||
|
results = self.compare(opts, conf, tmp, len(dfiles))
|
||||||
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
|
# modify binary file
|
||||||
|
self.edit_content(d4, bytes(get_string(20), 'ascii'), binary=True)
|
||||||
|
expected = {d1: False, d2: True, d3: True, d4: False}
|
||||||
results = self.compare(opts, conf, tmp, len(dfiles))
|
results = self.compare(opts, conf, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify all files
|
# modify all files
|
||||||
self.edit_content(d2, get_string(20))
|
self.edit_content(d2, get_string(20))
|
||||||
self.edit_content(d3, get_string(21))
|
self.edit_content(d3, get_string(21))
|
||||||
expected = {d1: False, d2: False, d3: False}
|
expected = {d1: False, d2: False, d3: False, d4: False}
|
||||||
results = self.compare(opts, conf, tmp, len(dfiles))
|
results = self.compare(opts, conf, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user