From 7977c130fc6321dad41c82f77cc2e44db6771246 Mon Sep 17 00:00:00 2001 From: Maeva Pourpoint <maeva@passcal.nmt.edu> Date: Fri, 24 Apr 2020 16:29:20 -0600 Subject: [PATCH] added unit tests; tested code against python 2 and 3 using tox; formatted python code using PEP8 style guide; removed config file --- CONTRIBUTING.rst | 3 ++- HISTORY.rst | 3 +-- data2passcal/config.ini | 22 --------------------- data2passcal/config.py | 31 ------------------------------ data2passcal/data2passcal.py | 37 ++++++++++++++++-------------------- setup.py | 8 ++------ tests/test_data2passcal.py | 24 ++++++++++------------- tox.ini | 11 +++++++---- 8 files changed, 38 insertions(+), 101 deletions(-) delete mode 100644 data2passcal/config.ini delete mode 100644 data2passcal/config.py diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b262255..0866d54 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -76,7 +76,8 @@ Ready to contribute? Here's how to set up `data2passcal` for local development. 5. When you're done making changes, check that your changes pass the tests:: - $ python -m pytest + $ python -m unittest (or python -m unittest tests.test_data2passcal under Python2) + 6. Commit your changes and push your branch to GitHub:: $ git add . diff --git a/HISTORY.rst b/HISTORY.rst index d35c92d..966dfb2 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -21,7 +21,6 @@ History 2020.107 (2020-04-16) ------------------ * Added some unit tests to ensure basic functionality of data2passcal -* Created configuration file (.ini file) to store and access ftp and test related variables -* Updated list of platform specific dependencies to be installed when installing data2passcal (see setup.py) +* Updated list of platform specific dependencies to be installed when installing data2passcal in dev mode (see setup.py) * Installed and tested data2passcal against Python2.7 and Python3.6 using tox * Formatted Python code to conform to the PEP8 style guide (exception: E722, E712, E501) diff --git a/data2passcal/config.ini b/data2passcal/config.ini deleted file mode 100644 index 6422e38..0000000 --- a/data2passcal/config.ini +++ /dev/null @@ -1,22 +0,0 @@ -[FTP_INFO] -ftp_ip = 129.138.26.29 -ftp_user = ftp -ftp_password = data2passcal -ftp_send_attempts = 3 -ftp_blocksize = 8192 -ftp_timeout = 120 -ftp_dir = AUTO/MSEED -ftp_reconnect_wait = 60 -ftp_debug_level = 0 -ftp_host = qc.passcal.nmt.edu - -[TEST] -ftp_dir = AUTO/TEST -ftp_reconnect_wait = 5 -mock_test = True -testmode = False -ftp_timeout = 5 - -[FILES] -logfile = data2passcal.log - diff --git a/data2passcal/config.py b/data2passcal/config.py deleted file mode 100644 index 6f3ac69..0000000 --- a/data2passcal/config.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python -''' -data2passcal - -Create configuration file -''' - -import configparser - -VERSION = '2020.107' - -config = configparser.ConfigParser() -config['FTP_INFO'] = {'FTP_IP': '129.138.26.29', - 'FTP_HOST': 'qc.passcal.nmt.edu', - 'FTP_USER': 'ftp', - 'FTP_PASSWORD': 'data2passcal', - 'FTP_DIR': 'AUTO/MSEED', - 'FTP_TIMEOUT': '120', - 'FTP_RECONNECT_WAIT': '60', - 'FTP_BLOCKSIZE': '8192', - 'FTP_SEND_ATTEMPTS': '3', - 'FTP_DEBUG_LEVEL': '0'} -config['TEST'] = {'TESTMODE': 'False', - 'FTP_DIR': 'AUTO/TEST', - 'FTP_TIMEOUT': '5', - 'FTP_RECONNECT_WAIT': '5', - 'MOCK_TEST': 'True'} -config['FILES'] = {'LOGFILE': 'data2passcal.log'} - -with open('config.ini', 'w') as configfile: - config.write(configfile) diff --git a/data2passcal/data2passcal.py b/data2passcal/data2passcal.py index 7cb8551..ebdae01 100644 --- a/data2passcal/data2passcal.py +++ b/data2passcal/data2passcal.py @@ -7,7 +7,6 @@ Lloyd Carothers IRIS/PASSCAL ''' from __future__ import division, print_function -import configparser import datetime import ftplib import logging @@ -25,36 +24,32 @@ VERSION = '2020.107' # Cache the ftplib.FTP class so it will be available to test_FTP(FTP) when calling isinstance assert FTPCache = ftplib.FTP -# Parse configuration file -config = configparser.ConfigParser() -print(config.read('data2passcal/config.ini')) - # TEST related -TESTMODE = config.getboolean('TEST', 'TESTMODE') +TESTMODE = False # FTP related -FTP_IP = config.get('FTP_INFO', 'FTP_IP') -FTP_HOST = config.get('FTP_INFO', 'FTP_HOST') -FTP_USER = config.get('FTP_INFO', 'FTP_USER') -FTP_PASSWORD = config.get('FTP_INFO', 'FTP_PASSWORD') -FTP_DIR = config.get('FTP_INFO', 'FTP_DIR') -FTP_TIMEOUT = config.getint('FTP_INFO', 'FTP_TIMEOUT') -FTP_RECONNECT_WAIT = config.getint('FTP_INFO', 'FTP_RECONNECT_WAIT') +FTP_IP = '129.138.26.29' +FTP_HOST = 'qc.passcal.nmt.edu' +FTP_USER = 'ftp' +FTP_PASSWORD = 'data2passcal' +FTP_DIR = 'AUTO/MSEED' +FTP_TIMEOUT = 120 +FTP_RECONNECT_WAIT = 60 if TESTMODE: - FTP_DIR = config.get('TEST', 'FTP_DIR') - FTP_TIMEOUT = config.getint('TEST', 'FTP_TIMEOUT') - FTP_RECONNECT_WAIT = config.getint('TEST', 'FTP_RECONNECT_WAIT') -FTP_BLOCKSIZE = config.getint('FTP_INFO', 'FTP_BLOCKSIZE') -# number of time to try to open the ftp connection - testing will retry for a week. Why not? + FTP_DIR = 'AUTO/TEST' + FTP_TIMEOUT = 5 + FTP_RECONNECT_WAIT = 5 +FTP_BLOCKSIZE = 8192 +# number of time to try to open the ftp connection FTP_CONNECT_ATTEMPTS = 60 * 60 * 24 * 7 / FTP_RECONNECT_WAIT # number of times a single file with try to be sent -FTP_SEND_ATTEMPTS = config.getint('FTP_INFO', 'FTP_SEND_ATTEMPTS') +FTP_SEND_ATTEMPTS = 3 # debug level of ftplib, 0-3 -FTP_DEBUG_LEVEL = config.getint('FTP_INFO', 'FTP_DEBUG_LEVEL') +FTP_DEBUG_LEVEL = 0 # Files related -LOGFILE = config.get('FILES', 'LOGFILE') +LOGFILE = 'data2passcal.log' # store the files sent in ~/data2passcal.sent SENTFILE = os.path.join(os.path.expanduser('~'), '.data2passcal.sent') # If this file exists open it, incorporate, and save to new name, and delete old diff --git a/setup.py b/setup.py index 9f29d0f..11504a8 100644 --- a/setup.py +++ b/setup.py @@ -29,10 +29,7 @@ setup( 'data2passcal=data2passcal.data2passcal:main', ], }, - install_requires=[ - "mock;python_version<'3.3'", - "configparser;python_version<'3.2'" - ], + install_requires=[], setup_requires=[], extras_require={ 'dev': [ @@ -45,7 +42,7 @@ setup( 'coverage', 'Sphinx', 'twine', - 'pytest' + "mock;python_version<'3.3'" ] }, license="GNU General Public License v3", @@ -54,7 +51,6 @@ setup( keywords='data2passcal', name='data2passcal', packages=find_packages(include=['data2passcal']), - test_suite='tests', url='https://git.passcal.nmt.edu/passoft/data2passcal', version='2020.107', zip_safe=False, diff --git a/tests/test_data2passcal.py b/tests/test_data2passcal.py index 02d5c33..fb90024 100644 --- a/tests/test_data2passcal.py +++ b/tests/test_data2passcal.py @@ -5,32 +5,28 @@ from __future__ import division, print_function -import configparser import ftplib import os import unittest from data2passcal.data2passcal import get_FTP, ismseed, scan_dir, send2passcal -VERSION = '2020.107' - - try: from unittest.mock import patch except ImportError: from mock import patch -config = configparser.ConfigParser() -config.read('data2passcal/config.ini') -FTP_HOST = config.get('FTP_INFO', 'FTP_HOST') -FTP_USER = config.get('FTP_INFO', 'FTP_USER') -FTP_PASSWORD = config.get('FTP_INFO', 'FTP_PASSWORD') -FTP_DIR = config.get('FTP_INFO', 'FTP_DIR') -FTP_TIMEOUT = config.getint('FTP_INFO', 'FTP_TIMEOUT') -FTP_RECONNECT_WAIT = config.getint('FTP_INFO', 'FTP_RECONNECT_WAIT') +VERSION = '2020.107' + +FTP_HOST = 'qc.passcal.nmt.edu' +FTP_USER = 'ftp' +FTP_PASSWORD = 'data2passcal' +FTP_DIR = 'AUTO/MSEED' +FTP_TIMEOUT = 120 +FTP_RECONNECT_WAIT = 60 FTP_CONNECT_ATTEMPTS = 60 * 60 * 24 * 7 / FTP_RECONNECT_WAIT -FTP_SEND_ATTEMPTS = config.getint('FTP_INFO', 'FTP_SEND_ATTEMPTS') -MOCK_TEST = config.getboolean('TEST', 'MOCK_TEST') +FTP_SEND_ATTEMPTS = 3 +MOCK_TEST = True class TestData2passcal(unittest.TestCase): diff --git a/tox.ini b/tox.ini index f6954a3..d1ee218 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,10 @@ deps = flake8 commands = flake8 --ignore=E722,E712,E501 data2passcal flake8 --ignore=E722,E712,E501 tests -[testenv] -deps = pytest -setenv = PYTHONPATH = {toxinidir} -commands = pytest +[testenv:py27] +changedir = tests +deps = mock +commands = python -m unittest test_data2passcal + +[testenv:py36] +commands = python -m unittest -- GitLab