aboutsummaryrefslogtreecommitdiffstats
path: root/test/apps/test_main.py
blob: 4fa094bf11b865435cd4cc4a909b96ad7f352cf8 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

# standard imports
import contextlib
import io
import json
import os
import tempfile
import unittest
import yaml

# objects to test
from bsie.apps import main


## code ##

class TestMain(unittest.TestCase):
    def setUp(self):
        config = {
            'ReaderBuilder': {},
            'ExtractorBuilder': [
                {'bsie.extractor.generic.stat.Stat': {}},
                {'bsie.extractor.generic.path.Path': {}},
                ]
            }
        # create config file
        _, self.config_path = tempfile.mkstemp(prefix='bsie-test-', suffix='.yaml')
        with open(self.config_path, 'wt') as cfile:
            yaml.dump(config, cfile)

    def tearDown(self):
        if os.path.exists(self.config_path):
            os.unlink(self.config_path)

    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, ['info'])
        outbuf = io.StringIO()
        with contextlib.redirect_stdout(outbuf):
            main(['info', '--config', self.config_path, 'predicates'])
        self.assertEqual(set(outbuf.getvalue().strip().split('\n')), {
            'https://schema.bsfs.io/ie/Node/Entity#filename',
            'https://schema.bsfs.io/ie/Node/Entity#filesize',
            'https://schema.bsfs.io/core/Predicate',
            })


## main ##

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

## EOF ##