TestInMemoryOutput   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 1
c 6
b 2
f 2
dl 0
loc 8
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
1
import glob
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 os
3
import time
4
import unittest
5
6
import elasticsearch
7
import nose.tools as nt
0 ignored issues
show
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...
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
from topik.fileio import TopikProject
12
from topik.fileio.tests import test_data_path
13
14
# make logging quiet during testing, to keep Travis CI logs short.
15
import logging
16
logging.basicConfig()
17
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...
18
logging.getLogger('urllib3').setLevel(logging.ERROR)
19
20
SAVE_FILENAME = "test_project"
21
22
sample_tokenized_doc = (2318580746137828354,
0 ignored issues
show
Coding Style Naming introduced by
The name sample_tokenized_doc does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
23
 [u'nano', u'sized', u'tio', u'particles', u'applications', u'including',
24
  u'use', u'photocatalysts', u'heat', u'transfer', u'fluids', u'nanofluids',
25
  u'present', u'study', u'tio', u'nanoparticles', u'controllable', u'phase',
26
  u'particle', u'size', u'obtained', u'homogeneous', u'gas', u'phase',
27
  u'nucleation', u'chemical', u'vapor', u'condensation', u'cvc', u'phase',
28
  u'particle', u'size', u'tio', u'nanoparticles', u'processing', u'conditions',
29
  u'characterized', u'x', u'ray', u'diffraction', u'transmission', u'electron',
30
  u'microscopy', u'chamber', u'temperature', u'pressure', u'key', u'parameters',
31
  u'affecting', u'particle', u'phase', u'size', u'pure', u'anatase', u'phase',
32
  u'observed', u'synthesis', u'temperatures', u'low', u'c', u'chamber',
33
  u'pressure', u'varying', u'torr', u'furnace', u'temperature', u'increased',
34
  u'c', u'pressure', u'torr', u'mixture', u'anatase', u'rutile', u'phases',
35
  u'observed', u'predominant', u'phase', u'anatase', u'average', u'particle',
36
  u'size', u'experimental', u'conditions', u'observed', u'nm'])
