Repository: sunpy/sunpy

Issue:
0.9.2: test_get_body_barycentric fails -- 0. != 360.
Hi,

I now managed to upload the latest version to Debian, and found the following test failure:
```
__________________________ test_get_body_barycentric ___________________________

    def test_get_body_barycentric():
        # Validate against published values from the Astronomical Almanac (2013)
        e1 = get_body_heliographic_stonyhurst('earth', '2013-Jan-01')
        assert_quantity_allclose(e1.lon, 0*u.deg, atol=1e-12*u.deg)
        assert_quantity_allclose(e1.lat, -3.03*u.deg, atol=5e-3*u.deg)
        assert_quantity_allclose(e1.radius, 0.9832947*u.AU, atol=5e-7*u.AU)
    
        e2 = get_body_heliographic_stonyhurst('earth', '2013-Sep-01')
>       assert_quantity_allclose(e2.lon, 0*u.deg, atol=1e-12*u.deg)

sunpy/coordinates/tests/test_ephemeris.py:19: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

actual = <Longitude 360. deg>, desired = <Quantity 0. deg>, rtol = 1e-07
atol = <Quantity 1.e-12 deg>, kwargs = {}
np = <module 'numpy' from '/usr/lib/python2.7/dist-packages/numpy/__init__.pyc'>

    def assert_quantity_allclose(actual, desired, rtol=1.e-7, atol=None,
                                 **kwargs):
        """[...]"""
        import numpy as np
        np.testing.assert_allclose(*_unquantify_allclose_arguments(actual, desired,
                                                                   rtol, atol),
>                                  **kwargs)
E       AssertionError: 
E       Not equal to tolerance rtol=1e-07, atol=1e-12
E       
E       (mismatch 100.0%)
E        x: array(360.)
E        y: array(0.)

/usr/lib/python2.7/dist-packages/astropy/tests/helper.py:510: AssertionError
```

