diff --git a/swh/graph/tests/test_cli.py b/swh/graph/tests/test_cli.py new file mode 100644 index 0000000..7e24e0e --- /dev/null +++ b/swh/graph/tests/test_cli.py @@ -0,0 +1,50 @@ +# Copyright (C) 2019 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import unittest + +from pathlib import Path +from tempfile import TemporaryDirectory +from typing import Dict + +from click.testing import CliRunner + +import swh.graph + +from swh.graph import cli + + +def read_properties(properties_fname) -> Dict[str, str]: + """read a Java .properties file""" + properties = {} + with open(properties_fname) as f: + for line in f: + if line.startswith('#'): + continue + (key, value) = line.rstrip().split('=', maxsplit=1) + properties[key] = value + + return properties + + +class TestCompress(unittest.TestCase): + + DATA_DIR = Path(swh.graph.__file__).parent.parent.parent \ + / 'tests' / 'dataset' + + def setUp(self): + self.runner = CliRunner() + + def test_pipeline(self): + """run full compression pipeline""" + with TemporaryDirectory(suffix='.swh-graph-test') as tmpdir: + result = self.runner.invoke( + cli.compress, + ['--graph', self.DATA_DIR / 'example', '--outdir', tmpdir]) + + self.assertEqual(result.exit_code, 0) + properties = read_properties(Path(tmpdir) / 'example.properties') + self.assertEqual(int(properties['nodes']), 21) + self.assertEqual(int(properties['arcs']), 23)