Changeset 351
- Timestamp:
- 09/01/10 18:16:17
- Files:
-
- spongenet/trunk/spongenet/expand.py (modified) (5 diffs)
- spongenet/trunk/spongenet/parse.py (modified) (9 diffs)
- spongenet/trunk/spongenet/tests/expand/bad_config.py (modified) (1 diff)
- spongenet/trunk/spongenet/tests/expand/config.py (modified) (1 diff)
- spongenet/trunk/spongenet/tests/parse/xmlref.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spongenet/trunk/spongenet/expand.py
r348 r351 31 31 32 32 USAGE = "\n".join(__doc__.splitlines()[3:8]) 33 TEST_PATH = "tests/expand"33 TEST_PATH = os.path.join("tests", "expand") 34 34 35 35 … … 224 224 225 225 namespace = {} 226 namespace[" zipdir"] = None227 namespace[" xmldir"] = None228 namespace[" zipdir_pattern"] = None229 namespace[" zipfile_pattern"] = None230 namespace[" xmlfile_pattern"] = None226 namespace["ZIPDIR"] = None 227 namespace["XMLDIR"] = None 228 namespace["ZIPDIR_PATTERN"] = None 229 namespace["ZIPFILE_PATTERN"] = None 230 namespace["XMLFILE_PATTERN"] = None 231 231 try: 232 232 execfile(path, globals(), namespace) … … 235 235 except SyntaxError: 236 236 print USAGE 237 return (namespace[" zipdir"],238 namespace[" xmldir"],239 namespace[" zipdir_pattern"],240 namespace[" zipfile_pattern"],241 namespace[" xmlfile_pattern"],)237 return (namespace["ZIPDIR"], 238 namespace["XMLDIR"], 239 namespace["ZIPDIR_PATTERN"], 240 namespace["ZIPFILE_PATTERN"], 241 namespace["XMLFILE_PATTERN"],) 242 242 243 243 … … 354 354 for zip_month in zip_months: 355 355 # Create each monthly XML subdirectory. 356 xml_month = os.path.join(xmldir, os.path. split(zip_month)[1])356 xml_month = os.path.join(xmldir, os.path.basename(zip_month)) 357 357 if not os.path.exists(xml_month): 358 358 os.mkdir(xml_month, 0755) … … 370 370 for zip_file in zipfiles: 371 371 # Create an XML subdirectory for each zip file. 372 xml_subdir = os.path.splitext(os.path. split(zip_file)[1])[0]372 xml_subdir = os.path.splitext(os.path.basename(zip_file))[0] 373 373 xml_subdir = os.path.join(xml_month, xml_subdir) 374 374 if not os.path.exists(xml_subdir): spongenet/trunk/spongenet/parse.py
r350 r351 23 23 import os 24 24 import glob 25 import hashlib 25 26 import doctest 26 27 import unittest 27 28 from StringIO import StringIO 29 import xml.etree.ElementTree as ET 28 30 29 31 USAGE = "\n".join(__doc__.splitlines()[3:8]) 30 TEST_PATH = "tests/parse"32 TEST_PATH = os.path.join("tests", "parse") 31 33 32 34 … … 48 50 49 51 50 def doc_path():52 def xmldoc_path(): 51 53 """ 52 54 Return the XML document file path from the command line. … … 58 60 >>> sys.stdout = temp_stdout 59 61 >>> sys.argv = [] 60 >>> _ doc_path =doc_path()62 >>> _xmldoc_path = xmldoc_path() 61 63 >>> sys.stdout = save_stdout 62 64 >>> USAGE == temp_stdout.getvalue()[:-1] … … 69 71 >>> sys.stdout = temp_stdout 70 72 >>> sys.argv = ["", "", "",] 71 >>> _ doc_path =doc_path()73 >>> _xmldoc_path = xmldoc_path() 72 74 >>> sys.stdout = save_stdout 73 75 >>> USAGE == temp_stdout.getvalue()[:-1] … … 79 81 >>> temp_stdout = StringIO() 80 82 >>> sys.stdout = temp_stdout 81 >>> _ doc_path = os.path.join(82 ... os.path.dirname(83 ... os.path.abspath(__file__)),84 ... TEST_PATH)85 >>> sys.argv = ["", _ doc_path]86 >>> _ doc_path =doc_path()83 >>> _xmldoc_path = os.path.join( 84 ... os.path.dirname( 85 ... os.path.abspath(__file__)), 86 ... TEST_PATH) 87 >>> sys.argv = ["", _xmldoc_path] 88 >>> _xmldoc_path = xmldoc_path() 87 89 >>> sys.stdout = save_stdout 88 90 >>> USAGE == temp_stdout.getvalue()[:-1] … … 94 96 >>> temp_stdout = StringIO() 95 97 >>> sys.stdout = temp_stdout 96 >>> _ doc_path = os.path.join(97 ... os.path.dirname(98 ... os.path.abspath(__file__)),99 ... TEST_PATH, "xxxxx")100 >>> sys.argv = ["", _ doc_path]101 >>> _ doc_path =doc_path()98 >>> _xmldoc_path = os.path.join( 99 ... os.path.dirname( 100 ... os.path.abspath(__file__)), 101 ... TEST_PATH, "xxxxx") 102 >>> sys.argv = ["", _xmldoc_path] 103 >>> _xmldoc_path = xmldoc_path() 102 104 >>> sys.stdout = save_stdout 103 105 >>> USAGE == temp_stdout.getvalue()[:-1] … … 106 108 Supply valid XML document path argument. 107 109 108 >>> _ doc_path = os.path.join(109 ... os.path.dirname(110 ... os.path.abspath(__file__)),111 ... TEST_PATH, "xml","*","*.xml")112 >>> _ doc_path = glob.glob(_doc_path)[0]113 >>> sys.argv = ["", _ doc_path]114 >>> _ doc_path ==doc_path()110 >>> _xmldoc_path = os.path.join( 111 ... os.path.dirname( 112 ... os.path.abspath(__file__)), 113 ... TEST_PATH, "xml","*","*.xml") 114 >>> _xmldoc_path = glob.glob(_xmldoc_path)[0] 115 >>> sys.argv = ["", _xmldoc_path] 116 >>> _xmldoc_path == xmldoc_path() 115 117 True 116 118 """ … … 136 138 137 139 140 def xmldoc(path): 141 """ 142 Return the XML document as a list of strings from a file at path. 143 144 Get the test reference data. 145 146 >>> xmlref = os.path.join( 147 ... os.path.dirname( 148 ... os.path.abspath(__file__)), 149 ... TEST_PATH, "xmlref.py") 150 >>> namespace = {} 151 >>> execfile(xmlref, globals(), namespace) 152 >>> xml_doc_lens = namespace["XML_DOC_LENS"] 153 >>> xml_doc_md5s = namespace["XML_DOC_MD5S"] 154 155 Pick a test document. 156 157 >>> xmldoc_glob = os.path.join( 158 ... os.path.dirname( 159 ... os.path.abspath(__file__)), 160 ... TEST_PATH, "xml","*","*.xml") 161 >>> _xmldoc_path = glob.glob(xmldoc_glob)[0] 162 >>> _xmldoc = xmldoc(_xmldoc_path) 163 164 Verify the test document matches the reference data. 165 166 >>> _xmldoc[0] == '<?xml version="1.0" encoding="utf-8"?>\\n' 167 True 168 >>> _xmldoc[-1] == '</root>\\n' 169 True 170 >>> len(_xmldoc) == xml_doc_lens[os.path.basename(_xmldoc_path)] 171 True 172 >>> doc_hash = hashlib.md5() 173 >>> doc_hash.update("".join(_xmldoc)) 174 >>> doc_hash.hexdigest() == xml_doc_md5s[os.path.basename(_xmldoc_path)] 175 True 176 """ 177 178 _xmldoc = None 179 with open(path) as handle: 180 _xmldoc = handle.readlines() 181 182 return _xmldoc 183 184 138 185 def _main(): 139 186 """ … … 145 192 """ 146 193 147 _doc_path = doc_path() 148 if _doc_path: 149 print _doc_path 194 _xmldoc_path = xmldoc_path() 195 if _xmldoc_path: 196 _xmldoc = xmldoc(_xmldoc_path) 197 print len(_xmldoc) 150 198 151 199 return spongenet/trunk/spongenet/tests/expand/bad_config.py
r344 r351 5 5 import os 6 6 7 zipdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 8 "tests/expand/zip") 9 xmldir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 10 "tests/expand/xml") 7 EXPAND_TEST_PATH = os.path.join("tests", "expand") 8 9 ZIPDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 10 EXPAND_TEST_PATH, "zip") 11 XMLDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 12 EXPAND_TEST_PATH, "xml") 11 13 # The next line has a SyntaxError 12 zipdir_pattern= "[0-9][0-9][0-9][0-9]_[0-9][0-9]13 zipfile_pattern= "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \14 ZIPDIR_PATTERN = "[0-9][0-9][0-9][0-9]_[0-9][0-9] 15 ZIPFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 14 16 "[0-9][0-9][0-9][0-9][0-9][0-9]-" \ 15 17 "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 16 18 "[0-9][0-9][0-9][0-9][0-9][0-9].zip" 17 xmlfile_pattern= "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \19 XMLFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 18 20 "[0-9][0-9][0-9][0-9][0-9][0-9].xml" spongenet/trunk/spongenet/tests/expand/config.py
r344 r351 5 5 import os 6 6 7 zipdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 8 "tests/expand/zip") 9 xmldir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 10 "tests/expand/xml") 11 zipdir_pattern = "[0-9][0-9][0-9][0-9]_[0-9][0-9]" 12 zipfile_pattern = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 7 EXPAND_TEST_PATH = os.path.join("tests", "expand") 8 9 ZIPDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 10 EXPAND_TEST_PATH, "zip") 11 XMLDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 12 EXPAND_TEST_PATH, "xml") 13 ZIPDIR_PATTERN = "[0-9][0-9][0-9][0-9]_[0-9][0-9]" 14 ZIPFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 13 15 "[0-9][0-9][0-9][0-9][0-9][0-9]-" \ 14 16 "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 15 17 "[0-9][0-9][0-9][0-9][0-9][0-9].zip" 16 xmlfile_pattern= "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \18 XMLFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 17 19 "[0-9][0-9][0-9][0-9][0-9][0-9].xml"