Skip to content

Commit

Permalink
some windowsfixes, but still 3 failures, 7 errors (mostly CRLF newlin…
Browse files Browse the repository at this point in the history
…es messing up comparisons, and some unclosed files preventing cleanup removals
  • Loading branch information
staffanm committed Nov 2, 2013
1 parent f7377df commit f7bd9e8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
6 changes: 5 additions & 1 deletion ferenda/documentrepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,11 @@ def transform(uri):
pseudobasefile = "index"
path = repo.store.path(pseudobasefile, 'toc', '.html')
if path:
return os.path.relpath(path, basedir)
relpath = os.path.relpath(path, basedir)
if os.sep == "\\":
relpath = relpath.replace(os.sep, "/")
return relpath

else:
return uri
return transform
Expand Down
1 change: 1 addition & 0 deletions ferenda/fulltextindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def update(self, uri, repo, basefile, title, identifier, text, **kwargs):
def commit(self):
if self._writer:
self._writer.commit()
self._writer.close()
if not isinstance(self._writer, whoosh.writing.BufferedWriter):
# A bufferedWriter can be used again after commit(), a regular writer cannot
self._writer = None
Expand Down
7 changes: 4 additions & 3 deletions ferenda/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,15 @@ def link_or_copy(src, dst):
ensure_dir(dst)
if os.path.lexists(dst):
os.unlink(dst)
if os.symlink:
if sys.platform == 'win32':
# windows python have no working sumlink
copy_if_different(src, dst)
else:
# The semantics of symlink are not identical to copy. The
# source must be relative to the dstination, not relative to
# cwd at creation time.
relsrc = os.path.relpath(src, os.path.dirname(dst))
os.symlink(relsrc, dst)
else:
copy_if_different(src, dst)


# util.string
Expand Down
32 changes: 16 additions & 16 deletions test/testDevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ def test_mkpatch(self):
downloaded_path = store.downloaded_path(basefile)
def my_download_single(self):
# this function simulates downloading
with open(downloaded_path, "w") as fp:
with open(downloaded_path, "wb") as fp:
fp.write("""This is a file.
It has been downloaded.
""")
""".encode())

repo = DocumentRepository(datadir=tempdir)
with repo.store.open_downloaded(basefile, "w") as fp:
with repo.store.open_downloaded(basefile, "wb") as fp:
fp.write("""This is a file.
It has been patched.
""")
""".encode())

d = Devel()
globalconf = LayeredConfig({'datadir':tempdir,
Expand All @@ -93,10 +93,10 @@ def my_download_single(self):
self.assertIn("+It has been patched.", patchcontent)

# test 2: Same, but with a multi-line desc
with repo.store.open_downloaded(basefile, "w") as fp:
with repo.store.open_downloaded(basefile, "wb") as fp:
fp.write("""This is a file.
It has been patched.
""")
""".encode())
longdesc = """A longer comment
spanning
several lines"""
Expand All @@ -114,17 +114,17 @@ def my_download_single(self):
# test 3: If intermediate file exists, patch that one
intermediate_path = store.intermediate_path(basefile)
util.ensure_dir(intermediate_path)
with open(intermediate_path, "w") as fp:
with open(intermediate_path, "wb") as fp:
fp.write("""This is a intermediate file.
It has been patched.
""")
""".encode())
intermediate_path = store.intermediate_path(basefile)
def my_parse(self, basefile=None):
# this function simulates downloading
with open(intermediate_path, "w") as fp:
with open(intermediate_path, "wb") as fp:
fp.write("""This is a intermediate file.
It has been processed.
""")
""".encode())
with patch('ferenda.DocumentRepository.parse') as mock:
mock.side_effect = my_parse
patchpath = d.mkpatch("base", basefile, "Example patch")
Expand Down Expand Up @@ -152,7 +152,7 @@ class Parser(object):
def parse(self, source):
res = Body()
for chunk in source:
res.append(Paragraph([str(len(chunk))]))
res.append(Paragraph([str(len(chunk.strip()))]))
return res
""")

Expand Down Expand Up @@ -182,7 +182,7 @@ def parse(self, source):
<str>22</str>
</Paragraph>
<Paragraph>
<str>13</str>
<str>12</str>
</Paragraph>
</Body>
""".strip()+"\n"
Expand All @@ -192,13 +192,13 @@ def parse(self, source):

def test_construct(self):
uri = "http://example.org/doc"
with open("testconstructtemplate.rq", "w") as fp:
with open("testconstructtemplate.rq", "wb") as fp:
fp.write("""PREFIX dct: <http://purl.org/dc/terms/>
CONSTRUCT { ?s ?p ?o . }
WHERE { ?s ?p ?o .
<%(uri)s> ?p ?o . }
""")
""".encode())
g = Graph()
g.bind("dct", str(DCT))
g.add((URIRef(uri),
Expand Down Expand Up @@ -240,12 +240,12 @@ def test_construct(self):

def test_select(self):
uri = "http://example.org/doc"
with open("testselecttemplate.rq", "w") as fp:
with open("testselecttemplate.rq", "wb") as fp:
fp.write("""PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?p ?o
WHERE { <%(uri)s> ?p ?o . }
""")
""".encode())

result = """
[
Expand Down
4 changes: 2 additions & 2 deletions test/testDocRepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,8 +2291,8 @@ def test_successful_patch_with_desc(self):
patchdesc = """This is a longer patch description.
It can span several lines."""
with open(descpath, "w") as fp:
fp.write(patchdesc)
with open(descpath, "wb") as fp:
fp.write(patchdesc.encode())

result, desc = self.repo.patch_if_needed("123/a", self.sourcedoc)
self.assertEqual(patchdesc, desc)
Expand Down
2 changes: 1 addition & 1 deletion tools/test.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SET SKIP_SLEEPYCAT_TESTS=1
SET SKIP_ELASTICSEARCH_TESTS=1
SET FERENDA_PYTHON2_FALLBACK="C:\Python27\python.exe"
IF [%1] == [] (
python -Wi -m unittest discover -v -f test
python -Wi -m unittest discover -v test
) ELSE (
SET PYTHONPATH=test
python -Wi -m unittest -v %1
Expand Down

0 comments on commit f7bd9e8

Please sign in to comment.