-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 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
Empty file.
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,16 @@ | ||
from os.path import join, realpath, dirname | ||
from tempfile import TemporaryDirectory | ||
|
||
CIMBAR_SRC = realpath(join(dirname(realpath(__file__)), '..', '..')) | ||
BIN_DIR = join(CIMBAR_SRC, 'dist', 'bin') | ||
|
||
|
||
class TestDirMixin(): | ||
def setUp(self): | ||
self.working_dir = TemporaryDirectory() | ||
super().setUp() | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
with self.working_dir: | ||
pass |
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,88 @@ | ||
import subprocess | ||
from os.path import join as path_join, getsize | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
|
||
from helpers import TestDirMixin, CIMBAR_SRC, BIN_DIR | ||
|
||
|
||
CIMBAR_EXE = path_join(BIN_DIR, 'cimbar') | ||
|
||
|
||
def _get_command(*args): | ||
cmd = [CIMBAR_EXE] | ||
for arg in args: | ||
if isinstance(arg, str): | ||
cmd += arg.split(' ') | ||
else: | ||
cmd += arg | ||
return cmd | ||
|
||
# look in dist/bin/ for executables | ||
# run them, confirm a few boring command results against samples(?) | ||
# at the very least, confirm a roundtrip and cli options.... | ||
|
||
|
||
class CimbarCliTest(TestDirMixin, TestCase): | ||
def test_roundtrip_oneshot(self): | ||
# encode | ||
infile = path_join(CIMBAR_SRC, 'LICENSE') | ||
outprefix = path_join(self.working_dir.name, 'img') | ||
cmd = _get_command('--encode -i', infile, '-o', outprefix) | ||
|
||
res = subprocess.run(cmd, capture_output=True) | ||
self.assertEqual(0, res.returncode) | ||
|
||
encoded_img = f'{outprefix}_0.png' | ||
self.assertTrue(getsize(encoded_img) > 30000) | ||
|
||
# decode | ||
cmd = _get_command('-i', encoded_img, '-o', self.working_dir.name) | ||
res = subprocess.run(cmd, capture_output=True) | ||
self.assertEqual(0, res.returncode) | ||
|
||
# filename in stdout | ||
decoded_file = res.stdout.strip().decode('utf-8') | ||
self.assertTrue(self.working_dir.name in decoded_file) | ||
|
||
with open(infile) as r: | ||
expected = r.read() | ||
with open(decoded_file) as r: | ||
actual = r.read() | ||
|
||
self.assertEqual(expected, actual) | ||
|
||
def test_roundtrip_stdin(self): | ||
# encode | ||
infile = path_join(CIMBAR_SRC, 'LICENSE') | ||
outprefix = path_join(self.working_dir.name, 'img') | ||
cmd = _get_command('--encode -o', outprefix) | ||
|
||
res = subprocess.run( | ||
cmd, input=infile.encode('utf-8'), capture_output=True | ||
) | ||
|
||
self.assertEqual(0, res.returncode) | ||
|
||
encoded_img = f'{outprefix}_0.png' | ||
self.assertTrue(getsize(encoded_img) > 30000) | ||
|
||
# decode defaults to cwd -- which should be self.working_dir | ||
cmd = _get_command() | ||
res = subprocess.run( | ||
cmd, input=encoded_img.encode('utf-8'), capture_output=True, | ||
cwd=self.working_dir.name, | ||
) | ||
self.assertEqual(0, res.returncode) | ||
|
||
# filename in stdout | ||
decoded_file = res.stdout.strip().decode('utf-8') | ||
self.assertTrue(self.working_dir.name in decoded_file) | ||
|
||
with open(infile) as r: | ||
expected = r.read() | ||
with open(decoded_file) as r: | ||
actual = r.read() | ||
|
||
self.assertEqual(expected, actual) | ||
|