test_elastic_import()   B
last analyzed

Complexity

Conditions 5

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 29
rs 8.0894
cc 5
1
import nose.tools as nt
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Configuration introduced by
The import nose.tools could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2
import logging
3
4
from topik.fileio.in_elastic import read_elastic
5
from topik.fileio.project import TopikProject
6
from topik.fileio.tests import test_data_path
7
from ._solutions import solution_elastic
8
from elasticsearch.exceptions import ConnectionError
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in ConnectionError.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Configuration introduced by
The import elasticsearch.exceptions could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
9
from nose.plugins.skip import SkipTest
0 ignored issues
show
Configuration introduced by
The import nose.plugins.skip could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
10
11
INDEX = "test_elastic"
12
13
# make logging quiet during testing, to keep Travis CI logs short.
14
15
logging.basicConfig()
16
logging.getLogger('elasticsearch').setLevel(logging.ERROR)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable logging does not seem to be defined.
Loading history...
17
logging.getLogger('urllib3').setLevel(logging.ERROR)
18
19
20
def test_elastic_import():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
21
    output_args = {'source': 'localhost',
22
                   'index': INDEX,
23
                   'content_field': 'abstract'}
24
    # import data from file into known elastic server
25
    project = TopikProject("test_project", output_type='ElasticSearchOutput',
26
                           output_args=output_args)
27
28
    try:
29
        project.read_input('{}/test_data_json_stream.json'.format(
30
                   test_data_path), content_field="abstract")#,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable test_data_path does not seem to be defined.
Loading history...
31
               #output_type=elastic.ElasticSearchOutput.class_key(),
32
               #output_args=output_args, synchronous_wait=30)
33
    except ConnectionError:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable ConnectionError does not seem to be defined.
Loading history...
34
        raise SkipTest("Skipping Elasticsearch test - elasticsearch not running")
35
36
    loaded_corpus = read_elastic("localhost", index=INDEX)
37
    solution_found = False
38
    for doc in list(iter(loaded_corpus)):
39
        if solution_elastic == doc['abstract']:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable solution_elastic does not seem to be defined.
Loading history...
40
            solution_found = True
41
            break
42
    nt.assert_true(solution_found)
43
44
    # tear-down
45
    from elasticsearch import Elasticsearch
46
    instance = Elasticsearch("localhost")
47
    if instance.indices.exists(INDEX):
48
        instance.indices.delete(INDEX)
49
50