~rsalveti/linaro-image-tools/generic-hwpack-oe

« back to all changes in this revision

Viewing changes to linaro_image_tools/tests/fixtures.py

MergeĀ lp:~milo/linaro-image-tools/hwpack-format-converter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        return self.tempdir
42
42
 
43
43
 
 
44
class CreateTempFileFixture(object):
 
45
    """Class to create a temporary file to be used in a test."""
 
46
    def __init__(self, string=None):
 
47
        """Initialize the fixture.
 
48
 
 
49
        :param string: the string to write in the file.
 
50
        """
 
51
        self.temp_file = None
 
52
        self.string = string
 
53
 
 
54
    def setUp(self):
 
55
        self.temp_file = tempfile.NamedTemporaryFile()
 
56
        if self.string is not None:
 
57
            self.temp_file.write(self.string)
 
58
            # Go back to the initial position, we just need to write something
 
59
            # and be able to read from the beginning of the file.
 
60
            self.temp_file.seek(0)
 
61
 
 
62
    def tearDown(self):
 
63
        # We don't need to do anything, file is automatically deleted.
 
64
        pass
 
65
 
 
66
    def get_file_name(self):
 
67
        return self.temp_file.name
 
68
 
 
69
 
44
70
class MockSomethingFixture(object):
45
71
    """A fixture which mocks something on the given object.
46
72