Skip to content

Commit

Permalink
Abandoned "setuptools" in favor of plain "distutils"; now use "unitte…
Browse files Browse the repository at this point in the history
…st2"

style test discovery instead of the "setuptools" test_suite option.
  • Loading branch information
brandon-rhodes committed Feb 9, 2011
1 parent 5f67e7e commit 92ec258
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 72 deletions.
36 changes: 27 additions & 9 deletions INSTALL
Expand Up @@ -15,8 +15,14 @@ in this directory for licensing information.

INSTALLING

If you have installed the "setuptools" for Python on your system, you
can ask for PyEphem to be installed simply by typing:
If you have installed the Python "distribute" package (or the ancient
and outdated "setuptools") and "pip" on your system, then you can
install PyEphem simply by typing:

pip install pyephem

If for some reason you cannot install "pip", then "distribute" by itself
offers an installer that you can use this way:

easy_install pyephem

Expand All @@ -33,18 +39,30 @@ the package. Typically, entering

(which you will probably need to do as root, unless you have Python
installed in your home directory) will both build and install the
module, which you can use in your Python programs with either an
module.

You can use PyEphem in your Python programs by calling:

import ephem

or perhaps a
or perhaps something more like:

from ephem import Mars, Jupiter, Date

if you know what parts of "ephem" you want to use and you are tired of
putting "ephem." in front of all the names.

TESTING

Using the new "unittest" module in Python 2.7, you can run the PyEphem
test suite this way:

$ python -m unittest discover

from ephem import *
On older versions of Python you can separately install the backported
"unittest2" module and use its "unit2" command line to run the tests:

to avoid putting "ephem." in front of all the names. There are
documentation files in the doc/ directory, some small scripts in the
examples/ directory, and test suites for verifying your installation
in the test/ directory.
$ unit2 discover ephem

DOCUMENTATION

Expand Down
7 changes: 1 addition & 6 deletions setup.py
Expand Up @@ -4,12 +4,8 @@
' try "ephem" for Python 3')
sys.exit(1)

try:
from setuptools import setup, Extension
except:
from distutils.core import setup, Extension

import os
from distutils.core import setup, Extension
from glob import glob

