Commits

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.

  • Participants
  • Parent commits 3e8afef
  • Branches release-0.x

Comments (0)

Files changed (2)

File tests/test_command_proto.py

 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)

File tests/test_parser.py

 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):
     pass
 
 
 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)