aboutsummaryrefslogtreecommitdiffstats
path: root/test/apps/test_main.py
blob: ae19b5eab3f0eafd50c8341d3b41909bc271f07f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""

Part of the bsfs test suite.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# imports
import contextlib
import io
import json
import unittest

# objects to test
from bsfs.apps import main


## code ##

class TestMain(unittest.TestCase):
    def test_main(self):
        # must at least pass an app
        with contextlib.redirect_stderr(io.StringIO()):
            self.assertRaises(SystemExit, main, [])
        # app takes over
        with contextlib.redirect_stderr(io.StringIO()):
            self.assertRaises(SystemExit, main, ['init'])
        outbuf = io.StringIO()
        with contextlib.redirect_stdout(outbuf):
            main(['init', 'sparql'])
        self.assertEqual(json.loads(outbuf.getvalue()), {
            'Graph': {
                'user': 'http://example.com/me',
                'backend': {
                    'SparqlStore': {}}}})


## main ##

if __name__ == '__main__':
    unittest.main()

## EOF ##