Permalink
Browse files

TestUtils: Create load_testdata for loading docs

  • Loading branch information...
SanketDG committed Jul 16, 2016
1 parent f731ee4 commit e442dceaa01b04d07a01a6d415903b0bd9c78584
@@ -1,10 +1,11 @@
import os
import unittest
from coalib.bearlib.languages.documentation.DocumentationComment import (
DocumentationComment)
from coalib.bearlib.languages.documentation.DocumentationExtraction import (
extract_documentation)
from tests.bearlib.languages.documentation.TestUtils import (
load_testdata)
class DocumentationCommentTest(unittest.TestCase):
@@ -13,17 +14,6 @@ class DocumentationCommentTest(unittest.TestCase):
Parameter = DocumentationComment.Parameter
ReturnValue = DocumentationComment.ReturnValue
def load_testdata(self, filename):
filename = os.path.join(os.path.dirname(
os.path.realpath(__file__)),
os.path.join("documentation_extraction_testdata",
filename))
with open(filename, "r") as test_file:
data = test_file.read()
return data.splitlines(keepends=True)
class GeneralDocumentationCommentTest(DocumentationCommentTest):
@@ -104,7 +94,7 @@ def test_return_values_default(self):
self.check_docstring(doc, expected)
def test_python_default(self):
data = self.load_testdata("default.py")
data = load_testdata("default.py")
parsed_docs = [doc.parse() for doc in
extract_documentation(data, "python", "default")]
@@ -134,7 +124,7 @@ def test_python_default(self):
self.assertEqual(parsed_docs, expected)
def test_python_doxygen(self):
data = self.load_testdata("doxygen.py")
data = load_testdata("doxygen.py")
parsed_docs = [doc.parse() for doc in
extract_documentation(data, "python", "doxygen")]
@@ -160,7 +150,7 @@ def test_python_doxygen(self):
class JavaDocumentationCommentTest(DocumentationCommentTest):
def test_java_default(self):
data = self.load_testdata("default.java")
data = load_testdata("default.java")
parsed_docs = [doc.parse() for doc in
extract_documentation(data, "java", "default")]
@@ -1,4 +1,3 @@
import os.path
import unittest
from coalib.bearlib.languages.documentation.DocstyleDefinition import (
@@ -7,6 +6,8 @@
DocumentationComment)
from coalib.bearlib.languages.documentation.DocumentationExtraction import (
extract_documentation)
from tests.bearlib.languages.documentation.TestUtils import (
load_testdata)
from coalib.results.TextRange import TextRange
@@ -16,17 +17,8 @@ def test_extract_documentation_invalid_input(self):
with self.assertRaises(FileNotFoundError):
tuple(extract_documentation("", "PYTHON", "INVALID"))
@staticmethod
def load_testdata(filename):
filename = (os.path.dirname(os.path.realpath(__file__)) +
"/documentation_extraction_testdata/" + filename)
with open(filename, "r") as fl:
data = fl.read()
return data.splitlines(keepends=True)
def test_extract_documentation_C(self):
data = DocumentationExtractionTest.load_testdata("data.c")
data = load_testdata("data.c")
# No built-in documentation for C.
with self.assertRaises(KeyError):
@@ -83,7 +75,7 @@ def test_extract_documentation_C_2(self):
TextRange.from_values(1, 1, 2, 21))])
def test_extract_documentation_CPP(self):
data = DocumentationExtractionTest.load_testdata("data.cpp")
data = load_testdata("data.cpp")
# No built-in documentation for C++.
with self.assertRaises(KeyError):
@@ -127,7 +119,7 @@ def test_extract_documentation_CPP(self):
TextRange.from_values(32, 1, 37, 1))))
def test_extract_documentation_CPP_2(self):
data = DocumentationExtractionTest.load_testdata("data2.cpp")
data = load_testdata("data2.cpp")
docstyle_CPP_doxygen = DocstyleDefinition.load("CPP", "doxygen")
@@ -140,7 +132,7 @@ def test_extract_documentation_CPP_2(self):
TextRange.from_values(1, 1, 3, 4)),))
def test_extract_documentation_PYTHON3(self):
data = DocumentationExtractionTest.load_testdata("data.py")
data = load_testdata("data.py")
docstyle_PYTHON3_default = DocstyleDefinition.load("PYTHON3",
"default")
docstyle_PYTHON3_doxygen = DocstyleDefinition.load("PYTHON3",
@@ -0,0 +1,13 @@
import os
def load_testdata(filename):
filename = os.path.join(os.path.dirname(
os.path.realpath(__file__)),
os.path.join("documentation_extraction_testdata",
filename))
with open(filename) as test_file:
data = test_file.read()
return data.splitlines(keepends=True)

0 comments on commit e442dce

Please sign in to comment.