Can't write xml files via "lxml" package when using pyfakefs #716
Replies: 27 comments
-
Thanks for the report! I just had a quick local test under Windows, and the problem did not occur, so I have to make further tests under Linux. I don't have the time today (and probably not in the next few days), but I will see what I can find - right now I have no idea. From the callstack it looks like the excel file had been written in the fake fs, but the contents are incorrect. I will let you know if I find the problem, and hopefully a solution. |
Beta Was this translation helpful? Give feedback.
-
In your related issue you write that this only happens on an ARM system. I have no possibility to test under such a system, so this may be a bit tricky... |
Beta Was this translation helpful? Give feedback.
-
Sidenote: Different from my original report I updated Numpy to 1.23.2 which is the current stable. But nothing changed. This becomes more wired now.
I'm sorry. ;) This seems not to be urgent. I assume the cause isn't pyfakefs. It must be something behind. I have to think about further tests, maybe with xmltree or openpyxl itself. |
Beta Was this translation helpful? Give feedback.
-
Ok, thanks - in this case, I'll probably leave this alone for the time being, maybe you will find something out. |
Beta Was this translation helpful? Give feedback.
-
Can you please have a short look on this "class". My expertise end here. The file suffix is Does this give you any idea about a possible problem? Now I have better and easier code to reproduce but I have to test it on my home machine this night first. |
Beta Was this translation helpful? Give feedback.
-
What you are showing is If |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hm, this still doesn't explain why it works on most systems... |
Beta Was this translation helpful? Give feedback.
-
Now I can reproduce it with my home PC (amd64) and with the Pi4 (arm64). Using The formally used openpyxl seems to use different xml libraries if needed. See here or here. That would explain why I couldn't reproduce the problem on both machines before. Now the interesting question is if you can reproduce it either. ;) Code to reproduce
Output of test "Works"
Output of test "Problem"
|
Beta Was this translation helpful? Give feedback.
-
Yes, I can reproduce this. As I wrote,
|
Beta Was this translation helpful? Give feedback.
-
See also #180. |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, |
Beta Was this translation helpful? Give feedback.
-
Ah, I missed your link to the |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for explaining. I'm not sure if pyfakefs should patch something like this. Isn't openpyxl/lxml an edge case? As a user I wouldn't expect that magic from pyfakefs. IMHO this is my own responsibility to handle that. But before that the user should know the reason. What would help more is if pyfakefs would be able to detect a situation (C library using python package) like this and then give a warning about that. I'm not good at this. But isn't it possible to look (e.g. via |
Beta Was this translation helpful? Give feedback.
-
In principle you are right, but for some often-used cases it may make sense to do the patching in
Most packages that use C libraries are not problematic as they don't use fs functions ( |
Beta Was this translation helpful? Give feedback.
-
When there is so much patching I wonder if my tests are still "real". Technically your fake-fs is in RAM, right? Or more precise: In the "RAM scope" of the current running Python interpreter? |
Beta Was this translation helpful? Give feedback.
-
Well, if are going to patch the file system access, this is somewhat unavoidable. As I wrote, patching the fs access of some common libraries is a convenience, as most users won't have the time or patience to do it themselves, but this is currently only done for In the case of
Yes, it is. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for spending time onto this. |
Beta Was this translation helpful? Give feedback.
-
I had a look at the source code of |
Beta Was this translation helpful? Give feedback.
-
I'm not able to reproduce this on my PC when I use The current code I'm using.
I also added some debug-print-statements in the openpyxl code. I'm pretty sure when openpyxl does use Pythons inbuild |
Beta Was this translation helpful? Give feedback.
-
Well, it depends what calls are used in the code. In this example, the |
Beta Was this translation helpful? Give feedback.
-
With writing I can reproduce the problem. Sorry, my mistake. How do you set
This doesn't work in my system. The goal is to prevent openpyxl to import lxml even if it is installed, right? |
Beta Was this translation helpful? Give feedback.
-
You have to set the environment variable, probably |
Beta Was this translation helpful? Give feedback.
-
Sorry, now it works. But this is no solution for unittesting. So I did it in the code like this
It seems to me that I have to do this before importing openpyxl. That break PEP8 rules in the code. I opened an Issue at openpyxl upstream. |
Beta Was this translation helpful? Give feedback.
-
Yeah, not the best solution, but at least a workaround. I haven't decided yet if and how to handle this in pyfakefs, didn't find a good solution yet. |
Beta Was this translation helpful? Give feedback.
-
For your information: I have played around with patching |
Beta Was this translation helpful? Give feedback.
-
I'm moving this to discussions, as it may be helpful to others. |
Beta Was this translation helpful? Give feedback.
-
I'm really sorry for such a broad and unspecific bug report. But I could break it down to the fact that the problem occurs only when I use
pyfakefs
but if I use a real fileystem for (nearly) the same test everything is fine.Do you have any idea what could cause this side effect or how I could go on with my investigation?
Maybe pyfakefs doesn't write a real file to the fake filesystem? Can I checkt that somehow?
The last lines of the raised error
The raised errors seems to have nothing to do with
pyfakefs
or my own package.Description
The unittest checks if a excel file can be read. The test does this steps
pandas.DataFrame
.pandas.DataFrame.to_excel()
)pandas.read_excel()
).Of course in the real tests there happens a lot more between 2. and 3. I have a wrapper around
pandas.DataFrame.to_excel()
.The unittests
Environment
In the beginning this problem occur in older versions with Pandas (1.3.5), Numpy and openpyxl. Just for that bug report I updated everything possible (except my operating system and the python interpreter) to the current available stable release version. But the error is still there.
Full error output
Misc
Referenced by https://codeberg.org/buhtz/buhtzology/issues/28
Beta Was this translation helpful? Give feedback.
All reactions