BaseOutputTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 7
Bugs 3 Features 2
Metric Value
wmc 4
c 7
b 3
f 2
dl 0
loc 27
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_load_file() 0 6 1
A test_save_file() 0 4 1
A test_get_date_filtered_data() 0 7 1
A test_get_filtered_data() 0 4 1
1
import os
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...
2
import unittest
3
import logging
4
import elasticsearch
5
6
from topik.fileio.base_output import load_output
7
from topik.fileio.reader import read_input
8
from topik.fileio.tests import test_data_path
9
from topik.fileio.out_elastic import ElasticSearchOutput
10
from topik.fileio.out_memory import InMemoryOutput
11
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...
12
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...
13
14
INDEX = "topik_unittest"
15
SAVE_FILENAME = "test_save.topikdata"
16
CONTENT_FIELD = "abstract"
17
18
# make logging quiet during testing, to keep Travis CI logs short.
19
20
logging.basicConfig()
21
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...
22
logging.getLogger('urllib3').setLevel(logging.ERROR)
23
24
25
class BaseOutputTest(object):
0 ignored issues
show
Coding Style introduced by
This class 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...
Comprehensibility Best Practice introduced by
The variable object does not seem to be defined.
Loading history...
26
    test_raw_data = None
27
28
    def test_get_filtered_data(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
29
        data = list(self.test_raw_data.get_filtered_data(CONTENT_FIELD))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable CONTENT_FIELD does not seem to be defined.
Loading history...
30
        self.assertEqual(len(data), 100)
0 ignored issues
show
Bug introduced by
The Instance of BaseOutputTest does not seem to have a member named assertEqual.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Comprehensibility Best Practice introduced by
The variable data does not seem to be defined.
Loading history...
31
        self.assertFalse(data[0] == data[1])
0 ignored issues
show
Bug introduced by
The Instance of BaseOutputTest does not seem to have a member named assertFalse.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
32
33
    def test_save_file(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
34
        self.test_raw_data.save(SAVE_FILENAME)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable SAVE_FILENAME does not seem to be defined.
Loading history...
35
        self.assertTrue(os.path.exists(SAVE_FILENAME))
0 ignored issues
show
Bug introduced by
The Instance of BaseOutputTest does not seem to have a member named assertTrue.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
36
        os.remove(SAVE_FILENAME)
37
38
    def test_load_file(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
39
        self.test_raw_data.save(SAVE_FILENAME)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable SAVE_FILENAME does not seem to be defined.
Loading history...
40
        self.test_raw_data = load_output(SAVE_FILENAME)
41
        data = list(self.test_raw_data.get_filtered_data(CONTENT_FIELD))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable CONTENT_FIELD does not seem to be defined.
Loading history...
42
        self.assertEqual(len(data), 100)
0 ignored issues
show
Bug introduced by
The Instance of BaseOutputTest does not seem to have a member named assertEqual.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Comprehensibility Best Practice introduced by
The variable data does not seem to be defined.
Loading history...
43
        os.remove(SAVE_FILENAME)
44
45
    def test_get_date_filtered_data(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
46
        result_list = list(self.test_raw_data.get_date_filtered_data(field_to_get=CONTENT_FIELD,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable CONTENT_FIELD does not seem to be defined.
Loading history...
47
                                                                     start=1975,
48
                                                                     end=1999,
49
                                                                     filter_field="year"))
50
        self.assertEqual(len(result_list), 25)
0 ignored issues
show
Bug introduced by
The Instance of BaseOutputTest does not seem to have a member named assertEqual.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Comprehensibility Best Practice introduced by
The variable result_list does not seem to be defined.
Loading history...
51
        self.assertTrue(-1611117933394825767 in [int(item[0]) for item in
0 ignored issues
show
Bug introduced by
The Instance of BaseOutputTest does not seem to have a member named assertTrue.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
52
                        result_list])
53
54
55
class TestInMemoryOutput(unittest.TestCase, BaseOutputTest):
0 ignored issues
show
Coding Style introduced by
This class 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...
Comprehensibility Best Practice introduced by
The variable unittest does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable BaseOutputTest does not seem to be defined.
Loading history...
56
    def setUp(self):
57
        self.test_raw_data = InMemoryOutput()
58
        self.test_raw_data.import_from_iterable(read_input(
59
            '{}/test_data_json_stream.json'.format(test_data_path)),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable test_data_path does not seem to be defined.
Loading history...
60
            field_to_hash=CONTENT_FIELD)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable CONTENT_FIELD does not seem to be defined.
Loading history...
61
62
63
class TestElasticSearchOutput(unittest.TestCase, BaseOutputTest):
0 ignored issues
show
Coding Style introduced by
This class 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...
Comprehensibility Best Practice introduced by
The variable unittest does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable BaseOutputTest does not seem to be defined.
Loading history...
64
    def setUp(self):
65
        self.test_raw_data = ElasticSearchOutput(
66
            source='localhost',
67
            index=INDEX,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable INDEX does not seem to be defined.
Loading history...
68
            content_field='abstract'
69
        )
70
        try:
71
            self.test_raw_data.import_from_iterable(read_input(
72
                '{}/test_data_json_stream.json'.format(test_data_path)),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable test_data_path does not seem to be defined.
Loading history...
73
                field_to_hash=CONTENT_FIELD)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable CONTENT_FIELD does not seem to be defined.
Loading history...
74
75
        except ConnectionError:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable ConnectionError does not seem to be defined.
Loading history...
76
            raise SkipTest("Skipping Elasticsearch test - elasticsearch not running")
77
78
    def tearDown(self):
79
        instance = elasticsearch.Elasticsearch("localhost")
80
        instance.indices.delete(INDEX)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable INDEX does not seem to be defined.
Loading history...
81
        if instance.indices.exists("{}_year_alias_date".format(INDEX)):
82
            instance.indices.delete("{}_year_alias_date".format(INDEX))
83
84