MockedOpen should optionally not intercept all writes

RESOLVED FIXED in mozilla28

Status

Firefox Build System
General
RESOLVED FIXED
5 years ago
5 months ago

People

(Reporter: gps, Assigned: gps)

Tracking

Trunk
mozilla28

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

5 years ago
I need to extend MockedOpen to not intercept all writes in order to test WebIDL foo in bug 928195.
(Assignee)

Comment 1

5 years ago
Created attachment 831017 [details] [diff] [review]
MockedOpen should optionally not intercept all writes

Simple change with basic tests.
Attachment #831017 - Flags: review?(mh+mozilla)
(Assignee)

Updated

5 years ago
Assignee: nobody → gps
Status: NEW → ASSIGNED
What is your usecase?
(Assignee)

Comment 3

5 years ago
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.
(Assignee)

Comment 6

5 years ago
Created attachment 8334066 [details] [diff] [review]
os.path.exists should work with MockedOpen

Changed patch to work with os.path.exists.
Attachment #8334066 - Flags: review?(mh+mozilla)
(Assignee)

Updated

5 years ago
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
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28

Updated

5 months ago
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.