Skip to content
Snippets Groups Projects
Commit 10d5c0c0 authored by Maeva Pourpoint's avatar Maeva Pourpoint
Browse files

Update test_data2passcal.py - remove setup() and rethink test_scan_dir();...

Update test_data2passcal.py - remove setup() and rethink test_scan_dir(); Update .gitlab-ci.yml - remove call to tox
parent 8af2c819
No related branches found
No related tags found
1 merge request!5Conda packaging
Pipeline #707 passed with stages
in 1 minute and 39 seconds
......@@ -15,19 +15,40 @@ cache:
- .cache/pip
stages:
- static analysis
- test
before_script:
- pip install -e .[dev]
linting_python2:
image: python:2.7
tags:
- passoft
stage: static analysis
script:
- flake8 --ignore=E722,E712 data2passcal
- flake8 --ignore=E722,E712 tests
linting_python3:
image: python:3.6
tags:
- passoft
stage: static analysis
script:
- flake8 --ignore=E722,E712 data2passcal
- flake8 --ignore=E722,E712 tests
python2.7:
image: python:2.7
tags:
- passoft
stage: test
script:
- tox -e py27
- tox -e flake8
- cd tests/
- pwd
- ls
- python -m unittest test_data2passcal
python3.5:
image: python:3.5
......@@ -35,8 +56,9 @@ python3.5:
- passoft
stage: test
script:
- tox -e py35
- tox -e flake8
- pwd
- ls
- python -m unittest
python3.6:
image: python:3.6
......@@ -44,8 +66,9 @@ python3.6:
- passoft
stage: test
script:
- tox -e py36
- tox -e flake8
- pwd
- ls
- python -m unittest
python3.7:
image: python:3.7
......@@ -53,8 +76,9 @@ python3.7:
- passoft
stage: test
script:
- tox -e py37
- tox -e flake8
- pwd
- ls
- python -m unittest
python3.8:
image: python:3.8
......@@ -62,5 +86,6 @@ python3.8:
- passoft
stage: test
script:
- tox -e py38
- tox -e flake8
- pwd
- ls
- python -m unittest
......@@ -23,38 +23,31 @@ VERSION = '2020.119'
MOCK_TEST = True
TEST_DIR = os.path.dirname(os.path.realpath(__file__)) + '/test_data'
MS_FILELIST = ['ST00.AB..BHZ.2007.160', 'ST00.AB..BHZ.2007.161',
'ST00.AB..BHZ.2007.162', 'ST00.AB..BHZ.2007.163',
'ST00.AB..BHZ.2007.164']
class TestData2passcal(unittest.TestCase):
"""Tests for `data2passcal` package."""
def setUp(self):
"""Set up test fixtures, if any"""
dir_testdata = os.path.dirname(os.path.realpath(__file__)) + '/test_data' # noqa
filelist = ['/'.join([dir_testdata, x])
for x in os.listdir(dir_testdata)
if not os.path.basename(x).startswith('.') and not
os.path.basename(x).endswith('.log')]
self.dir_testdata = dir_testdata
self.filelist = filelist
def test_scan_dir(self):
"""
Test basic functionality of scan_dir function
Only 5 files available under ./test_data directory
Not taking into account .DS_STORE file
"""
filelist_test = [x for x in scan_dir(self.dir_testdata)
if not os.path.basename(x).startswith('.') and not
os.path.basename(x).endswith('.log')]
self.assertEqual(len(filelist_test), len(self.filelist),
'Incorrect number of files')
for f in filelist_test:
self.assertIn(f, self.filelist, 'File {0} not found in {1}'
.format(f, self.dir_testdata))
filelist = [os.path.join(TEST_DIR, f) for f in MS_FILELIST]
if sys.version_info < (3, 2):
self.assertItemsEqual(filelist, scan_dir(TEST_DIR),
'scan_dir did not find the correct file(s)')
else:
self.assertCountEqual(filelist, scan_dir(TEST_DIR),
'scan_dir did not find the correct file(s)')
def test_ismseed(self):
"""Test basic functionality of ismseed function"""
for f in self.filelist:
filelist = [os.path.join(TEST_DIR, f) for f in MS_FILELIST]
for f in filelist:
self.assertTrue(ismseed(f), '{} is not a miniseed file'
.format(os.path.basename(f)))
......@@ -72,18 +65,18 @@ class TestData2passcal(unittest.TestCase):
def test_send_data_mock(self, mock_ftp_constructor):
"""Mock test sending MSEED files (test data) to PASSCAL's QC system"""
mock_ftp = mock_ftp_constructor.return_value
send2passcal(self.filelist)
filelist = [os.path.join(TEST_DIR, f) for f in MS_FILELIST]
send2passcal(filelist)
self.assertTrue(mock_ftp.storbinary.called, 'No data sent')
self.assertEqual(mock_ftp.storbinary.call_count, len(self.filelist),
self.assertEqual(mock_ftp.storbinary.call_count, len(filelist),
'Failed to send all files - Sent {0} of {1}'
.format(mock_ftp.storbinary.call_count,
len(self.filelist)))
len(filelist)))
files_sent = []
for x in mock_ftp.storbinary.call_args_list:
args, kwargs = x
files_sent.append(args[0].split(' ')[1])
for f in self.filelist:
f = os.path.basename(f)
for f in MS_FILELIST:
self.assertLess(files_sent.count(f), FTP_SEND_ATTEMPTS,
'Attempted to send file {0} more than {1} times'
.format(f, FTP_SEND_ATTEMPTS))
......@@ -92,7 +85,8 @@ class TestData2passcal(unittest.TestCase):
def test_send_data(self):
"""Test sending MSEED files (test data) to PASSCAL's QC system"""
ftp = get_FTP()
send2passcal(self.filelist)
filelist = [os.path.join(TEST_DIR, f) for f in MS_FILELIST]
send2passcal(filelist)
wdir = ftp.pwd()
try:
files_sent = [os.path.basename(x) for x in ftp.nlst(wdir)]
......@@ -101,10 +95,9 @@ class TestData2passcal(unittest.TestCase):
print("No files found in this directory")
else:
raise
for f in self.filelist:
f_ = os.path.basename(f)
self.assertIn(f_, files_sent, 'File {} was not sent to PASSCAL'
.format(f_))
for f in MS_FILELIST:
self.assertIn(f, files_sent, 'File {} was not sent to PASSCAL'
.format(f))
ftp.quit()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment