Ejemplo n.º 1
0
def test_analyze_handler_exits_when_infile_does_not_exist():
    with tempfile.NamedTemporaryFile() as f:
        inpath = f.name
    args = cli.parse_args(
        [cli.ANALYZE, '-i', inpath, '-o', OUTPATH, '-s', 'root'])
    with pytest.raises(SystemExit):
        cli.handle_parsed_args(args)
Ejemplo n.º 2
0
def test_fill_handler(mocker):
    args = cli.parse_args(
        [cli.FILL, '-q', QUESTIONS_XML, '-a', ANSWERS_XML, '-c', COMMENTS_XML])
    mocker.patch('analyzer.migrate_data.fill_database', autospec=True)
    cli.handle_parsed_args(args)
    analyzer.migrate_data.fill_database.assert_called_once_with(
        QUESTIONS_XML, ANSWERS_XML, COMMENTS_XML, None)
Ejemplo n.º 3
0
def test_csv_handler_for_comments(mocker):
    args = cli.parse_args(
        [cli.GENERATE_CSV, '-n', NUM, '-o', OUTPATH, '-c', '-t', TAG])
    mocker.patch('analyzer.util.generate_comments_csv', autospec=True)
    cli.handle_parsed_args(args)
    analyzer.util.generate_comments_csv.assert_called_once_with(
        int(NUM), OUTPATH, TAG)
Ejemplo n.º 4
0
def test_analyze_handler_exits_when_rpf_too_small():
    rpf = "0"
    with tempfile.NamedTemporaryFile() as f:
        inpath = f.name
        args = cli.parse_args([
            cli.ANALYZE, '-i', inpath, '-o', OUTPATH, '-s', 'root', '-rpf', rpf
        ])
        with pytest.raises(SystemExit):
            cli.handle_parsed_args(args)
Ejemplo n.º 5
0
def test_csv_handler_for_questions(mocker):
    args = cli.parse_args(
        [cli.GENERATE_CSV, '-n', NUM, '-o', OUTPATH, '-q', '-t', TAG])
    mocker.patch('analyzer.util.generate_posts_csv', autospec=True)
    cli.handle_parsed_args(args)
    analyzer.util.generate_posts_csv.assert_called_once_with(
        num_posts=int(NUM),
        outpath=OUTPATH,
        post_type=database.PostType.QUESTION,
        tag=TAG)
Ejemplo n.º 6
0
def test_plot_handler_population_file_key_error():
    with tempfile.NamedTemporaryFile() as f:
        inpath = f.name
        alpha = .5
        width = 100

        args = cli.parse_args([
            cli.PLOT, '-i', inpath, '-i', inpath, '-o', OUTPATH, '-a',
            str(alpha), '-w',
            str(width), '-pop', TEST_POPULATION_JSON
        ])
        with pytest.raises(KeyError):
            cli.handle_parsed_args(args)
Ejemplo n.º 7
0
def test_plot_handler_population_file_dont_exist():
    with tempfile.NamedTemporaryFile() as f:
        inpath = f.name
        alpha = .5
        width = 100
        population = 'empty.json'

        args = cli.parse_args([
            cli.PLOT, '-i', inpath, '-i', inpath, '-o', OUTPATH, '-a',
            str(alpha), '-w',
            str(width), '-pop', population
        ])
        with pytest.raises(SystemExit):
            cli.handle_parsed_args(args)
Ejemplo n.º 8
0
def test_plot_handler_correct_population_file():
    inpath = os.path.abspath(
        os.path.join(os.path.dirname(__file__),
                     'sanitized_comments_predictions.csv'))
    alpha = .5
    width = 100
    out = 'plot'

    args = cli.parse_args([
        cli.PLOT, '-i', inpath, '-o', out, '-a',
        str(alpha), '-w',
        str(width), '-pop', TEST_POPULATION_JSON
    ])
    cli.handle_parsed_args(args)
    assert os.path.isfile(f'{out}.svg')
Ejemplo n.º 9
0
def test_analyze_handler(mocker, monkeypatch):
    sentiroot = 'root'
    rpf = "2000"
    with tempfile.NamedTemporaryFile() as f:
        inpath = f.name
        args = cli.parse_args([
            cli.ANALYZE, '-i', inpath, '-o', OUTPATH, '-s', sentiroot, '-rpf',
            rpf
        ])
        mocker.patch('analyzer.classify.classify_sentiment', autospec=True)
        monkeypatch.setattr('os.path.abspath', lambda x: x)
        cli.handle_parsed_args(args)

    analyzer.classify.classify_sentiment.assert_called_once_with(
        int(rpf), os.path.abspath(sentiroot), inpath, OUTPATH)
Ejemplo n.º 10
0
def test_plot_handler_no_population_given(mocker):
    with tempfile.NamedTemporaryFile() as f:
        inpath = f.name
        alpha = .5
        width = 100
        args = cli.parse_args([
            cli.PLOT, '-i', inpath, '-i', inpath, '-o', OUTPATH, '-a',
            str(alpha), '-w',
            str(width)
        ])
        mocker.patch('analyzer.stats.plot_predictions', autospec=True)
        cli.handle_parsed_args(args)
    analyzer.stats.plot_predictions.assert_called_once_with([inpath, inpath],
                                                            alpha, OUTPATH,
                                                            width, False,
                                                            False, None)
Ejemplo n.º 11
0
def test_teardown_handler(mocker):
    args = cli.parse_args([cli.TEARDOWN])
    mocker.patch('analyzer.database.teardown_database', autospec=True)
    cli.handle_parsed_args(args)
    analyzer.database.teardown_database.assert_called_once_with(
        analyzer.database.Driver.DEV)
Ejemplo n.º 12
0
def main():
    args = cli.parse_args(sys.argv[1:])
    cli.handle_parsed_args(args)