Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding fixtures for git project support and finishing tests

  • Loading branch information...
commit a7841edc23d43d825fd069165d0a42e84575e63a 1 parent ee91476
@aconbere authored
View
8 igor/documents.py
@@ -138,16 +138,16 @@ def summary(self, length):
def published_date(self):
header_published_date = self.headers.get('published_date')
- return header_published_date or self.extra_data['published_date'] or \
+ return header_published_date or self.extra_data.get('published_date') or \
datetime.now()
def author(self):
- headers_author = self.text_file.headers.get('author')
- return header_author or self.extra_data['author'] or ""
+ header_author = self.text_file.headers.get('author')
+ return header_author or self.extra_data.get('author') or ""
def author_email(self):
header_email = self.text_file.headers.get('email')
- return header_email or self.extra_data['author_email'] or ""
+ return header_email or self.extra_data.get('author_email') or ""
def publish_directory(self, date_format = "%Y/%m/%d"):
return path.join(self.published_date().strftime(date_format),
View
15 igor/tools.py
@@ -1,6 +1,8 @@
from __future__ import with_statement
from os import walk, path, makedirs, removedirs
+from pkg_resources import resource_filename
+import yaml
from shutil import copytree, rmtree
from documents import HomePage, Post, Feed, Archive, Document
@@ -34,7 +36,7 @@ def make_posts(start_path, prefix, extensions=[".txt"]):
and returns each file to the Post class
"""
posts_path = path.join(start_path, prefix)
- vcs_cls = vcs.get(vcs.type(start_path))
+ vcs_cls = vcs.get(vcs.project_type(start_path))
def make_post(f):
extra_data = vcs_cls(start_path, f).data()
@@ -68,3 +70,14 @@ def publish(source, destination=""):
publisher.publish()
copy_supporting_files(config['source'], config['destination'])
return True
+
+def init(destination):
+ init_path = resource_filename("igor_extras",
+ "initial_project")
+ copytree(init_path, destination)
+
+ with open(path.join(destination, "_config.yaml"), 'w') as f:
+ yaml_config = yaml.dump(Config.defaults,
+ default_flow_style=False)
+ f.write(yaml_config)
+ return True
View
2  igor/vcs/__init__.py
@@ -1 +1 @@
-from vcs import type, get, NullVCS
+from vcs import project_type, get, NullVCS
View
17 igor/vcs/git/__init__.py
@@ -1,22 +1,25 @@
from log import Log
+from igor.utils import relpath
+
class Git(object):
def __init__(self, project_path, file_path):
self.project_path = project_path
self.file_path = file_path
- self.relpath = relpath(self.project_path, self.filename)
+ self.relpath = relpath(self.file_path, self.project_path)
self.headers, self.comment = Log(self.project_path).call(self.relpath)
+ print(self.headers)
def published_date(self):
- return self.headers['datetime'].datetime
+ return self.headers['author'].datetime
- def author_email(self):
- return self.headers['email'].name
+ def author(self):
+ return self.headers['author'].name
- def email(self):
+ def author_email(self):
return self.headers['author'].email
def data(self):
- return {'email': self.email(),
- 'author': self.author_email(),
+ return {'email': self.author_email(),
+ 'author': self.author(),
'published_date': self.published_date()}
View
4 igor/vcs/git/log.py
@@ -41,14 +41,14 @@ def call(self, filename):
p.wait()
if p.returncode != 0:
- print("freakout!")
+ raise Exception("Not a git repository")
else:
out = p.stdout.read()
headers, comment = self.sections(out)
headers = self.retreive_headers(headers)
comment = "\n".join(comment).strip()
- return(headers, comment)
+ return(headers, comment)
@classmethod
def grammer(cls):
View
14 igor/vcs/vcs.py
@@ -5,7 +5,7 @@
systems = {}
-def type(project_path):
+def project_type(project_path):
dirs = list_dirs(project_path)
if ".git" in dirs:
return "git"
@@ -19,18 +19,18 @@ def type(project_path):
return "cvs"
return None
-def get(type):
+def get(project_type):
for k,v in systems.iteritems():
- if k == type:
+ if k == project_type:
return v
return NullVCS
-def register(type, cls):
- systems[type] = cls
+def register(project_type, cls):
+ systems[project_type] = cls
class NullVCS(object):
- def __init__(self, text_file, project_path):
- self.text_file = text_file
+ def __init__(self, project_path, file_path):
+ self.file_path = file_path
self.project_path = path.abspath(path.expanduser(project_path))
def author(self):
View
10 scripts/igor
@@ -16,6 +16,7 @@ from igor import version
from igor import tools
from igor import markup
from igor.config import Config
+from igor.tools import init
parser = OptionParser(
usage = "igor COMMAND [OPTIONS]",
@@ -91,15 +92,8 @@ class InitCommand(Command):
sys.exit(1)
print("Initializing new igor project: %s" % out_path)
+ init(out_path)
- init_path = pkg_resources.resource_filename("igor_extras",
- "initial_project")
- copytree(init_path, out_path)
-
- with open(path.join(out_path, "_config.yaml"), 'w') as f:
- yaml_config = yaml.dump(Config.defaults,
- default_flow_style=False)
- f.write(yaml_config)
register(InitCommand.name, InitCommand)
class PublishCommand(Command):
View
50 test/conftest.py
@@ -0,0 +1,50 @@
+import sys
+from shutil import rmtree
+from os import path, chdir
+from subprocess import check_call as call
+
+sys.path.append(".")
+
+from igor.tools import init
+
+test_project = "/tmp/igor.test"
+test_output = "/tmp/blog.test"
+
+def initialize_test_project():
+ try:
+ rmtree(test_project)
+ except:
+ pass
+ init(test_project)
+
+ current_dir = path.abspath("")
+ chdir(test_project)
+ call(["git", "init"])
+ call(["git", "add", "."])
+ call(["git", "commit", "-m", "first commit"])
+ chdir(current_dir)
+
+ return test_project
+
+def initialize_test_file():
+ project = initialize_test_project()
+ return path.join(project, "_posts/welcome.txt")
+
+def teardown_test_project(a):
+ try:
+ rmtree(test_project)
+ except:
+ pass
+
+def pytest_funcarg__project(request):
+ return request.cached_setup(
+ setup = initialize_test_project,
+ teardown = teardown_test_project,
+ scope = "module")
+
+def pytest_funcarg__file(request):
+ return request.cached_setup(
+ setup = initialize_test_file,
+ teardown = teardown_test_project,
+ scope = "module")
+
View
15 test/test_config.py
@@ -1,26 +1,25 @@
import sys
-import os
-from pkg_resources import resource_filename
+from os import path
+from shutil import rmtree
sys.path.append(".")
from igor.config import Config
-def test_config():
- source = "./igor_extras/initial_project"
- destination = "/tmp/igor_unit_tests"
- c = Config(source, destination).data()
+def test_config(project):
+ destination = "/tmp/blog.test"
+ c = Config(project, destination).data()
assert(c['author'] == "John Doe")
assert(c['email'] == "jdoe@example.com")
assert(c['blog_title'] == "Welcome to Igor")
assert(c['destination'] == destination)
- assert(c['publish_dir'].endswith("blog/"))
+ assert(c['publish_dir'] == destination+"/") # no publish prefix
assert(c['blog_url'] == "http://example.com/")
assert(c['media_url'] == "http://media.example.com/")
assert(c['summary_length'] == 10)
assert(c['templates_prefix'] == "_templates")
assert(c['posts_prefix'] == "_posts")
- assert(c['source'].endswith("/igor_extras/initial_project"))
+ assert(c['source'] == project)
assert(c['posts_dir'])
assert(c['templates_dir'])
View
37 test/test_documents.py
@@ -1,14 +1,10 @@
import sys
-import os
+from os import path
sys.path.append(".")
-from igor.documents import Document, Post, HomePage, HeaderParser,\
+from igor.documents import Document, Post, HomePage, TextFile,\
find_document
-from igor.utils import slugify
-
-test_project = "./igor_extras/initial_project"
-test_file = path.join(test_project, "_posts/welcome.txt")
def test_document():
d = Document("slug")
@@ -18,30 +14,30 @@ def test_document():
def test_find_document():
ds = [Document("a"), Document("slug"), Document("slug"),
Document("b"), Document("c")]
- d = find_document([p], "slug")
- assert(d.slug = "slug")
+ d = find_document(ds, "slug")
+ assert(d.slug == "slug")
-def test_text_file():
- t = TextFile(test_file)
+def test_text_file(file):
+ t = TextFile(file)
assert(isinstance(t.headers, dict))
assert(t.title)
assert(t.body)
-def test_text_file_pop_section():
- t = TextFile(test_file)
+def test_text_file_pop_section(file):
+ t = TextFile(file)
top, rest = t.pop_section("this is the first section\n\nthis is the second\n\n".splitlines())
assert(top == "this is the first section")
-def test_text_file_parse():
+def test_text_file_parse(file):
content = "this: 'is a header'\n\nwith a title\n\nand content"
- t = TextFile(test_file)
+ t = TextFile(file)
headers, title, body = t.parse(content)
assert(headers == {'this': 'is a header'})
assert(title == "with a title")
assert(body == "and content")
-def test_post():
- p = Post(TextFile(test_file))
+def test_post(file):
+ p = Post(file)
assert(p.title)
assert(p.slug)
assert(p.filename)
@@ -49,12 +45,11 @@ def test_post():
assert(p.markup())
assert(p.summary(1))
assert(p.published_date())
- assert(p.author())
- assert(p.author_email())
+ assert(p.author() == "")
+ assert(p.author_email() == "")
-def test_home_page():
- f = "./examples/init/_posts/welcome.txt"
- p = Post(f, "./examples/init")
+def test_home_page(file):
+ p = Post(file)
h = HomePage([p])
assert(h)
assert(isinstance(h.headers, dict))
View
9 test/test_git.py
@@ -1,14 +1,13 @@
import sys
import os
+from os import path
sys.path.append(".")
from igor.vcs.git import Git
-test_project = "./igor_extras/initial_project"
-test_file = path.join(test_project, "_posts/welcome.txt")
-
-def test_git():
- g = Git(test_project, test_file)
+def test_git(project):
+ file = path.join(project, "_posts/welcome.txt")
+ g = Git(project, file)
assert(g.author_email())
assert(g.published_date())
assert(g.author())
View
13 test/test_git_log.py
@@ -1,5 +1,6 @@
import sys
import os
+from os import path
sys.path.append(".")
from igor.vcs.git.log import Log, Actor
@@ -15,7 +16,7 @@ def test_log_parsing():
first run at the parser
"""
- log = Log("fake/dir", "fake_file")
+ log = Log("fake/dir")
headers, comment = log.sections(test_git_log)
hs = log.retreive_headers(headers)
check_data = {
@@ -34,10 +35,10 @@ def test_log_parsing():
assert([(k, str(v)) for k,v in hs.iteritems()] == [(k,str(v)) for k,v in check_data.iteritems()])
assert("\n".join(comment).strip() == "first run at the parser")
-def test_log_retrieval():
+def test_log_retrieval(project):
curdir = os.path.abspath(os.curdir)
- l = Log("examples/init", "_posts/welcome.txt")
- l.call()
+ l = Log(project)
+ headers, comment = l.call("_posts/welcome.txt")
test_headers = {
"commit": Ref("commit",
"4906ae03a875febcdc1fbd6b3d1d8d6f83ff309d"),
@@ -48,7 +49,7 @@ def test_log_retrieval():
"aconbere@gmail.com", "1248138252",
"1000")
}
- assert(l.comment)
+ assert(comment)
header_keys = ["commit", "committer", "tree", "author"]
- assert([k for k,v in l.headers.iteritems()] == header_keys)
+ assert([k for k,v in headers.iteritems()] == header_keys)
View
8 test/test_git_ls_tree.py
@@ -4,6 +4,8 @@
from igor.git.ls_tree import ListTree, ListElement
+test_project = "/tmp/igor.test"
+
def test_list_item_parsing():
test_element = ListElement("100644", "blob", "ddec4c671efebd5b61b219d2de49c828f6a4d956", "_gitignore")
l = ListElement.from_string("100644 blob ddec4c671efebd5b61b219d2de49c828f6a4d956 _gitignore")
@@ -16,7 +18,7 @@ def test_list_parsing():
100644 blob 33436dc95ca1755a459a4dd9f7992b45008f3837 example.txt
"""
- l = ListTree("examples/init/")
+ l = ListTree(test_project)
elements = l.parse_list(test_list)
assert_data = [
ListElement("100644", "blob", "902edab1599d6bcb08854e004362a6af2889ffbb", "_config.yaml"),
@@ -25,7 +27,7 @@ def test_list_parsing():
]
assert([str(s) for s in elements] == [str(s) for s in assert_data])
-def test_list_retrieval():
- l = ListTree("examples/init")
+def test_list_retrieval(project):
+ l = ListTree(project)
l.call()
assert(len(l.elements) > 0)
View
17 test/test_publisher.py
@@ -1,17 +1,20 @@
import sys
from os import path
+from shutil import rmtree
sys.path.append(".")
from igor.publisher import Publisher
from igor.documents import Post
-test_dest = "/tmp/igor.test"
-test_template_dir = "./examples/init/_templates"
-test_context = {}
+def test_publisher(project):
+ context = {}
+ destination = "/tmp/blog.test"
+ file = path.join(project, "_posts/welcome.txt")
+ template_dir = path.join(project, "_templates")
-def test_publisher():
- post = Post("./examples/init/_posts/welcome.txt", "./examples/init")
- p = Publisher([post], test_dest, test_template_dir, test_context)
+ post = Post(file)
+ p = Publisher([post], destination, template_dir, context)
assert(p.publish())
- assert(path.exists(path.join(test_dest, post.publish_directory())))
+ assert(path.exists(path.join(destination, post.publish_directory())))
+ rmtree(destination)
View
45 test/test_tools.py
@@ -1,37 +1,50 @@
import sys
from os import path, listdir
+from shutil import rmtree
sys.path.append(".")
-from igor.tools import find_files, make_posts, publish
+from igor.tools import find_files, make_posts, publish, init
from igor.documents import Document
-test_project = "./igor_extras/initial_project"
-
-def test_find_files():
+def test_find_files(project):
+ posts_path = path.join(project, "_posts")
extensions = [".txt", ".mkd"]
- files = list(find_files(path.abspath(test_project), extensions=extensions))
+ files = list(find_files(posts_path, extensions=extensions))
assert(len(files) >= 1)
+
for file in files:
name, ext = path.splitext(file)
assert(path.exists(file))
assert(ext in extensions)
-def test_make_posts():
- ps = list(make_posts(test_project,
+def test_make_posts(project):
+ ps = list(make_posts(project,
"_posts",
extensions = [".txt", ".mkd"]))
assert(len(ps) >= 1)
-def test_publish():
- from shutil import rmtree
+def test_publish(project):
+ destination = "/tmp/blog.test"
+ published = publish(project, destination)
+ assert(published)
+ assert(path.exists("/tmp/blog.test"))
+ assert(path.exists("/tmp/blog.test/index.html"))
+ assert(path.exists("/tmp/blog.test/feed.atom"))
+ rmtree(destination)
+ # It would be great to add a test for the existance of a post
+
+def test_init():
+ destination = "/tmp/igor.test"
try:
- rmtree("/tmp/igor.test")
+ rmtree(destination)
except:
pass
- published = publish(test_project, "/tmp/igor.test")
- assert(published)
- assert(path.exists("/tmp/igor.test"))
- assert(path.exists("/tmp/igor.test/index.html"))
- assert(path.exists("/tmp/igor.test/feed.atom"))
- # It would be great to add a test for the existance of a post
+
+ init(destination)
+ assert(path.exists(destination))
+ assert(path.exists(path.join(destination, "_posts")))
+ assert(path.exists(path.join(destination, "_templates")))
+ assert(path.exists(path.join(destination, "media")))
+ assert(path.exists(path.join(destination, "_config.yaml")))
+ rmtree(destination)
View
2  test/test_utils.py
@@ -1,6 +1,4 @@
import sys
-import os
-
sys.path.append(".")
from igor.utils import hidden, slugify
View
12 test/test_vcs.py
@@ -1,17 +1,15 @@
import sys
-import os
sys.path.append(".")
-from igor.vcs import type, get, NullVCS
+from igor.vcs import NullVCS, get, project_type
from igor.vcs.git import Git
-test_project = "./igor_extras/initial_project"
-def test_vcs_type():
- assert(type(test_project), "none")
+def test_vcs_type(project):
+ pt = project_type(project)
+ assert(pt == "git")
def test_get():
assert(get("git") == Git)
- assert(get("none") == NullVCS)
+ assert(get(None) == NullVCS)
-
Please sign in to comment.
Something went wrong with that request. Please try again.