Skip to content

Commit

Permalink
neither __file__ nor __name__ are available while loading module for …
Browse files Browse the repository at this point in the history
…Python<3.5, wrap check into a function, use __name__ rather than __file__ for html-file
  • Loading branch information
realead committed May 28, 2019
1 parent 15fa92a commit 34599c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
41 changes: 18 additions & 23 deletions tests/build/cythonize_with_annotate.srctree
@@ -1,7 +1,7 @@
PYTHON setup.py build_ext --inplace
PYTHON -c "import not_annotated"
PYTHON -c "import default_annotated"
PYTHON -c "import fullc_annotated"
PYTHON -c "import not_annotated; not_annotated.check()"
PYTHON -c "import default_annotated; default_annotated.check()"
PYTHON -c "import fullc_annotated; fullc_annotated.check()"
######## setup.py ########

from Cython.Build.Dependencies import cythonize
Expand All @@ -15,36 +15,31 @@ setup(
)
######## not_annotated.pyx ########
# check that html-file doesn't exist:

import os.path as os_path
module_path = os_path.join(os_path.dirname(__file__), os_path.basename(__file__).split('.', 1)[0])
assert not os_path.isfile(module_path+'.html')
def check():
import os.path as os_path
assert not os_path.isfile(__name__+'.html')



######## default_annotated.pyx ########
# load html-site and check that the marker isn't there:
def check():
from codecs import open
with open(__name__+'.html', 'r', 'utf8') as html_file:
html = html_file.read()

from codecs import open
import os.path as os_path
module_path = os_path.join(os_path.dirname(__file__), os_path.basename(__file__).split('.', 1)[0])
with open(module_path + '.html', 'r', 'utf8') as html_file:
html = html_file.read()

from Cython.Compiler.Annotate import AnnotationCCodeWriter
assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE not in html) # per default no complete c code
from Cython.Compiler.Annotate import AnnotationCCodeWriter
assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE not in html) # per default no complete c code



######## fullc_annotated.pyx ########
# load html-site and check that the marker is there:
def check():
from codecs import open
with open(__name__+'.html', 'r', 'utf8') as html_file:
html = html_file.read()

from codecs import open
import os.path as os_path
module_path = os_path.join(os_path.dirname(__file__), os_path.basename(__file__).split('.', 1)[0])
with open(module_path + '.html', 'r', 'utf8') as html_file:
html = html_file.read()

from Cython.Compiler.Annotate import AnnotationCCodeWriter
assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE in html)
from Cython.Compiler.Annotate import AnnotationCCodeWriter
assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE in html)

15 changes: 7 additions & 8 deletions tests/build/cythonize_with_annotate_via_Options.srctree
@@ -1,5 +1,5 @@
PYTHON setup.py build_ext --inplace
PYTHON -c "import fullc_annotated"
PYTHON -c "import fullc_annotated; fullc_annotated.check()"

######## setup.py ########

Expand All @@ -17,12 +17,11 @@ setup(
######## fullc_annotated.pyx ########
# load html-site and check that the marker is there:

from codecs import open
import os.path as os_path
module_path = os_path.join(os_path.dirname(__file__), os_path.basename(__file__).split('.', 1)[0])
with open(module_path + '.html', 'r', 'utf8') as html_file:
html = html_file.read()
def check():
from codecs import open
with open(__name__+'.html', 'r', 'utf8') as html_file:
html = html_file.read()

from Cython.Compiler.Annotate import AnnotationCCodeWriter
assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE in html)
from Cython.Compiler.Annotate import AnnotationCCodeWriter
assert (AnnotationCCodeWriter.COMPLETE_CODE_TITLE in html)

0 comments on commit 34599c1

Please sign in to comment.