separate py3 runtime tests from src tree + actually run said tests in CI

This commit is contained in:
Robert McGregor 2020-09-14 20:38:22 +01:00
parent d3246df2c3
commit 6f0657e5c9
10 changed files with 152 additions and 145 deletions

3
.gitignore vendored
View File

@ -98,3 +98,6 @@ xcuserdata
javac-services.0.log
javac-services.0.log.lck
test/
# Don't ignore python tests
!runtime/Python3/test/

View File

@ -10,7 +10,6 @@
#
import codecs
import unittest
from antlr4.InputStream import InputStream
@ -25,10 +24,3 @@ class FileStream(InputStream):
with open(fileName, 'rb') as file:
bytes = file.read()
return codecs.decode(bytes, encoding, errors)
class TestFileStream(unittest.TestCase):
def testStream(self):
stream = FileStream(__file__)
self.assertTrue(stream.size>0)

View File

@ -3,7 +3,6 @@
# Use of this file is governed by the BSD 3-clause license that
# can be found in the LICENSE.txt file in the project root.
#
import unittest
#
@ -85,20 +84,3 @@ class InputStream (object):
def __str__(self):
return self.strdata
class TestInputStream(unittest.TestCase):
def testStream(self):
stream = InputStream("abcde")
self.assertEqual(0, stream.index)
self.assertEqual(5, stream.size)
self.assertEqual(ord("a"), stream.LA(1))
stream.consume()
self.assertEqual(1, stream.index)
stream.seek(5)
self.assertEqual(Token.EOF, stream.LA(1))
self.assertEqual("bcd", stream.getText(1, 3))
stream.reset()
self.assertEqual(0, stream.index)

View File

