Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def find_protoc():
if protoc is None:
sys.stderr.write(
'protoc not found. Is protobuf-compiler installed? \n'
'Alternatively, you can point the PROTOC environment variable'
'at a local version.')
'Alternatively, you can point the PROTOC environment variable '
'to a local version.')
sys.exit(1)
return protoc

Expand Down
34 changes: 13 additions & 21 deletions tests/test_comment_type.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import sys
import unicodedata
import re
from glob import *
import glob
import unittest

PROTO_FILES = glob.glob("*.proto")

class TestCommentType(unittest.TestCase):
''' Test class for mandatory new line. '''
''' Test class for mandatory comments. '''

def test_brief_necessity(self):
''' Test the necessity of "brief" comment. '''

for file in glob("*.proto"):
with open(file, "rt") as fin:
i = 0
for file in PROTO_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
noMessage = 0
noComment = 0
hasBrief = False
saveStatement = ""

for line in fin:
i += 1
for i, line in enumerate(fin, start=1):

# Divide statement and comment. Concatenate multi line statements.

Expand Down Expand Up @@ -57,7 +56,7 @@ def test_brief_necessity(self):
noComment += 1;
if comment.find("\\brief") != -1:
hasBrief = True

elif len(saveStatement) == 0:
if re.search(r"\bmessage\b", statement) is not None or re.search(r"\bextend\b",statement) is not None:
self.assertTrue(hasBrief, file + " in line " + str(i - 1) + ": \\brief section in comment is missing for: '" + statement + "'")
Expand All @@ -73,18 +72,15 @@ def test_brief_necessity(self):
def test_min_two_lines(self):
''' Test to check if short comment is of minimum two lines. '''

for file in glob("*.proto"):
with open(file, "rt") as fin:
i = 0
for file in PROTO_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
isEnum = False
noMessage = 0
noComment = 0
hasBrief = False
saveStatement = ""

for line in fin:
i += 1

for i, line in enumerate(fin, start=1):
# Divide statement and comment. Concatenate multi line statements.

# Search for comment ("//").
Expand Down Expand Up @@ -129,19 +125,15 @@ def test_min_two_lines(self):
def test_comment_existence(self):
''' Test to check if every message, extend , statement or enum has a comment. '''

for file in glob("*.proto"):

with open(file, "rt") as fin:
i = 0
for file in PROTO_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
isEnum = False
noMessage = 0
noComment = 0
hasBrief = False
saveStatement = ""

for line in fin:
i += 1

for i, line in enumerate(fin, start=1):
# Divide statement and comment. Concatenate multi line statements.

# Search for comment ("//").
Expand Down
41 changes: 14 additions & 27 deletions tests/test_doxygen_output.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
import sys
import unicodedata
import re
from glob import *
import glob
import unittest

DOC_FILES = glob.glob("doc/html/*.htm*")

class TestDoxygenOutput(unittest.TestCase):
""" Test class for the doxygen output. """

def test_hash(self):
''' Test case is checking if there are illegal hash chars in the documentation. -> doxygen link not found. '''
for file in glob("doc/html/*.htm*"):
with open(file, "rt") as fin:
i = 0

for line in fin:
i += 1
for file in DOC_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
for i, line in enumerate(fin, start=1):
matchHash = re.search(r"([\s>]|^)#\w(\S)*", line)

if matchHash is not None:
self.assertIsNone(matchHash, file + " in line " + str(i) + ": not permitted hash found. Search for: '"+ line[matchHash.start():matchHash.end()])
self.assertIsNone(matchHash, file + " in line " + str(i) + ": not permitted hash found. Search for: '"+ line[matchHash.start():matchHash.end()])


def test_slash_triplet(self):
''' Test case is checking if there are slash triplets in the documentation. -> doxygen didn't interpret something properly. '''

for file in glob("doc/html/*.htm*"):
with open(file, "rt") as fin:
i = 0

for line in fin:
i += 1
for file in DOC_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
for i, line in enumerate(fin, start=1):
matchHash = re.search(r"([\s>]|^)///\s*",line)

