Package gavo :: Package helpers :: Module testhelpers
[frames] | no frames]

Module testhelpers

source code

Helper classes for the DaCHS' unit tests.

WARNING: This messes up some global state. DO NOT import into modules doing regular work. testtricks is the module for that kind for stuff.

Classes
  FakeSimbad
we monkeypatch simbadinterface such that we don't query simbad during tests.
  ResourceInstance
A helper class for TestResource.
  TestResource
A wrapper for testresources maintaining some backward compatibility.
  ForkingSubprocess
A subprocess that doesn't exec but fork.
  VerboseTest
A TestCase with a couple of convenient assert methods.
  SamplesBasedAutoTest
A metaclass that builds tests out of a samples attribute of a class.
  SimpleSampleComparisonTest
A base class for tests that simply run a function and compare for equality.
  StandIn
A class having the attributes passed as kwargs to the constructor.
  FakeContext
A scaffolding class for testing renderers.
  CatchallUI
A replacement for base.ui, collecting the messages being sent.
Functions
 
ensureResources() source code
 
cleanXML(aString)
removes IDs and some other detritus from XML literals.
source code
 
printFormattedXML(xmlString)
pipes xmlString through xmlstarlet fo, pretty-printing it.
source code
 
computeWCSKeys(pos, size, cutCrap=False)
returns a dictionary containing a 2D WCS structure for an image centered at pos with angular size.
source code
 
getTestRD(id='test.rd') source code
 
getTestTable(tableName, id='test.rd') source code
 
getTestData(dataId) source code
 
captureOutput(callable, args=(), kwargs={})
runs callable(*args, **kwargs) and captures the output.
source code
 
messageCollector(*args, **kwds)
A context manager recording UI events.
source code
 
trialMain(testClass) source code
 
getServerInThread(data, onlyOnce=False)
runs a server in a thread and returns thread and base url.
source code
 
DataServer(*args, **kwds)
a context manager for briefly running a web server returning data.
source code
 
userconfigContent(*args, **kwds)
a context manager to temporarily set some content to userconfig.
source code
 
main(testClass, methodPrefix=None) source code
Variables
  TEST_BASE = '/home/msdemlei/gavo/trunk/docs'
  originalEnvironment = {'ADS_NO_LOOKERS': '1', 'ADS_TOKEN': 'Eu...
  dbname = "dachstest"
  dsn = initdachs.DSN(dbname)
  __package__ = 'gavo.helpers'
  __warningregistry__ = {('testhelpers imported from non-test di...
Function Details

cleanXML(aString)

source code 

removes IDs and some other detritus from XML literals.

The result will be invalid XML, and all this assumes the fixed-prefix logic of the DC software.

For new tests, you should just getXMLTree and XPath tests.

computeWCSKeys(pos, size, cutCrap=False)

source code 

returns a dictionary containing a 2D WCS structure for an image centered at pos with angular size. Both are 2-tuples in degrees.

captureOutput(callable, args=(), kwargs={})

source code 

runs callable(*args, **kwargs) and captures the output.

The function returns a tuple of return value, stdout output, stderr output.

messageCollector(*args, **kwds)

source code 

A context manager recording UI events.

The object returned by the context manager is a CatchallUI; get the events accumulated during the run time in its events attribute.

Decorators:
  • @contextlib.contextmanager

getServerInThread(data, onlyOnce=False)

source code 

runs a server in a thread and returns thread and base url.

onlyOnce will configure the server such that it destroys itself after having handled one request. The thread would still need to be joined.

So, better use the DataServer context manager.

DataServer(*args, **kwds)

source code 

a context manager for briefly running a web server returning data.

This yields the base URL the server is listening on.

Decorators:
  • @contextlib.contextmanager

userconfigContent(*args, **kwds)

source code 

a context manager to temporarily set some content to userconfig.

This cleans up after itself and clears any userconfig cache before it sets to work.

content are RD elements without the root (resource) tag.

Decorators:
  • @contextlib.contextmanager

Variables Details

originalEnvironment

Value:
{'ADS_NO_LOOKERS': '1',
 'ADS_TOKEN': 'Eun83XFwcvIsx3CcWmBp0IpY3PZPERQHdgQNCH6I',
 'AUTOJUMP_ERROR_PATH': '/home/msdemlei/.local/share/autojump/errors.l\
og',
 'AUTOJUMP_SOURCED': '1',
 'CDROM_PATH': '/auto/cdrom',
 'COLORFGBG': '0;default',
 'COLORTERM': 'rxvt-xpm',
...

__warningregistry__

Value:
{('testhelpers imported from non-test directory.  This is almost certa\
inly not what you want (or set GAVO_OOTTEST).',
  <type 'exceptions.UserWarning'>,
  69): True}