def setUp(self): self.indexpath = testcfg.getpath('archiveindex') self.assertEqual( self.indexpath,'testdata/archive/index') # check to prevent deleting things in wrong dir due to config goof _purge(self.indexpath) # start with empty index self.arcdocpath = testcfg.getpath('archive') self.assertEqual(self.arcdocpath,'testdata/archive') try: self.arcdocpath.makedirs() except OSError, e: # ignore OSError: [Errno 17] File exists if e.errno != 17: raise
def setUp(self): logpath = testcfg.getpath('logs') # check test path to avoid config goof # we will delete files! self.assert_('testlogs' in logpath) self.qlogpath = logpath/(self.FILE_BASE+'.qlog') self.mlogpath = logpath/(self.FILE_BASE+'.mlog') self.cleanup()
def testSafeConfig(self): # make sure we are using safe test config keys = [n for n,v in cfg.cparser.items('path')] # take these items outside of test keys.remove('docbase') keys.remove('testdoc') # check that the above code do what we want self.assert_('data' in keys) self.assert_('logs' in keys) self.assert_('weblibsnapshot' in keys) self.assert_('archiveindex' in keys) for name in keys: self.assert_('test' in cfg.getpath(name)) # we get test path even if we import from config from minds.config import cfg as config_cfg for name in keys: self.assert_('test' in config_cfg.getpath(name))
def setUp(self): messagelog.mlog = messagelog.MsgLogger() # prepare some configuration for this test self.interval0 = testcfg.get('indexing.interval' ) self.numDoc0 = testcfg.get('indexing.numDoc' ) self.max_interval0 = testcfg.get('indexing.max_interval') testcfg.set('indexing.interval' , '3' ) testcfg.set('indexing.numDoc' , '5' ) testcfg.set('indexing.max_interval', '360') # make dummy queued msg 0.tmp self.logpath = testcfg.getpath('logs') self.path0 = self.logpath/'0.tmp' self.path0.touch() # create empty file dt0 = datetime.datetime(2000,1,1,10,00,0) mtime = time.mktime(dt0.timetuple()) # first queued: 2000-1-1 10:00 localtime self.path0.utime((mtime, mtime))
def setup_debug_weblib(filename_or_data): """ Helper function to setup the weblib directory """ # should only call this from debug or testing mode from minds.safe_config import cfg as testcfg test_path = testcfg.getpath('weblib')/Store.DEFAULT_FILENAME assert 'test' in test_path # clean the weblib directory files = [test_path] + ['%s.%s' % (test_path, i+1) for i in range(Store.BACKUP_COUNT)] for f in files: try: path(f).remove() except OSError: pass getStore().reset() getWeblib().reset() if not filename_or_data: return # blank data is fine if isinstance(filename_or_data, path) or ('\n' not in filename_or_data): # treat as filename src = path(filename_or_data) src.copyfile(test_path) else: # treat as data fp = file(test_path,'wb') fp.write(filename_or_data) fp.close() getStore().load(test_path)
def testGetPath(self): datapath = cfg.getpath('data') # Test # a. data is a path object. # b. datapath exists (because implicit call to setupPaths() self.assert_(datapath.exists())
# -*- coding: utf-8 -*- import datetime import sets import StringIO import sys import unittest from minds.safe_config import cfg as testcfg from minds import weblib from minds.weblib import store testpath = testcfg.getpath('testDoc') class TestTag(unittest.TestCase): def test0(self): # empty name not allowed self.assertRaises(ValueError, weblib.Tag, name='') def test_hasIllegalChar(self): illegal = ',@#+:<>' self.assert_(weblib.Tag.hasIllegalChar(illegal)) self.assert_(weblib.Tag.hasIllegalChar('filler,')) self.assert_(weblib.Tag.hasIllegalChar('filler@')) self.assert_(weblib.Tag.hasIllegalChar('filler#')) self.assert_(weblib.Tag.hasIllegalChar('filler+')) self.assert_(weblib.Tag.hasIllegalChar('filler:')) self.assert_(weblib.Tag.hasIllegalChar('filler<')) self.assert_(weblib.Tag.hasIllegalChar('filler>')) xascii = r""" !"$%&'()*-./0123456789;=?ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~""" + '\x7f'
def setUp(self): self.indexpath = testcfg.getpath('archiveindex') self.apath = testcfg.getpath('archive') self._cleanup() self.populateTestDocs()
import StringIO import sys import unittest import urllib from minds.safe_config import cfg as testcfg from minds import app_httpserver from minds.cgibin import weblib as weblib_cgi from minds.util import fileutil from minds.util import patterns_tester from minds import weblib from minds.weblib import query_wlib from minds.weblib import store test_path = testcfg.getpath('testDoc')/'test_weblib/weblib.dat' class TestCGIBase(unittest.TestCase): def setUp(self): store.setup_debug_weblib(test_path) def tearDown(self): # TODO HACK: close any open file before replace. # Need comphrensive review store.getStore().reset() def _run_url(self, path): """ Invoke the URL and return the response HTTP message """ buf = fileutil.aStringIO()
def setUp(self): self.indexpath = testcfg.getpath('archiveindex') self.cleanup()
# -*- coding: utf-8 -*- import datetime import os import os.path import sets import StringIO import sys import unittest from minds.safe_config import cfg as testcfg from minds import weblib from minds.weblib import store testpath = testcfg.getpath("testDoc") class TestDsvUtil(unittest.TestCase): # list of (encoded string, decoded fields) DATA = [ ("", [""]), # 0 field (r"a", ["a"]), # 1 field (r"a|b|c", ["a", "b", "c"]), # 3 fields (r"|b", ["", "b"]), # start with bar (r"a|", ["a", ""]), # end with bar (r"a||b", ["a", "", "b"]), # consecutive bars (r"\x7Ca|b\x7C|\x7Cc\x7C", ["|a", "b|", "|c|"]), # bars escaped (r"\\a|b\\|\\c\\", ["\\a", "b\\", "\\c\\"]), # slashes escaped (r"\\a|\\\x7C|\x7Cc\\", ["\\a", "\\|", "|c\\"]), # bars and slashes escaped (r"1\n2|3\n\n4", ["1\n2", "3\n\n4"]), # \n escaped (r"m\\n", ["m\\n"]), # escape \, not \n
import StringIO import unittest from minds.safe_config import cfg as testcfg from minds.util import fileutil from minds.util.fileutil import BoundedFile, RecordFile testpath = testcfg.getpath('data') assert 'test' in testpath class TestBoundedFile(unittest.TestCase): def test_boundedFile(self): buf = StringIO.StringIO() bfp = BoundedFile(buf, 10) bfp.write('12345') self.assert_(not bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 5) bfp.write('678') self.assert_(not bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 8) bfp.write('90ab') self.assert_(bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 8) # although bfp is still 2 characters below maxsize # make sure once it is overflowed you cannot write anymore bfp.write('c')
def setUp(self): self.apath = testcfg.getpath('archive') self.cleanup()