@ -5,7 +5,6 @@
#
from io import StringIO
import unittest
from antlr4.Token import Token
# need forward declarations
@ -178,105 +177,3 @@ class IntervalSet(object):
if a<len(symbolicNames):
return symbolicNames[a]
return "<UNKNOWN>"
class TestIntervalSet(unittest.TestCase):
def testEmpty(self):
s = IntervalSet()
self.assertIsNone(s.intervals)
self.assertFalse(30 in s)
def testOne(self):
s = IntervalSet()
s.addOne(30)
self.assertTrue(30 in s)
self.assertFalse(29 in s)
self.assertFalse(31 in s)
def testTwo(self):
s = IntervalSet()
s.addOne(30)
s.addOne(40)
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertFalse(35 in s)
def testRange(self):
s = IntervalSet()
s.addRange(range(30,41))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertTrue(35 in s)
def testDistinct1(self):
s = IntervalSet()
s.addRange(range(30,32))
s.addRange(range(40,42))
self.assertEquals(2,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertFalse(35 in s)
def testDistinct2(self):
s = IntervalSet()
s.addRange(range(40,42))
s.addRange(range(30,32))
self.assertEquals(2,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertFalse(35 in s)
def testContiguous1(self):
s = IntervalSet()
s.addRange(range(30,36))
s.addRange(range(36,41))
self.assertEquals(1,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertTrue(35 in s)
def testContiguous2(self):
s = IntervalSet()
s.addRange(range(36,41))
s.addRange(range(30,36))
self.assertEquals(1,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
def testOverlapping1(self):
s = IntervalSet()
s.addRange(range(30,40))
s.addRange(range(35,45))
self.assertEquals(1,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(44 in s)
def testOverlapping2(self):
s = IntervalSet()
s.addRange(range(35,45))
s.addRange(range(30,40))
self.assertEquals(1,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(44 in s)
def testOverlapping3(self):
s = IntervalSet()
s.addRange(range(30,32))
s.addRange(range(40,42))
s.addRange(range(50,52))
s.addRange(range(20,61))
self.assertEquals(1,len(s.intervals))
self.assertTrue(20 in s)
self.assertTrue(60 in s)
def testComplement(self):
s = IntervalSet()
s.addRange(range(10,21))
c = s.complement(1,100)
self.assertTrue(1 in c)
self.assertTrue(100 in c)
self.assertTrue(10 not in c)
self.assertTrue(20 not in c)

View File

@ -144,17 +144,3 @@ class Recognizer(object):
self._stateNumber = atnState
del RecognitionException
import unittest
class Test(unittest.TestCase):
def testVersion(self):
major, minor = Recognizer().extractVersion("1.2")
self.assertEqual("1", major)
self.assertEqual("2", minor)
major, minor = Recognizer().extractVersion("1.2.3")
self.assertEqual("1", major)
self.assertEqual("2", minor)
major, minor = Recognizer().extractVersion("1.2-snapshot")
self.assertEqual("1", major)
self.assertEqual("2", minor)

View File

@ -0,0 +1,8 @@
import unittest
from antlr4.FileStream import FileStream
class TestFileStream(unittest.TestCase):
def testStream(self):
stream = FileStream(__file__)
self.assertTrue(stream.size > 0)

View File

@ -0,0 +1,19 @@
import unittest
from antlr4.Token import Token
from antlr4.InputStream import InputStream
class TestInputStream(unittest.TestCase):
def testStream(self):
stream = InputStream("abcde")
self.assertEqual(0, stream.index)
self.assertEqual(5, stream.size)
self.assertEqual(ord("a"), stream.LA(1))
stream.consume()
self.assertEqual(1, stream.index)
stream.seek(5)
self.assertEqual(Token.EOF, stream.LA(1))
self.assertEqual("bcd", stream.getText(1, 3))
stream.reset()
self.assertEqual(0, stream.index)

View File

@ -0,0 +1,101 @@
import unittest
from antlr4.IntervalSet import IntervalSet
class TestIntervalSet(unittest.TestCase):
def testEmpty(self):
s = IntervalSet()
self.assertIsNone(s.intervals)
self.assertFalse(30 in s)
def testOne(self):
s = IntervalSet()
s.addOne(30)
self.assertTrue(30 in s)
self.assertFalse(29 in s)
self.assertFalse(31 in s)
def testTwo(self):
s = IntervalSet()
s.addOne(30)
s.addOne(40)
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertFalse(35 in s)
def testRange(self):
s = IntervalSet()
s.addRange(range(30,41))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertTrue(35 in s)
def testDistinct1(self):
s = IntervalSet()
s.addRange(range(30,32))
s.addRange(range(40,42))
self.assertEquals(2,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertFalse(35 in s)
def testDistinct2(self):
s = IntervalSet()
s.addRange(range(40,42))
s.addRange(range(30,32))
self.assertEquals(2,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertFalse(35 in s)
def testContiguous1(self):
s = IntervalSet()
s.addRange(range(30,36))
s.addRange(range(36,41))
self.assertEquals(1,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
self.assertTrue(35 in s)
def testContiguous2(self):
s = IntervalSet()
s.addRange(range(36,41))
s.addRange(range(30,36))
self.assertEquals(1,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(40 in s)
def testOverlapping1(self):
s = IntervalSet()
s.addRange(range(30,40))
s.addRange(range(35,45))
self.assertEquals(1,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(44 in s)
def testOverlapping2(self):
s = IntervalSet()
s.addRange(range(35,45))
s.addRange(range(30,40))
self.assertEquals(1,len(s.intervals))
self.assertTrue(30 in s)
self.assertTrue(44 in s)
def testOverlapping3(self):
s = IntervalSet()
s.addRange(range(30,32))
s.addRange(range(40,42))
s.addRange(range(50,52))
s.addRange(range(20,61))
self.assertEquals(1,len(s.intervals))
self.assertTrue(20 in s)
self.assertTrue(60 in s)
def testComplement(self):
s = IntervalSet()
s.addRange(range(10,21))
c = s.complement(1,100)
self.assertTrue(1 in c)
self.assertTrue(100 in c)
self.assertTrue(10 not in c)
self.assertTrue(20 not in c)

View File

@ -0,0 +1,15 @@
import unittest
from antlr4.Recognizer import Recognizer
class TestRecognizer(unittest.TestCase):
def testVersion(self):
major, minor = Recognizer().extractVersion("1.2")
self.assertEqual("1", major)
self.assertEqual("2", minor)
major, minor = Recognizer().extractVersion("1.2.3")
self.assertEqual("1", major)
self.assertEqual("2", minor)
major, minor = Recognizer().extractVersion("1.2-snapshot")
self.assertEqual("1", major)
self.assertEqual("2", minor)

View File

@ -4,5 +4,9 @@ src_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__
sys.path.insert(0,src_path)
from TestTokenStreamRewriter import TestTokenStreamRewriter
from xpathtest import XPathTest
from TestFileStream import TestFileStream
from TestInputStream import TestInputStream
from TestIntervalSet import TestIntervalSet
from TestRecognizer import TestRecognizer
import unittest
unittest.main()