37
38
test_data_path = os.path.join(test_data_path, "test_data_json_stream.json")
0 ignored issues
show
Coding Style Naming introduced by
The name test_data_path does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Comprehensibility Best Practice introduced by
The variable test_data_path does not seem to be defined.
Loading history...
39
40
41
class ProjectTest(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...
42
    def test_context_manager(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...
43
        for filename in glob.glob("context_output*"):
44
            os.remove(filename)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable filename does not seem to be defined.
Loading history...
45
        with TopikProject("context_output", self.output_type, self.output_args) as project:
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named output_type.

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...
Bug introduced by
The Instance of ProjectTest does not seem to have a member named output_args.

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 self does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable project does not seem to be defined.
Loading history...
46
            project.read_input(source=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...
47
            project.tokenize()
48
            project.vectorize(method='bag_of_words')
49
            project.run_model(model_name='lda', ntopics=2)
50
51
        # above runs through a whole workflow (minus plotting.)  At end, it closes file.
52
        # load output here.
53
        with TopikProject("context_output") as project:
54
            nt.assert_equal(len(list(project.get_filtered_corpus_iterator())), 100)
55
            nt.assert_true(sample_tokenized_doc in list(iter(project.selected_tokenized_corpus)))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable sample_tokenized_doc does not seem to be defined.
Loading history...
56
            nt.assert_equal(project.selected_vectorized_corpus.global_term_count, 2434)
57
            nt.assert_equal(len(project.selected_vectorized_corpus), 100)  # All documents processed
58
            for doc in project.selected_modeled_corpus.doc_topic_matrix.values():
59
                nt.assert_almost_equal(sum(doc), 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable doc does not seem to be defined.
Loading history...
60
            for topic in project.selected_modeled_corpus.topic_term_matrix.values():
61
                nt.assert_almost_equal(sum(topic), 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable topic does not seem to be defined.
Loading history...
62
63
        for filename in glob.glob("context_output*"):
64
            os.remove(filename)
65
66
    def test_read_input(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...
67
        nt.assert_equal(len(list(self.project.get_filtered_corpus_iterator())), 100)
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
68
69
    def test_get_filtered_corpus_iterator(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_filtered_corpus_iterator does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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...
70
        doc_list = list(self.project.get_filtered_corpus_iterator())
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
71
        nt.assert_equal(type(doc_list[0]), type(('123', 'text')))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable doc_list does not seem to be defined.
Loading history...
72
        nt.assert_equal(len(doc_list), 100)
73
74
    def test_get_date_filtered_corpus_iterator(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_date_filtered_corpus_iterator does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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...
75
        results = list(self.project.get_date_filtered_corpus_iterator(
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
76
            field_to_get="abstract", start=1975, end=1999, filter_field='year'))
77
        nt.assert_equal(len(results), 25)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable results does not seem to be defined.
Loading history...
78
79
    def test_tokenize(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...
80
        self.project.tokenize('simple')
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
81
        in_results = False
82
        for id, doc in self.project.selected_tokenized_corpus:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
Coding Style Naming introduced by
The name id does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
Unused Code introduced by
The variable id seems to be unused.
Loading history...
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
83
            if doc in sample_tokenized_doc:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable doc does not seem to be defined.
Loading history...
84
                in_results = True
85
                break
86
        nt.assert_true(in_results)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable in_results does not seem to be defined.
Loading history...
87
88
    def test_vectorize(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...
89
        self.project.tokenize()
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
90
        self.project.vectorize()
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
91
        nt.assert_equal(self.project.selected_vectorized_corpus.global_term_count, 2434)
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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 self does not seem to be defined.
Loading history...
92
        nt.assert_equal(len(self.project.selected_vectorized_corpus), 100)  # All documents processed
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
93
94
    def test_model(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...
95
        self.project.tokenize()
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
96
        self.project.vectorize()
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
97
        self.project.run_model(model_name='lda', ntopics=2)
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
98
        for doc in self.project.selected_modeled_corpus.doc_topic_matrix.values():
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
99
            nt.assert_almost_equal(sum(doc), 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable doc does not seem to be defined.
Loading history...
100
        for topic in self.project.selected_modeled_corpus.topic_term_matrix.values():
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
101
            nt.assert_almost_equal(sum(topic), 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable topic does not seem to be defined.
Loading history...
102
103
    def test_visualize(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...
104
        self.project.tokenize()
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
105
        self.project.vectorize(method='bag_of_words')
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
106
        self.project.run_model(ntopics=2)
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
107
        self.project.visualize(vis_name='termite', topn=5)
0 ignored issues
show
Bug introduced by
The Instance of ProjectTest does not seem to have a member named project.

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...
108
109
110
class TestInMemoryOutput(unittest.TestCase, ProjectTest):
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 ProjectTest does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable unittest does not seem to be defined.
Loading history...
111
    def setUp(self):
112
        self.output_type = "InMemoryOutput"
113
        self.output_args = {}
114
        self.project = TopikProject("test_project",
115
                                    output_type=self.output_type,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
116
                                    output_args=self.output_args)
117
        self.project.read_input(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...
118
119
120
class TestElasticSearchOutput(unittest.TestCase, ProjectTest):
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 ProjectTest does not seem to be defined.
Loading history...
121
    INDEX = "test_index"
122
123
    def setUp(self):
124
        self.output_type = "ElasticSearchOutput"
125
        self.output_args = {'source': 'localhost',
126
                            'index': TestElasticSearchOutput.INDEX,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable TestElasticSearchOutput does not seem to be defined.
Loading history...
127
                            'content_field': "abstract"}
128
        self.project = TopikProject("test_project", output_type=self.output_type,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
129
                                    output_args=self.output_args)
130
        try:
131
            self.project.read_input(test_data_path, content_field="abstract", synchronous_wait=30)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable test_data_path does not seem to be defined.
Loading history...
132
        except ConnectionError:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable ConnectionError does not seem to be defined.
Loading history...
133
            raise SkipTest("Skipping Elasticsearch test - elasticsearch not running")
134
135
    def tearDown(self):
136
        instance = elasticsearch.Elasticsearch("localhost")
137
        instance.indices.delete(TestElasticSearchOutput.INDEX)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable TestElasticSearchOutput does not seem to be defined.
Loading history...
138
        if instance.indices.exists("{}_year_alias_date".format(TestElasticSearchOutput.INDEX)):
139
            instance.indices.delete("{}_year_alias_date".format(TestElasticSearchOutput.INDEX))
140
        time.sleep(1)
141