Giter VIP home page Giter VIP logo

elasticsearch-test-py's Introduction

Python Elasticsearch Test

Start Elasticsearch using Python.

Settings

elasticsearch_test.ElasticsearchTest(
  port=1234
  es_path='/home/maria/elasticsearch-5.2.4'
  data_dir='/home/maria/es-data'
  es_java_opts='-Xms512m -Xmx512m'
)

port

Default: 9200

es_path

Path to the Elasticsearch directory (home of /bin). Default: uses $ES_HOME

es_java_opts

Sets $ES_JAVA_OPTS for process to this value if present.

data_dir

Directory to place /data and /logs in. Default: uses tempfile.

Running

import time
import elasticsearch_test
instance = elasticsearch_test.ElasticsearchTest()

# This blocks until either an error is found
# or Elasticsearch has been initialized.

instance.start()

# or

instance.start(block=False)

while True:
    if instance.is_started():
        break
    time.sleep(1)

Testing

Use it as a resource::

import elasticsearch_test
import elasticsearch

with elasticsearch_test.ElasticsearchTest() as instance:
    connection_info = instance.get_connection_info()
    client = elasticsearch.Elasticsearch(connection_info)

Use it as a Pytest fixture::

import elasticsearch_test

@pytest.fixture(scope="session")
def es():
    instance = elasticsearch_test.ElasticsearchTest()
    instance.start()
    yield instance
    instance.stop()

When using data_dir, if there are preexisting data in the directory, you should also wait for the data to be initialized::

with elasticsearch_test.ElasticsearchTest(data_dir='my_data') as instance:
    while not instance.is_data_initialized():
        time.sleep(1)
    # do something!

Test this package

Needed: pyenv and the plugin pyenv-virtualenv.

  1. Create a normal virtualenv and activate it

  2. Install extras pip install .[testing]

  3. Install the needed Python versions using pyenv: 3.4, 3.5, 3.6, 3.7

  4. Setup virtualenvs for all but the Python version you are using, for example if you use 3.4

    $ pyenv virtualenv -p python3.5 3.5.6 py35
    $ pyenv virtualenv -p python3.6 3.6.6 py36
    $ pyenv virtualenv -p python3.7 3.7.1 py37
    
  5. Activate everything and run tox:

    $ pyenv shell py35 py36 py37
    $ source ./venv/bin/activate
    $ tox
    

elasticsearch-test-py's People

Contributors

majsan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.