Closed Bug 776035 Opened 13 years ago Closed 13 years ago

Make mozunit even easier to use, and use it in config/tests python unit tests

Categories

(Firefox Build System :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla17

People

(Reporter: glandium, Assigned: glandium)

References

Details

Attachments

(3 files, 4 obsolete files)

No description provided.
Assignee: nobody → mh+mozilla
Attachment #644853 - Flags: review?(ted.mielczarek)
Attachment #644854 - Flags: review?(ted.mielczarek)
Attachment #644853 - Attachment is obsolete: true
Attachment #644853 - Flags: review?(ted.mielczarek)
Attachment #644855 - Flags: review?(ted.mielczarek)
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!
Attachment #644390 - Flags: review?(ted.mielczarek) → review+
Depends on: 776046
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.
Attachment #645221 - Flags: review?(ted.mielczarek)
Attachment #644390 - Attachment is obsolete: true
Attachment #645221 - Flags: review?(ted.mielczarek) → review+
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?
Attachment #644854 - Flags: review?(ted.mielczarek) → review+
Attachment #644855 - Flags: review?(ted.mielczarek) → review+
> @@ +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
With support for 'a'.
Attachment #645317 - Flags: review?(ted.mielczarek)
Attachment #644854 - Attachment is obsolete: true
Attachment #644855 - Attachment is obsolete: true
Comment on attachment 645319 [details] [diff] [review] part 3 - Use the new MockedOpen in unit-Preprocessor.py Carrying over r+.
Attachment #645319 - Flags: review+
Attachment #645317 - Flags: review?(ted.mielczarek) → review+
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: