Jan Borsodi committed 1d7ea37

Fixes to tests to ensure they can access tests files relative to the test itself.
Also normalized newlines from output generators.

Comments (0)

Files changed (2)


 import difflib
+import re
+from os.path import dirname, join
 from hob.proto import PackageManager
 from hob.template import TextGenerator
             print line,
     assert out == expected
+def fixpath(fname):
+    return join(dirname(__file__), fname)
 def processProto(fname, syntax="scope", export=["package", "service", "message", "enum"]):
     manager = PackageManager()
     package = manager.loadFile(fname)
     gen = TextGenerator(syntax=syntax)
     text = gen.package(package, export=export)
+    text = re.sub(r"\r\n", "\n", text)
     return text
 def test_basic_messages():
-    text = processProto("tests/proto/basic.proto")
-    expected = open("tests/syntax_scope/basic.proto").read()
+    text = processProto(fixpath("proto/basic.proto"))
+    expected = open(fixpath("syntax_scope/basic.proto")).read()
     compareOutput(text, expected)
 def test_composed_messages():
-    text = processProto("tests/proto/composed.proto")
-    expected = open("tests/syntax_scope/composed.proto").read()
+    text = processProto(fixpath("proto/composed.proto"))
+    expected = open(fixpath("syntax_scope/composed.proto")).read()
     compareOutput(text, expected)
 def test_enums():
-    text = processProto("tests/proto/enums.proto")
-    expected = open("tests/syntax_scope/enums.proto").read()
+    text = processProto(fixpath("proto/enums.proto"))
+    expected = open(fixpath("syntax_scope/enums.proto")).read()
     compareOutput(text, expected)
 def test_options():
-    text = processProto("tests/proto/options.proto")
-    expected = open("tests/syntax_scope/options.proto").read()
+    text = processProto(fixpath("proto/options.proto"))
+    expected = open(fixpath("syntax_scope/options.proto")).read()
     compareOutput(text, expected)


 import os
+from os.path import dirname, join
 from hob.parser import Lexer, create_lexer_rules, PackageBuilder, Loader, ParseError, BuildError
 from hob.proto import Package, Request, Event, Message, Proto
+def fixpath(fname):
+    return join(dirname(__file__), fname)
 class FakeLoadError(Exception):
 def load(filename):
     l = Lexer(create_lexer_rules())
-    loader = PathLoader(l, "tests/proto")
+    loader = PathLoader(l, fixpath("proto"))
     pkg = Package(filename)
     builder = PackageBuilder(pkg, loader)
     loader.load(filename, builder)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.