From cfca483bb4b1df4be015420748afe4379639fc04 Mon Sep 17 00:00:00 2001 From: jlaura <jlaura@asu.edu> Date: Thu, 16 Jun 2016 15:38:02 -0700 Subject: [PATCH] Tests and add icu dep. --- .travis.yml | 4 ++-- conda/meta.yaml | 2 ++ plio/examples/Apollo15/pngs.lis | 6 ++++++ plio/io_utils.py | 35 ------------------------------ plio/tests/test_io_utils.py | 16 -------------- plio/tests/test_utils.py | 20 +++++++++++++++-- plio/utils.py | 38 +++++++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 55 deletions(-) create mode 100644 plio/examples/Apollo15/pngs.lis delete mode 100644 plio/io_utils.py delete mode 100644 plio/tests/test_io_utils.py diff --git a/.travis.yml b/.travis.yml index 95cd240..022c662 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,13 +20,13 @@ install: # We do this conditionally because it saves us some downloading if the # version is the same. - if [ "$TRAVIS_OS_NAME" == "linux" ]; then - if [ "$PYTHON_VERSION" == "2.7" ]; then + if [ "$PYTHON_VERSION" == 2.7 ]; then wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh; else wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; fi else - if ["$PYTHON_VERSION" == "2.7"]; then + if ["$PYTHON_VERSION" == 2.7]; then curl -o miniconda.sh https://repo.continuum.io/miniconda/Miniconda-latest-MacOSX-x86_64.sh; else curl -o miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh; diff --git a/conda/meta.yaml b/conda/meta.yaml index c0f1d40..08523fa 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -12,6 +12,7 @@ requirements: - pvl - protobuf 3.0.0b2 - gdal >=2 + - icu - h5py - pandas - sqlalchemy @@ -22,6 +23,7 @@ requirements: - pvl - protobuf 3.0.0b2 - gdal >=2 + - icu - h5py - pandas - sqlalchemy diff --git a/plio/examples/Apollo15/pngs.lis b/plio/examples/Apollo15/pngs.lis new file mode 100644 index 0000000..6ab84be --- /dev/null +++ b/plio/examples/Apollo15/pngs.lis @@ -0,0 +1,6 @@ +AS15-M-0295_SML.png +AS15-M-0296_SML.png +AS15-M-0297_SML.png +AS15-M-0298_SML.png +AS15-M-0299_SML.png +AS15-M-0300_SML.png \ No newline at end of file diff --git a/plio/io_utils.py b/plio/io_utils.py deleted file mode 100644 index 5ec884b..0000000 --- a/plio/io_utils.py +++ /dev/null @@ -1,35 +0,0 @@ -import shutil -import tempfile - - -def create_dir(basedir=''): - """ - Create a unique, temporary directory in /tmp where processing will occur - - Parameters - ---------- - basedir : str - The PATH to create the temporary directory in. - """ - return tempfile.mkdtemp(dir=basedir) - - -def delete_dir(dir): - """ - Delete a directory - - Parameters - ---------- - dir : str - Remove a directory - """ - shutil.rmtree(dir) - - -def file_to_list(file): - with open(file, 'r') as f: - file_list = f.readlines() - file_list = map(str.rstrip, file_list) - file_list = filter(None, file_list) - - return file_list diff --git a/plio/tests/test_io_utils.py b/plio/tests/test_io_utils.py deleted file mode 100644 index e9105a6..0000000 --- a/plio/tests/test_io_utils.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import unittest - -from .. import io_utils - -class TestIoUtils(unittest.TestCase): - - def setUp(self): - pass - - def test_create_and_destroy_directory(self): - path = io_utils.create_dir() - self.assertTrue(os.path.exists(path)) - io_utils.delete_dir(path) - self.assertFalse(os.path.exists(path)) - diff --git a/plio/tests/test_utils.py b/plio/tests/test_utils.py index 1f999c6..0098c5e 100644 --- a/plio/tests/test_utils.py +++ b/plio/tests/test_utils.py @@ -1,8 +1,9 @@ +import os import unittest +from ..examples import get_path from .. import utils - class TestUtils(unittest.TestCase): def test_find_in_dict(self): @@ -36,4 +37,19 @@ class TestUtils(unittest.TestCase): } self.assertEqual(utils.find_nested_in_dict(d, 'a'), 1) - self.assertEqual(utils.find_nested_in_dict(d, ['c', 'f', 'g']), 5) \ No newline at end of file + self.assertEqual(utils.find_nested_in_dict(d, ['c', 'f', 'g']), 5) + + + + def test_create_and_destroy_directory(self): + path = utils.create_dir() + self.assertTrue(os.path.exists(path)) + utils.delete_dir(path) + self.assertFalse(os.path.exists(path)) + + def test_file_to_list(self): + truth = ['AS15-M-0295_SML.png', 'AS15-M-0296_SML.png', + 'AS15-M-0297_SML.png', 'AS15-M-0298_SML.png', + 'AS15-M-0299_SML.png', 'AS15-M-0300_SML.png'] + + self.assertEqual(utils.file_to_list(get_path('pngs.lis')), truth) \ No newline at end of file diff --git a/plio/utils.py b/plio/utils.py index 365af38..1b97f24 100644 --- a/plio/utils.py +++ b/plio/utils.py @@ -3,6 +3,42 @@ import shutil import tempfile import os import fnmatch +import shutil +import tempfile + + +def create_dir(basedir=''): + """ + Create a unique, temporary directory in /tmp where processing will occur + + Parameters + ---------- + basedir : str + The PATH to create the temporary directory in. + """ + return tempfile.mkdtemp(dir=basedir) + + +def delete_dir(dir): + """ + Delete a directory + + Parameters + ---------- + dir : str + Remove a directory + """ + shutil.rmtree(dir) + + +def file_to_list(file): + with open(file, 'r') as f: + file_list = f.readlines() + file_list = map(str.rstrip, file_list) + file_list = filter(None, file_list) + + return list(file_list) + def create_dir(basedir=''): """ @@ -53,6 +89,7 @@ def file_search(searchdir,searchstring): return filelist + def find_in_dict(obj, key): """ Recursively find an entry in a dictionary @@ -98,6 +135,7 @@ def find_nested_in_dict(data, key_list): """ return reduce(lambda d, k: d[k], key_list, data) + def xstr(s): """ Return an empty string if the input is a NoneType. Otherwise -- GitLab