This is on a 32 bit x86 platform. Full build log [here](https://buildd.debian.org/status/fetch.php?pkg=sunpy&arch=i386&ver=0.9.2-1&stamp=1534369425&raw=0).
lightcurve doesn't respect sunpy.config set dynamically
<!-- This comments are hidden when you submit the issue so you do not need to remove them!
Please be sure to check out our contributing guidelines: https://github.com/sunpy/sunpy/blob/master/CONTRIBUTING.rst
Please be sure to check out our code of conduct:
https://github.com/sunpy/sunpy/blob/master/CODE_OF_CONDUCT.rst -->

<!-- Please have a search on our GitHub repository to see if a similar issue has already been posted.
If a similar issue is closed, have a quick look to see if you are satisfied by the resolution.
If not please go ahead and open an issue! -->

### Description
The [docs](http://docs.sunpy.org/en/stable/guide/customization.html) indicate sunpy configuration can be dynamically updated but this doesn't seem to work when using lightcurve

### Expected behavior
After updating the config dynamically, specifically the download dir,  data should be downloaded there instead of the default or sunpyrc setting.

### Actual behavior
Data is not downloaded to dynamically set directory

### Steps to Reproduce
<!-- Ideally a code example could be provided so we can run it ourselves. -->
<!-- If you are pasting code, use tripe backticks (```) around your code snippet. -->

```
import sunpy
from sunpy import lightcurve as lc
sunpy.config.set('downloads', 'download_dir', '<somepath>')
goes = lc.GOESLightCurve.create('2010/01/01', '2010/01/02')
```
If you check `<somepath>` the data will not there but it will be in default `~/sunpy/data`

### System Details
<!-- It is sunpy.util.system_info(), this is optional but strongly recommended. -->
```
###########
 General 
###########
Time : Wednesday, 21. November 2018 11:44AM UT            
System : Linux  
Processor : x86_64
Arch : 64bit                                                                                            
SunPy : 0.9.3                                                                                 
SunPy_git : ae91b907db214bcb0f03915071d5bdbf334a5366
OS: debian stretch/sid  (Linux 4.4.0-128-generic x86_64) <--- it's actually MacOS mojave
                                          
###########                           
 Required Libraries                                                                                                                            
###########                                                                                                                                   
Python: 3.6.2                                                                                                                                  
NumPy: 1.15.2                                                                                                                                  
SciPy: 1.1.0                                                                                                                                   
matplotlib: 3.0.0                                                                                                                              
Astropy: 3.0.4                                                                                                                                 
Pandas: 0.23.4                                                                                                                            

###########                                                                                                                              
 Recommended Libraries                                                                                                                     
###########                                                                                                                               
beautifulsoup: 4.6.3                                                                                                                           
PyQt: NOT INSTALLED                                                                                                                           
SUDS: 0.6                                                                                                                                     
Sqlalchemy: 1.2.12                                                                                                                          
Requests: 2.19.1


Discussion:
Yeah, that is tricky since we don't test under 32bit nor do I have access to a system to debug it. 
My quick fix for this was to replace the assert with
```
assert_quantity_allclose((e2.lon+1*u.deg)%(360*u.deg), 1*u.deg, atol=1e-12*u.deg)
```
Another potential place is a few lines above that.
Comparing longitude with zero is always not very stable...
@nabobalis we could borrow the astropy circleci setup for 32bit testing. But yeah this code should probably just be more robust. Maybe using the `Longitude` class would help?


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -30,8 +30,6 @@
 AUTHOR_EMAIL = metadata.get('author_email', '')
 LICENSE = metadata.get('license', 'unknown')
 URL = metadata.get('url', 'https://sunpy.org')
-with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.rst'), encoding='utf-8') as f:
-    LONG_DESCRIPTION = f.read()
 __minimum_python_version__ = metadata.get("minimum_python_version", "3.6")
 
 # Enforce Python version check - this is the same check as in __init__.py but
@@ -40,6 +38,9 @@
     sys.stderr.write("ERROR: SunPy requires Python {} or later\n".format(__minimum_python_version__))
     sys.exit(1)
 
+with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.rst'), encoding='utf-8') as f:
+    LONG_DESCRIPTION = f.read()
+
 # Import ah_bootstrap after the python version validation
 import ah_bootstrap  # noqa
 from setuptools import setup  # noqa
diff --git a/sunpy/conftest.py b/sunpy/conftest.py
--- a/sunpy/conftest.py
+++ b/sunpy/conftest.py
@@ -38,7 +38,7 @@ def pytest_runtest_setup(item):
     pytest hook to skip all tests that have the mark 'remotedata' if the
     pytest_remotedata plugin is not installed.
     """
-    if isinstance(item, item.Function):
+    if isinstance(item, pytest.Function):
         if 'remote_data' in item.keywords and not HAVE_REMOTEDATA:
             pytest.skip("skipping remotedata tests as pytest-remotedata is not installed")
 
diff --git a/sunpy/util/config.py b/sunpy/util/config.py
--- a/sunpy/util/config.py
+++ b/sunpy/util/config.py
@@ -46,22 +46,20 @@ def get_and_create_download_dir():
     '''
     Get the config of download directory and create one if not present.
     '''
-    config = load_config()
-    if not os.path.isdir(config.get('downloads', 'download_dir')):
-        os.makedirs(config.get('downloads', 'download_dir'))
+    if not os.path.isdir(sunpy.config.get('downloads', 'download_dir')):
+        os.makedirs(sunpy.config.get('downloads', 'download_dir'))
 
-    return config.get('downloads', 'download_dir')
+    return sunpy.config.get('downloads', 'download_dir')
 
 
 def get_and_create_sample_dir():
     '''
     Get the config of download directory and create one if not present.
     '''
-    config = load_config()
-    if not os.path.isdir(config.get('downloads', 'sample_dir')):
-        os.makedirs(config.get('downloads', 'sample_dir'))
+    if not os.path.isdir(sunpy.config.get('downloads', 'sample_dir')):
+        os.makedirs(sunpy.config.get('downloads', 'sample_dir'))
 
-    return config.get('downloads', 'sample_dir')
+    return sunpy.config.get('downloads', 'sample_dir')
 
 
 def print_config():
@@ -186,7 +184,7 @@ def _expand_filepath(filepath, working_dir=""):
         return tempfile.gettempdir()
     # Relative filepaths
     elif not filepath.startswith("/"):
-        return os.path.join(working_dir, filepath)
+        return  os.path.abspath(os.path.join(working_dir, filepath))
     # Absolute filepath
     else:
-        return filepath
+        return os.path.abspath(filepath)


Test patch:
diff --git a/sunpy/coordinates/tests/test_ephemeris.py b/sunpy/coordinates/tests/test_ephemeris.py
--- a/sunpy/coordinates/tests/test_ephemeris.py
+++ b/sunpy/coordinates/tests/test_ephemeris.py
@@ -16,7 +16,8 @@ def test_get_body_barycentric():
     assert_quantity_allclose(e1.radius, 0.9832947*u.AU, atol=5e-7*u.AU)
 
     e2 = get_body_heliographic_stonyhurst('earth', '2013-Sep-01')
-    assert_quantity_allclose(e2.lon, 0*u.deg, atol=1e-12*u.deg)
+    # https://github.com/sunpy/sunpy/issues/2727
+    assert_quantity_allclose((e2.lon+1*u.deg)%(360*u.deg), 1*u.deg, atol=1e-12*u.deg)
     assert_quantity_allclose(e2.lat, 7.19*u.deg, atol=5e-3*u.deg)
     assert_quantity_allclose(e2.radius, 1.0092561*u.AU, atol=5e-7*u.AU)
 
diff --git a/sunpy/util/tests/test_config.py b/sunpy/util/tests/test_config.py
new file mode 100644
--- /dev/null
+++ b/sunpy/util/tests/test_config.py
@@ -0,0 +1,28 @@
+import os
+
+from sunpy import config
+from sunpy.util.config import get_and_create_sample_dir, get_and_create_download_dir
+
+USER = os.path.expanduser('~')
+
+
+def test_get_and_create_download_dir():
+    # test default config
+    path = get_and_create_download_dir()
+    assert path == os.path.join(USER, 'sunpy', 'data')
+    # test updated config
+    new_path = os.path.join(USER, 'data_here_please')
+    config.set('downloads', 'download_dir', new_path)
+    path = get_and_create_download_dir()
+    assert path == os.path.join(USER, new_path)
+
+
+def test_get_and_create_sample_dir():
+    # test default config
+    path = get_and_create_sample_dir()
+    assert path == os.path.join(USER, 'sunpy', 'data', 'sample_data')
+    # test updated config
+    new_path = os.path.join(USER, 'data_here_please')
+    config.set('downloads', 'sample_dir', new_path)
+    path = get_and_create_sample_dir()
+    assert path == new_path
diff --git a/sunpy/util/tests/test_sysinfo.py b/sunpy/util/tests/test_sysinfo.py
--- a/sunpy/util/tests/test_sysinfo.py
+++ b/sunpy/util/tests/test_sysinfo.py
@@ -2,6 +2,7 @@
 
 import sunpy
 
+
 def test_sysinfo():
 
     output = sunpy.util.get_sys_dict()
diff --git a/sunpy/util/tests/test_util.py b/sunpy/util/tests/test_util.py
--- a/sunpy/util/tests/test_util.py
+++ b/sunpy/util/tests/test_util.py
@@ -3,9 +3,7 @@
 """
 
 import numpy as np
-
 import pytest
-from pytest_mock import mocker
 
 from sunpy.util import util