if matchHash is not None:
self.assertIsNone(matchHash, file + " in line " + str(i) + ": not permitted slash triplet found. Search for: '"+line[matchHash.start():matchHash.end()])
self.assertIsNone(matchHash, file + " in line " + str(i) + ": not permitted slash triplet found. Search for: '"+line[matchHash.start():matchHash.end()])


def test_backslash_triplet(self):
''' Test case is checking if there are backslash triplets in the documentation. -> doxygen didn't interpret something properly. '''
for file in glob("doc/html/*.htm*"):
with open(file, "rt") as fin:
i = 0

for line in fin:
i += 1
for file in DOC_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
for i, line in enumerate(fin, start=1):
matchHash = re.search(r"([\s>]|^)\\\\\\\s*",line)

if matchHash is not None:
self.assertIsNone(matchHash, file + " in line " + str(i) + ": not permitted backslash triplet found. Search for: '"+line[matchHash.start():matchHash.end()])
self.assertIsNone(matchHash, file + " in line " + str(i) + ": not permitted backslash triplet found. Search for: '"+line[matchHash.start():matchHash.end()])
25 changes: 9 additions & 16 deletions tests/test_invalid_comment.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import sys
import unicodedata
import re
from glob import *
import glob
import unittest

PROTO_FILES = glob.glob("*.proto")

class TestInvalidCommentType(unittest.TestCase):
"""Test class for invalid comment types"""

def test_triple_slash(self):
''' Test to check if more than two forward slash('/') are present in comment section of proto file. '''
for file in glob("*.proto"):
with open(file, "rt") as fin:
i = 0

for line in fin:
i += 1
for file in PROTO_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
for i, line in enumerate(fin, start=1):
self.assertEqual(line.find("///"), -1, file + " in line " + str(i) + ": not permitted use of '///' ")

def test_comments_invalid_syntax(self):
''' Test to check if comments are given using invalid syntax '/*' or '*/' '''
for file in glob("*.proto"):
with open(file, "rt") as fin:
i = 0

for line in fin:
i += 1
for file in PROTO_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
for i, line in enumerate(fin, start=1):
self.assertEqual(line.find("/*"), -1, file + " in line " + str(i) + ": not permitted use of '/*' ")
self.assertEqual(line.find("*/"), -1, file + " in line " + str(i) + ": not permitted use of '*/' ")
28 changes: 11 additions & 17 deletions tests/test_invalid_enum.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import sys
import unicodedata
import re
from glob import *
import glob
import unittest

PROTO_FILES = glob.glob("*.proto")

class TestInvalidEnum(unittest.TestCase):
''' Test class to check invalid enum '''

def test_correct_enum_name(self):
''' Test if enum name is correct. '''
for file in glob("*.proto"):
with open(file, "rt") as fin:
i = 0
for file in PROTO_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
isEnum = False
enumName = ""
saveStatement = ""

for line in fin:
i += 1

for i, line in enumerate(fin, start=1):
# Divide statement and comment. Concatenate multi line statements.

# Search for comment ("//").
Expand Down Expand Up @@ -56,13 +53,13 @@ def test_correct_enum_name(self):
if matchName is not None:
checkName = statement[matchName.start():matchName.end()]

# Test to check correct ENUM name.
# Test to check correct ENUM name.
self.assertEqual(checkName.find(enumName), 0, file + " in line " + str(i) + ": enum type wrong. '" + checkName + "' should start with '" + enumName + "'")

# Test to check ENUM type is in captial letters/upper case.
self.assertEqual(checkName, checkName.upper(), file + " in line " + str(i) + ": enum type wrong. '" + checkName + "' should use upper case")


# Search for "enum".
matchEnum = re.search(r"\benum\b", statement)

Expand All @@ -84,16 +81,13 @@ def test_correct_enum_name(self):

def test_invalid_enum(self):
''' Test invalid enum definition. '''
for file in glob("*.proto"):
with open(file, "rt") as fin:
i = 0
for file in PROTO_FILES:
with open(file, "rt") as fin, self.subTest(file=file):
isEnum = False
enumName = ""
saveStatement = ""

for line in fin:
i += 1

for i, line in enumerate(fin, start=1):
# Divide statement and comment. Concatenate multi line statements.

# Search for comment ("//").
Expand Down
Loading