# Read the current version from ephem/__init__.py itself.
Expand Down Expand Up @@ -50,7 +46,6 @@ def read(*filenames):
'tests/jpl/*.txt',
'tests/usno/*.txt',
],},
test_suite = 'ephem.tests',
ext_modules = [
Extension('ephem._libastro',
['extensions/_libastro.c'] + libastro_files + libastro_data,
Expand Down
5 changes: 1 addition & 4 deletions src/ephem/tests/test_angles.py
Expand Up @@ -7,7 +7,7 @@

arcsecond = 2. * math.pi / 360. / 60. / 60.

class angle_suite(MyTestCase):
class AngleTests(MyTestCase):
def setUp(self):
self.d = degrees(1.5)
self.h = hours(1.6)
Expand All @@ -33,6 +33,3 @@ def test_angle_addition(self):
self.assertApprox(degrees('30') + degrees('90'), degrees('120'))
def test_angle_subtraction(self):
self.assertApprox(degrees('180') - hours('9'), degrees('45'))

if __name__ == '__main__':
unittest.main()
9 changes: 3 additions & 6 deletions src/ephem/tests/test_bodies.py
Expand Up @@ -56,7 +56,7 @@ def predict_attributes(body, was_computed, was_given_observer):
# Determine whether each kind of body supports the set of attributes
# we believe it should.

class body_suite(MyTestCase):
class BodyTests(MyTestCase):
def setUp(self):
self.date = date('1955/05/21')

Expand Down Expand Up @@ -254,7 +254,7 @@ def test_newlineTLE(self):
# indeed a major error occuring in its calculation. This small test
# should assure that reasonable values are returned from now on.

class planet_suite(unittest.TestCase):
class PlanetTests(unittest.TestCase):
"""See whether Jupiter Central Meridian Longitudes look good."""
def test_jupiter(self):
j = Jupiter('2008/10/1')
Expand All @@ -270,11 +270,8 @@ def test_saturn(self):
# Make sure the constellation function forces objects to determine
# their position before using their right ascension and declination.

class function_suite(unittest.TestCase):
class FunctionTests(unittest.TestCase):
def test_constellation(self):
oneb = readdb('Orion Nebula,f,5.59,-5.45,2,2000.0,')
oneb.compute('1999/2/28')
self.assertEqual(constellation(oneb), ('Ori', 'Orion'))

if __name__ == '__main__':
unittest.main()
7 changes: 2 additions & 5 deletions src/ephem/tests/test_constants.py
@@ -1,17 +1,14 @@
#!/usr/bin/env python

import ephem, unittest
import ephem
from ephem_test import MyTestCase

# Determine whether angles work reasonably.

class constant_suite(MyTestCase):
class ConstantTests(MyTestCase):
def test_constants(self):
self.assertEqual(ephem.c, 299792458)
self.assertEqual(ephem.meters_per_au, 1.4959787e11)
self.assertEqual(ephem.earth_radius, 6378160)
self.assertEqual(ephem.moon_radius, 1740000)
self.assertEqual(ephem.sun_radius, 695000000)

if __name__ == '__main__':
unittest.main()
5 changes: 1 addition & 4 deletions src/ephem/tests/test_dates.py
Expand Up @@ -7,7 +7,7 @@

# Determine whether dates behave reasonably.

class date_suite(unittest.TestCase):
class DateTests(unittest.TestCase):
def setUp(self):
self.date = Date('2004/09/04 00:17:15.8')

Expand Down Expand Up @@ -69,6 +69,3 @@ def OFF_test_localtime_premodern(self):
if time.timezone == 18000: # test only works in Eastern time zone
self.assertEqual(localtime(Date('1531/8/24 2:49')),
datetime(1957, 10, 4, 15, 28, 34, 4))

if __name__ == '__main__':
unittest.main()
10 changes: 1 addition & 9 deletions src/ephem/tests/test_jpl.py
Expand Up @@ -28,12 +28,8 @@ class JPLDatum(object):
class JPLTest(unittest.TestCase):

def runTest(self):
if not hasattr(self, 'path'):
return

in_data = False

c=0
for line in open(self.path):

if line.startswith('Target body name:'):
Expand Down Expand Up @@ -78,14 +74,10 @@ def runTest(self):

re, traceback, datetime, strptime, ephem

def additional_tests():
def load_tests(loader, tests, pattern):
suite = unittest.TestSuite()
for path in glob.glob(os.path.dirname(__file__) + '/jpl/*.txt'):
case = JPLTest()
case.path = path
suite.addTest(case)
return suite

if __name__ == '__main__':
suite = additional_tests()
unittest.TextTestRunner().run(suite)
Expand Up @@ -6,12 +6,9 @@

# See whether asking for the rising-time of Mars hangs indefinitely.

class convergence_suite(MyTestCase):
class Launchpad236872Tests(MyTestCase):
def runTest(self):
mars = ephem.Mars()
boston = ephem.city('Boston')
boston.date = ephem.Date('2008/5/29 15:59:16')
boston.next_rising(mars)

if __name__ == '__main__':
unittest.main()
Expand Up @@ -7,7 +7,7 @@
# Make sure that a series of next-risings does not keep returning the
# same time over and over again.

class next_rising_suite(MyTestCase):
class Launchpad244811Tests(MyTestCase):
def runTest(self):
boston = ephem.city("Boston")
boston.pressure = 1010.0 # undo pressure auto-adjustment
Expand All @@ -22,6 +22,3 @@ def runTest(self):

cur_date = boston.next_rising(mars, start=cur_date)
self.assertEquals(str(cur_date), '2009/7/2 06:13:53')

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion src/ephem/tests/test_observers.py
Expand Up @@ -3,7 +3,7 @@
from ephem import Observer
from unittest import TestCase

class observer_suite(TestCase):
class ObserverTests(TestCase):
def test_lon_can_also_be_called_long(self):
o = Observer()
o.lon = 3.0
Expand Down
6 changes: 1 addition & 5 deletions src/ephem/tests/test_rst.py
Expand Up @@ -4,14 +4,10 @@
from glob import glob
import os.path

def additional_tests():
def load_tests(loader, tests, pattern):
return unittest.TestSuite([
doctest.DocFileSuite('../doc/%s' % os.path.basename(path))
for path in glob(os.path.dirname(__file__) + '/../doc/*.rst')
if os.path.split(path)[-1] != 'index.rst'
# skips time-dependent doctest in index.rst
])

if __name__ == '__main__':
suite = additional_tests()
unittest.TextTestRunner().run(suite)
2 changes: 1 addition & 1 deletion src/ephem/tests/test_satellite.py
Expand Up @@ -8,7 +8,7 @@
'2 25544 51.6397 195.1243 0008906 304.8273 151.9344 15.72498628598335',
)

class Case(unittest.TestCase):
class SatelliteTests(unittest.TestCase):
def setUp(self):
self.iss = ephem.readtle(*tle_lines)
self.atlanta = ephem.city('Atlanta')
Expand Down
15 changes: 6 additions & 9 deletions src/ephem/tests/test_usno.py
Expand Up @@ -126,7 +126,7 @@ def report_error():

class Astrometric_Trial(Trial):
@classmethod
def matches(self, content):
def matches(cls, content):
return 'Astrometric Positions' in content

def check_data_line(self, line):
Expand All @@ -140,7 +140,7 @@ def check_data_line(self, line):

class Apparent_Geocentric_Trial(Trial):
@classmethod
def matches(self, content):
def matches(cls, content):
return 'Apparent Geocentric Positions' in content

def check_data_line(self, line):
Expand Down Expand Up @@ -168,7 +168,7 @@ def check_data_line(self, line):

class Apparent_Topocentric_Trial(Trial):
@classmethod
def matches(self, content):
def matches(cls, content):
return 'Apparent Topocentric Positions' in content

def examine_content(self):
Expand All @@ -191,7 +191,7 @@ def __init__(self):
self.data = []

@classmethod
def matches(self, content):
def matches(cls, content):
return 'Rise Az. Transit Alt. Set Az.' in content

def examine_content(self):
Expand Down Expand Up @@ -316,7 +316,7 @@ def check(attr):

class Rise_Set_Trial(Trial):
@classmethod
def matches(self, content):
def matches(cls, content):
return 'Rise and Set for' in content

def examine_content(self):
Expand Down Expand Up @@ -404,7 +404,7 @@ def two_digit_compare(event, usno_digits):

class Moon_Phases(Trial):
@classmethod
def matches(self, content):
def matches(cls, content):
return 'Phases of the Moon' in content

def examine_content(self):
Expand Down Expand Up @@ -475,6 +475,3 @@ def test_usno(self):
for path in glob.glob(os.path.dirname(__file__) + '/usno/*.txt'):
exec 'class T%d(unittest.TestCase, Mixin): path = %r' % (i, path)
i += 1

if __name__ == '__main__':
unittest.main()
6 changes: 1 addition & 5 deletions src/ephem/tests/test_usno_equinoxes.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python

from ephem_test import *
import math

# Determine whether the equinoxes and solstices which PyEphem predicts
# fall within one minute (by the clock) of those predicted by the
Expand Down Expand Up @@ -175,9 +174,6 @@ def process_usno(data):
ephem.previous_winter_solstice,
))

class usno_equinoxes_suite(MyTestCase):
class UsnoEquinoxesTests(MyTestCase):
def test_equinoxes(self):
process_usno(usno_data)

if __name__ == '__main__':
unittest.main()

0 comments on commit 92ec258

Please sign in to comment.