Last Comment Bug 776035 - Make mozunit even easier to use, and use it in config/tests python unit tests
: Make mozunit even easier to use, and use it in config/tests python unit tests
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: Build Config (show other bugs)
: unspecified
: All All
: -- normal (vote)
: mozilla17
Assigned To: Mike Hommey [:glandium]
:
Mentors:
Depends on: 776046
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-20 10:46 PDT by Mike Hommey [:glandium]
Modified: 2012-07-26 05:12 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Make mozunit even easier to use, and use it in config/tests python unit tests (10.05 KB, patch)
2012-07-20 10:48 PDT, Mike Hommey [:glandium]
ted: review+
Details | Diff | Review
part 2 - Add an enhanced MockedOpen facility to mozunit.py (6.06 KB, patch)
2012-07-23 00:40 PDT, Mike Hommey [:glandium]
no flags Details | Diff | Review
part 2 - Add an enhanced MockedOpen facility to mozunit.py (6.07 KB, patch)
2012-07-23 00:42 PDT, Mike Hommey [:glandium]
ted: review+
Details | Diff | Review
part 3 - Use the new MockedOpen in unit-Preprocessor.py (3.59 KB, patch)
2012-07-23 00:48 PDT, Mike Hommey [:glandium]
ted: review+
Details | Diff | Review
Make mozunit even easier to use, and use it in config/tests python unit tests (12.02 KB, patch)
2012-07-24 00:57 PDT, Mike Hommey [:glandium]
ted: review+
Details | Diff | Review
part 2 - Add an enhanced MockedOpen facility to mozunit.py (6.70 KB, patch)
2012-07-24 08:20 PDT, Mike Hommey [:glandium]
ted: review+
Details | Diff | Review
part 3 - Use the new MockedOpen in unit-Preprocessor.py (3.53 KB, patch)
2012-07-24 08:23 PDT, Mike Hommey [:glandium]
mh+mozilla: review+
Details | Diff | Review

Description Mike Hommey [:glandium] 2012-07-20 10:46:03 PDT

    
Comment 1 Mike Hommey [:glandium] 2012-07-20 10:48:17 PDT
Created attachment 644390 [details] [diff] [review]
Make mozunit even easier to use, and use it in config/tests python unit tests
Comment 2 Mike Hommey [:glandium] 2012-07-23 00:40:00 PDT
Created attachment 644853 [details] [diff] [review]
part 2 - Add an enhanced MockedOpen facility to mozunit.py
Comment 3 Mike Hommey [:glandium] 2012-07-23 00:42:54 PDT
Created attachment 644854 [details] [diff] [review]
part 2 - Add an enhanced MockedOpen facility to mozunit.py
Comment 4 Mike Hommey [:glandium] 2012-07-23 00:48:45 PDT
Created attachment 644855 [details] [diff] [review]
part 3 - Use the new MockedOpen in unit-Preprocessor.py
Comment 5 Ted Mielczarek [:ted.mielczarek] 2012-07-23 13:04:12 PDT
Comment on attachment 644390 [details] [diff] [review]
Make mozunit even easier to use, and use it in config/tests python unit tests

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

I forgot this file existed. Very cool!
Comment 6 Mike Hommey [:glandium] 2012-07-24 00:57:53 PDT
Created attachment 645221 [details] [diff] [review]
Make mozunit even easier to use, and use it in config/tests python unit tests

Same as the previous patch, but adds idl-parser and xpt unit tests. Also now depends on virtualenv pth (bug 776046) and removes the sys.path tricks.
Comment 7 Ted Mielczarek [:ted.mielczarek] 2012-07-24 05:17:39 PDT
Comment on attachment 644854 [details] [diff] [review]
part 2 - Add an enhanced MockedOpen facility to mozunit.py

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

::: config/mozunit.py
@@ +108,5 @@
> +    self.assertRaises(Exception,f.open('foo', 'r'))
> +    '''
> +    def __init__(self, files = {}):
> +        self.files = {}
> +        for name, content in files.items():

It's more conventional to use .iteritems().

@@ +113,5 @@
> +            self.files[os.path.abspath(name)] = content
> +
> +    def __call__(self, name, mode = 'r'):
> +        absname = os.path.abspath(name)
> +        if 'w' in mode:

Do you want to handle 'a' here?

@@ +117,5 @@
> +        if 'w' in mode:
> +            return MockedFile(self, absname)
> +        if absname in self.files:
> +            return MockedFile(self, absname, self.files[absname])
> +        return self.open(name, mode)

It seems a little odd that you only mock reads from files explicitly named in the constructor, but you mock writes to all files. I wonder if it'd be better to require explicitly listing all files up front, and assert when a file is opened that wasn't specified?

::: config/tests/unit-mozunit.py
@@ +3,5 @@
> +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
> +
> +import sys
> +import os
> +sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

This shouldn't be necessary with the virtualenv changes, right?
Comment 8 Mike Hommey [:glandium] 2012-07-24 05:28:41 PDT
> @@ +113,5 @@
> > +            self.files[os.path.abspath(name)] = content
> > +
> > +    def __call__(self, name, mode = 'r'):
> > +        absname = os.path.abspath(name)
> > +        if 'w' in mode:
> 
> Do you want to handle 'a' here?

Indeed.

> 
> @@ +117,5 @@
> > +        if 'w' in mode:
> > +            return MockedFile(self, absname)
> > +        if absname in self.files:
> > +            return MockedFile(self, absname, self.files[absname])
> > +        return self.open(name, mode)
> 
> It seems a little odd that you only mock reads from files explicitly named
> in the constructor, but you mock writes to all files. I wonder if it'd be
> better to require explicitly listing all files up front, and assert when a
> file is opened that wasn't specified?

My idea was that using MockedOpen, you can expect that no write will happen on the file system.

> ::: config/tests/unit-mozunit.py
> @@ +3,5 @@
> > +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
> > +
> > +import sys
> > +import os
> > +sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
> 
> This shouldn't be necessary with the virtualenv changes, right?

Sure. I didn't refresh this part after I did bug 776046
Comment 9 Mike Hommey [:glandium] 2012-07-24 08:20:46 PDT
Created attachment 645317 [details] [diff] [review]
part 2 - Add an enhanced MockedOpen facility to mozunit.py

With support for 'a'.
Comment 10 Mike Hommey [:glandium] 2012-07-24 08:23:59 PDT
Created attachment 645319 [details] [diff] [review]
part 3 - Use the new MockedOpen in unit-Preprocessor.py

Refreshed after bug 776046.
Comment 11 Mike Hommey [:glandium] 2012-07-24 08:24:26 PDT
Comment on attachment 645319 [details] [diff] [review]
part 3 - Use the new MockedOpen in unit-Preprocessor.py

Carrying over r+.
Comment 13 Ed Morley [:emorley] 2012-07-25 01:37:36 PDT
Push backed out for Windows mochitest crashes:
https://tbpl.mozilla.org/?tree=Mozilla-Inbound&rev=eecd3aa199e6

https://hg.mozilla.org/integration/mozilla-inbound/rev/1abfd50c8be6
Comment 14 Mike Hommey [:glandium] 2012-07-25 04:09:09 PDT
Relanded, as it was innocent
https://hg.mozilla.org/integration/mozilla-inbound/rev/284ee7c9fb33

Note You need to log in before you can comment on or make changes to this bug.