From 3d88dba3ed70c8511ae307aa905b72db8396af75 Mon Sep 17 00:00:00 2001 From: Evgeny Medvedev Date: Fri, 9 Nov 2018 02:16:46 +0700 Subject: [PATCH] Example cli test --- ethereumetl/cli/get_block_range_for_date.py | 9 ++++----- tests/ethereumetl/service/test_eth_service.py | 10 ++++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ethereumetl/cli/get_block_range_for_date.py b/ethereumetl/cli/get_block_range_for_date.py index 986a8e57d..4715a6e91 100644 --- a/ethereumetl/cli/get_block_range_for_date.py +++ b/ethereumetl/cli/get_block_range_for_date.py @@ -21,15 +21,14 @@ # SOFTWARE. -import click - from datetime import datetime + +import click from web3 import Web3 -from ethereumetl.file_utils import smart_open from ethereumetl.logging_utils import logging_basic_config -from ethereumetl.service.eth_service import EthService from ethereumetl.providers.auto import get_provider_from_uri +from ethereumetl.service.eth_service import EthService logging_basic_config() @@ -49,5 +48,5 @@ def get_block_range_for_date(provider_uri, date, output): start_block, end_block = eth_service.get_block_range_for_date(date) - with smart_open(output, 'w') as output_file: + with click.open_file(output, 'w') as output_file: output_file.write('{},{}\n'.format(start_block, end_block)) diff --git a/tests/ethereumetl/service/test_eth_service.py b/tests/ethereumetl/service/test_eth_service.py index 97f12d4c0..ffe4c519b 100644 --- a/tests/ethereumetl/service/test_eth_service.py +++ b/tests/ethereumetl/service/test_eth_service.py @@ -22,9 +22,11 @@ import pytest +from click.testing import CliRunner from dateutil.parser import parse from web3 import HTTPProvider, Web3 +from ethereumetl.cli import get_block_range_for_date from ethereumetl.service.eth_service import EthService from ethereumetl.service.graph_operations import OutOfBoundsError from tests.helpers import skip_if_slow_tests_disabled @@ -39,10 +41,10 @@ ('2018-06-10', 5761663, 5767303) ]) def test_get_block_range_for_date(date, expected_start_block, expected_end_block): - eth_service = get_new_eth_service() - parsed_date = parse(date) - blocks = eth_service.get_block_range_for_date(parsed_date) - assert blocks == (expected_start_block, expected_end_block) + runner = CliRunner() + result = runner.invoke(get_block_range_for_date, ['--date', date]) + assert 0 == result.exit_code + assert '{},{}\n'.format(expected_start_block, expected_end_block) == result.output @skip_if_slow_tests_disabled