Skip to content

Commit

Permalink
Merge pull request #418 from polystat/another-fix
Browse files Browse the repository at this point in the history
Moved django and cpython to temp directories
  • Loading branch information
dours committed Oct 31, 2022
2 parents f05e47b + c212689 commit 5762ed0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
java-version: '14'
distribution: 'adopt'
- name: Build with Maven
run: mvn clean compile -B -q
run: mvn clean compile -B

test:
strategy:
Expand All @@ -35,7 +35,7 @@ jobs:
with:
python-version: '3.8.10'
- name: Build with Maven
run: mvn clean verify -B -q -DskipITs
run: mvn clean verify -B -DskipITs
- name: archive artifacts
uses: actions/upload-artifact@v2
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.polystat.py2eo.transpiler

import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.{Order, Test, TestMethodOrder}
import org.junit.jupiter.api.{AfterEach, Order, Test, TestMethodOrder}
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation

import scala.concurrent.ExecutionContext.Implicits.global
Expand All @@ -15,28 +15,40 @@ import scala.util.Try
@TestMethodOrder(classOf[OrderAnnotation])
final class CPythonIT extends Commons {

private val dirPath: Path = s"$testsPrefix/testParserPrinter"
private val cpythonLink = "https://github.com/python/cpython"
private val directory = Directory.makeTemp(prefix = "org.polystat.py2eo.")
private val blacklisted = Set(
// these are excluded because of some encoding problems in the lexer
"test_unicode_identifiers.py", "test_source_encoding.py",
"badsyntax_3131.py", "badsyntax_pep3120.py",
"module_koi8_r.py", "module_iso_8859_1.py"
"module_koi8_r.py", "module_iso_8859_1.py",
// most of these are excluded because they do tests by comparing stack traces as strings
// but code before parser-printer has different line numbers than code after => traces are
// always different =>
// those tests cannot possibly pass
"test_traceback.py", "test_dis.py", "test_zipfile.py",
"test_multiprocessing_fork.py", "test_sys.py",
"test_import.yaml", "test_strtod.py", "test_trace.py",
"test_doctest.py", "test_concurrent_futures.py", "test_inspect.py",
"test_tracemalloc.py", "test_multiprocessing_spawn.py",
"test_sys_settrace.py", "test_multiprocessing_forkserver.py",
"test_compileall.py", "test_asyncio.py", "test_unittest.py",
"test_email.py", "test_tools.py", "test_atexit.py", "test_pdb.py",
"test_logging.py", "test_coroutines.py", "test_tasks.py",

"test_grammar.py", "test_headerregistry.py"
)

@Test
@Order(1)
def parserPrinterOnCPython(): Unit = {
val dir = Directory(dirPath)
dir.createDirectory(failIfExists = false)

val eoFiles = Directory(dirPath / "afterParser")
val eoFiles = Directory(directory / "afterParser")
eoFiles.createDirectory(failIfExists = false)

val cpython = Directory(dirPath / "cpython")
if (!cpython.exists) {
Process(s"git clone $cpythonLink ${cpython.name}", dirPath.jfile).!!
Process("git checkout v3.8.10", cpython.jfile).!!
}
val cpython = Directory(directory / "cpython")

Process(s"git clone $cpythonLink ${cpython.name}", directory.jfile).!!
Process("git checkout v3.8.10", cpython.jfile).!!

val testsDir = Directory(cpython / "Lib" / "test")
val tests = testsDir.deepFiles.filter(_.extension == "py")
Expand All @@ -58,9 +70,13 @@ final class CPythonIT extends Commons {
for (f <- futures) Await.result(f, Duration.Inf)
}

@AfterEach def cleanup(): Unit = {
directory.deleteRecursively
}

@Test
@Order(2)
def checkEOSyntax(): Unit = {
checkEOSyntaxInDirectory(Directory(dirPath / "afterParser").toString)
checkEOSyntaxInDirectory(Directory(directory / "afterParser").toString)
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
package org.polystat.py2eo.transpiler

import org.junit.jupiter.api.MethodOrderer.OrderAnnotation
import org.junit.jupiter.api.{Order, Test, TestMethodOrder}
import org.junit.jupiter.api.{AfterEach, Order, Test, TestMethodOrder}
import org.polystat.py2eo.parser.Statement
import org.polystat.py2eo.transpiler.Common.dfsFiles

import java.io.File
import java.nio.file.{Files, StandardCopyOption}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
import scala.reflect.io.Directory
import scala.sys.process.Process

@TestMethodOrder(classOf[OrderAnnotation])
class DjangoIT extends Commons {

private val djangoLink = "https://github.com/django/django"
private val directory = Directory.makeTemp(prefix = "org.polystat.py2eo.")

@Test
@Order(1)
def genUnsupportedDjango() : Unit = {
val root = new File(testsPrefix)
val django = new File(testsPrefix + "/django")
if (!django.exists()) {
Process("git clone -b 4.0 https://github.com/django/django", root).!!
def genUnsupportedDjango(): Unit = {
val django = Directory(directory + "/django")

Process(s"git clone -b 4.0 $djangoLink ${django.name}", directory.jfile).!!

val tests = django.deepFiles.filter(_.extension == "py")
for (test <- tests) {
def db(s: Statement.T, str: String) = () // debugPrinter(test)(_, _)

val name = test.name
val eoText =
Transpile.transpile(db)(
chopExtension(name),
Transpile.Parameters(wrapInAFunction = false, isModule = false),
readFile(test.jfile)
)
writeFile(test.jfile, "genUnsupportedEO", ".eo", eoText)
}
val test = dfsFiles(django).filter(f => f.getName.endsWith(".py"))

test.map(test =>
{
def db(s : Statement.T, str : String) = () // debugPrinter(test)(_, _)
val name = test.getName
val eoText =
Transpile.transpile(db)(
chopExtension(name),
Transpile.Parameters(wrapInAFunction = false, isModule = false),
readFile(test)
)
writeFile(test, "genUnsupportedEO", ".eo", eoText)
}
)
}

@AfterEach def cleanup(): Unit = {
directory.deleteRecursively
}

@Test
@Order(2)
def checkSyntaxForDjango() : Unit = {
checkEOSyntaxInDirectory(testsPrefix + "/django")
def checkSyntaxForDjango(): Unit = {
checkEOSyntaxInDirectory(Directory(directory + "/django").toString)
}

}
Expand Down

0 comments on commit 5762ed0

Please sign in to comment.