Closed Bug 937803 Opened 11 years ago Closed 11 years ago

MockedOpen should optionally not intercept all writes

Categories

(Firefox Build System :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla28

People

(Reporter: gps, Assigned: gps)

References

Details

Attachments

(1 file, 1 obsolete file)

I need to extend MockedOpen to not intercept all writes in order to test WebIDL foo in bug 928195.
Simple change with basic tests.
Attachment #831017 - Flags: review?(mh+mozilla)
Assignee: nobody → gps
Status: NEW → ASSIGNED
What is your usecase?
I have a test that needs to simulate a file in the source directory. While that file's presence is simulated, we write out some other files. There are later tests that trigger code performing os.path.exists(), which currently fails for files written via MockedOpen. I suppose an alternative patch would be to have MockedOpen intercept os.path.exists. But that would need to be behind an optional argument so tests against MockedOpen could be written. Pick your poison.
(In reply to Gregory Szorc [:gps] from comment #3)
> I suppose an alternative patch would
> be to have MockedOpen intercept os.path.exists. But that would need to be
> behind an optional argument so tests against MockedOpen could be written.
> Pick your poison.

As I've had this problem in the past with os.path.exists and MockedOpen, I'd prefer MockedOpen intercepting os.path.exists.
Note I don't think you need an optional argument for os.path.exists being intercepted or not. You just need to get os.path.exists value in your test function before MockedOpen intercepts it.
Changed patch to work with os.path.exists.
Attachment #8334066 - Flags: review?(mh+mozilla)
Attachment #831017 - Attachment is obsolete: true
Attachment #831017 - Flags: review?(mh+mozilla)
Comment on attachment 8334066 [details] [diff] [review]
os.path.exists should work with MockedOpen

Review of attachment 8334066 [details] [diff] [review]:
-----------------------------------------------------------------

::: config/tests/unit-mozunit.py
@@ +30,5 @@
>  
>              # Check that overwriting these files alters their content.
>              with open('file1', 'w') as file:
>                  file.write('foo')
> +            self.assertTrue(os.path.exists('file1'))

Please add another test before and after file3 is created.
Attachment #8334066 - Flags: review?(mh+mozilla) → review+
https://hg.mozilla.org/mozilla-central/rev/e4e085ffb2dd
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: