Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_basic failing on Windows #448

Open
sygout opened this issue Aug 23, 2022 · 1 comment · May be fixed by #493
Open

test_basic failing on Windows #448

sygout opened this issue Aug 23, 2022 · 1 comment · May be fixed by #493
Assignees
Labels
bug Something isn't working

Comments

@sygout
Copy link
Collaborator

sygout commented Aug 23, 2022

With master branch commit 02b3c84

When running pytest for test_basic.py on Windows, it returns an error:
==================================================================== test session starts ====================================================================
platform win32 -- Python 3.9.9, pytest-7.1.2, pluggy-1.0.0
rootdir: C:\Users\sygo\Sylvain\Codes\temporary\ontopy2\EMMO-python
collected 2 items

test_basic.py .F [100%]

========================================================================= FAILURES ==========================================================================
____________________________________________________________________ test_sync_reasoner _____________________________________________________________________

src = 'C:\Users\sygo\AppData\Local\Temp\tmpfvrqt25p', dst = 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
copy_function = <function copy2 at 0x000001CC8FCA7790>

def move(src, dst, copy_function=copy2):
    """Recursively move a file or directory to another location. This is
    similar to the Unix "mv" command. Return the file or directory's
    destination.

    If the destination is a directory or a symlink to a directory, the source
    is moved inside the directory. The destination path must not already
    exist.

    If the destination already exists but is not a directory, it may be
    overwritten depending on os.rename() semantics.

    If the destination is on our current filesystem, then rename() is used.
    Otherwise, src is copied to the destination and then removed. Symlinks are
    recreated under the new name if os.rename() fails because of cross
    filesystem renames.

    The optional `copy_function` argument is a callable that will be used
    to copy the source or it will be delegated to `copytree`.
    By default, copy2() is used, but any function that supports the same
    signature (like copy()) can be used.

    A lot more could be done here...  A look at a mv.c shows a lot of
    the issues this implementation glosses over.

    """
    sys.audit("shutil.move", src, dst)
    real_dst = dst
    if os.path.isdir(dst):
        if _samefile(src, dst):
            # We might be on a case insensitive filesystem,
            # perform the rename anyway.
            os.rename(src, dst)
            return

        # Using _basename instead of os.path.basename is important, as we must
        # ignore any trailing slash to avoid the basename returning ''
        real_dst = os.path.join(dst, _basename(src))

        if os.path.exists(real_dst):
            raise Error("Destination path '%s' already exists" % real_dst)
    try:
      os.rename(src, real_dst)

E FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:\Users\sygo\AppData\Local\Temp\tmpfvrqt25p' -> 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'

C:\Python\Python39\lib\shutil.py:815: FileExistsError

During handling of the above exception, another exception occurred:

testonto = get_ontology("http://emmo.info/testonto#")

def test_sync_reasoner(testonto: "Ontology") -> None:
    """Test `ontopy:Ontology.sync_reasoner()`."""
  testonto.sync_reasoner()

test_basic.py:60:


..\ontopy\ontology.py:1073: in sync_reasoner
sync(self, **kwargs)
..\ontopy\factpluspluswrapper\sync_factpp.py:80: in sync_reasoner_factpp
graph2 = FaCTPPGraph(graph1).inferred_graph()
..\ontopy\factpluspluswrapper\factppgraph.py:66: in inferred_graph
self.add_base_annotations()
..\ontopy\factpluspluswrapper\factppgraph.py:76: in add_base_annotations
inferred = self.inferred
..\ontopy\factpluspluswrapper\factppgraph.py:32: in inferred
self._inferred = self.raw_inferred_graph()
..\ontopy\factpluspluswrapper\factppgraph.py:62: in raw_inferred_graph
return OwlApiInterface().reason(self.graph)
..\ontopy\factpluspluswrapper\owlapi_interface.py:34: in reason
graph.serialize(tmpdir.name, format="xml")
C:\Users\sygo\Envs\ontopy2\lib\site-packages\rdflib\graph.py:1210: in serialize
shutil.move(name, dest)
C:\Python\Python39\lib\shutil.py:835: in move
copy_function(src, real_dst)
C:\Python\Python39\lib\shutil.py:444: in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)


src = 'C:\Users\sygo\AppData\Local\Temp\tmpfvrqt25p', dst = 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'

def copyfile(src, dst, *, follow_symlinks=True):
    """Copy data from src to dst in the most efficient way possible.

    If follow_symlinks is not set and src is a symbolic link, a new
    symlink will be created instead of copying the file it points to.

    """
    sys.audit("shutil.copyfile", src, dst)

    if _samefile(src, dst):
        raise SameFileError("{!r} and {!r} are the same file".format(src, dst))

    file_size = 0
    for i, fn in enumerate([src, dst]):
        try:
            st = _stat(fn)
        except OSError:
            # File most likely does not exist
            pass
        else:
            # XXX What about other special files? (sockets, devices...)
            if stat.S_ISFIFO(st.st_mode):
                fn = fn.path if isinstance(fn, os.DirEntry) else fn
                raise SpecialFileError("`%s` is a named pipe" % fn)
            if _WINDOWS and i == 0:
                file_size = st.st_size

    if not follow_symlinks and _islink(src):
        os.symlink(os.readlink(src), dst)
    else:
        with open(src, 'rb') as fsrc:
            try:
              with open(dst, 'wb') as fdst:

E PermissionError: [Errno 13] Permission denied: 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'

C:\Python\Python39\lib\shutil.py:266: PermissionError
------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------
*** Prepare graph
*** Run FaCT++ reasoner (and postprocess)
================================================================== short test summary info ==================================================================
FAILED test_basic.py::test_sync_reasoner - PermissionError: [Errno 13] Permission denied: 'C:\Users\sygo\AppData\Local\Temp\tmpe_8_gu75'
================================================================ 1 failed, 1 passed in 2.18s ================================================================

@sygout sygout added the bug Something isn't working label Aug 23, 2022
@HendrikBorgelt
Copy link

Hello EMMO-Python developers,
I posted an issue yesterday, without noticing this issue, however, i think they are related. The issue mentioned is #451, in which the first sub-Issue "temp.NamedTemporaryFile instead of temp.TemporaryDirectory". I hope the extended log file and text in #451 can help you. To explain a possible result in a simple manner, i think that a NamedTemporyFile is created in the OwlApiInterface, while a TemporaryDirectory must be created instead, in order to handle correctly from graph.serialize. The code i used to correct this issue is given below, where the section replaced is "python"-commented in order to see the changes.

with kind regards
Hendrik Borgelt

class OwlApiInterface:
      """Interface to the FaCT++ reasoner via OWLAPI."""
  
      def __init__(self):
          """Initialize the interface."""
  
      def reason(self, graph):
          """Generate the inferred axioms for a given Graph.
  
          Args:
              graph (Graph): An rdflib graph to execute the reasoner on.
  
          """
          # with tempfile.NamedTemporaryFile("wt") as tmpdir:
          #     graph.serialize(tmpdir.name, format="xml")
          #     return self._run(tmpdir.name, command="--run-reasoner")
          with tempfile.TemporaryDirectory("wt") as tmpdir:
              graph.serialize(tmpdir, format="xml")
              temp_file_name = os.listdir(tmpdir)[0]
              temp_file_path = tmpdir + '\\' + temp_file_name  # tmpdir.name
              return self._run(temp_file_path, command="--run-reasoner")

@jesper-friis jesper-friis linked a pull request Oct 21, 2022 that will close this issue
11 tasks
@jesper-friis jesper-friis linked a pull request Oct 21, 2022 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants