diff --git a/pythoscope/generator/objects_namer.py b/pythoscope/generator/objects_namer.py index 114ad84..d65d2f3 100644 --- a/pythoscope/generator/objects_namer.py +++ b/pythoscope/generator/objects_namer.py @@ -9,6 +9,7 @@ def get_name_base_for_object(obj): common_names = {'list': 'alist', 'dict': 'adict', 'array.array': 'array', + 'datetime': 'dt', # we can't name it 'datetime', because that is module's name 'types.FunctionType': 'function', 'types.GeneratorType': 'generator'} return common_names.get(obj.type_name, underscore(obj.type_name)) diff --git a/pythoscope/inspector/static.py b/pythoscope/inspector/static.py index 3e9c911..8f91efc 100644 --- a/pythoscope/inspector/static.py +++ b/pythoscope/inspector/static.py @@ -27,10 +27,15 @@ def unindent(string): """Remove the initial part of whitespace from string. >>> unindent("1 + 2 + 3\\n") - '1 + 2 + 3\\n' + '1 + 2 + 3' >>> unindent(" def fun():\\n return 42\\n") - 'def fun():\\n return 42\\n' + 'def fun():\\n return 42' + >>> unindent("\\n def fun():\\n return 42\\n") + 'def fun():\\n return 42' + >>> unindent(" def fun():\\n return 42\\n\\n") + 'def fun():\\n return 42' """ + string = re.sub(r'^\n*', '', string.rstrip()) # ignore leading and trailing newlines match = re.match(r'^([\t ]+)', string) if not match: return string @@ -61,6 +66,8 @@ def is_generator_definition(definition): True >>> is_generator_definition(" def indented_gen():\\n yield 3\\n") True + >>> is_generator_definition("\\n def indented_gen():\\n yield 3\\n") + True """ try: return is_generator_code(function_code_from_definition(definition)) diff --git a/pythoscope/serializer.py b/pythoscope/serializer.py index 66eae11..e6fd44d 100644 --- a/pythoscope/serializer.py +++ b/pythoscope/serializer.py @@ -211,6 +211,10 @@ class LibraryObject(SerializedObject): ("Element(%s)", ["tagName", "namespaceURI", "prefix"], set([("xml.dom.minidom", "Element")])), + ('datetime', 'datetime'): + ("datetime.datetime(%s)", + ["year", "month", "day", "hour", "minute", "second", "microsecond", "tzinfo"], + set(["datetime"])), } def __init__(self, obj, serialize): diff --git a/tools/gather-metrics.py b/tools/gather-metrics.py index 8d194a8..2a9857e 100644 --- a/tools/gather-metrics.py +++ b/tools/gather-metrics.py @@ -75,7 +75,7 @@ def contains_dynamic_inspection_error(output): def run_nosetests(project_dir, test_path): notify("Running nosetests on the generated test module...") - command = "nosetests -w %s %s" % (project_dir, test_path) + command = "PYTHONPATH=%s nosetests -w %s %s" % (project_dir, project_dir, test_path) print " $", command status, output = commands.getstatusoutput(command) print output @@ -95,7 +95,7 @@ def get_test_counts(output): def run_nosetests_with_coverage(project_dir, test_path, cover_package): notify("Running nosetests with coverage on the generated test module...") - command = "nosetests --with-coverage --cover-package=%s -w %s %s" % (cover_package, project_dir, test_path) + command = "PYTHONPATH=%s nosetests --with-coverage --cover-package=%s -w %s %s" % (project_dir, cover_package, project_dir, test_path) print " $", command status, output = commands.getstatusoutput(command) print output @@ -109,6 +109,11 @@ def extract_coverage_percent(output): for line in output.splitlines(): if line.startswith("TOTAL"): return line.split()[3] + else: + # If there was only one module, coverage doesn't report TOTAL. + for line in output.splitlines(): + if "%" in line: + return line.split()[3] raise GatheringError("Can't find coverage in the output.") def cleanup_project(project_dir): @@ -165,6 +170,12 @@ def main(): appfile="isodate/*.py", testfile="tests/*.py", cover_package="isodate"), + dict(project="pyatom-1.2", + poes=["pyatom_poe_from_readme.py"], + snippets=[], + appfile="pyatom.py", + testfile="tests/*.py", + cover_package="pyatom"), ] try: results = map(lambda p: gather_metrics_from_project(**p), projects) diff --git a/tools/projects/pyatom-1.2.tar.gz b/tools/projects/pyatom-1.2.tar.gz new file mode 100644 index 0000000..0bddebd Binary files /dev/null and b/tools/projects/pyatom-1.2.tar.gz differ diff --git a/tools/projects/pyatom_poe_from_readme.py b/tools/projects/pyatom_poe_from_readme.py new file mode 100644 index 0000000..ab2a018 --- /dev/null +++ b/tools/projects/pyatom_poe_from_readme.py @@ -0,0 +1,18 @@ +from pyatom import AtomFeed +import datetime + +feed = AtomFeed(title="My Blog", + subtitle="My example blog for a feed test.", + feed_url="http://example.org/feed", + url="http://example.org", + author="Me") + +# Do this for each feed entry +feed.add(title="My Post", + content="Body of my post", + content_type="html", + author="Me", + url="http://example.org/entry1", + updated=datetime.datetime.utcnow()) + +print feed.to_string()