~ubuntu-core-dev/ubuntu/xenial/ubuntu-release-upgrader/xenial

« back to all changes in this revision

Viewing changes to tests/test_cdrom.py

  • Committer: Dimitri John Ledkov
  • Date: 2015-01-20 22:30:06 UTC
  • mto: This revision was merged to the branch mainline in revision 2859.
  • Revision ID: dimitri.j.ledkov@intel.com-20150120223006-ba30fbqtp4x2n0og
Fix resource warnings & logging.warn deprecation warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
    def testWriteDatabase(self):
28
28
        expect = \
29
 
            "CD::36e3f69081b7d10081d167b137886a71-2 " \
 
29
            "CD::0380987599d9f666b749fbfe29d5b440-2 " \
30
30
            "\"Ubuntu 8.10 _Intrepid Ibex_ - Beta amd64 (20080930.4)\";\n" \
31
 
            "CD::36e3f69081b7d10081d167b137886a71-2::Label " \
 
31
            "CD::0380987599d9f666b749fbfe29d5b440-2::Label " \
32
32
            "\"Ubuntu 8.10 _Intrepid Ibex_ - Beta amd64 (20080930.4)\";\n"
33
33
        p = CURDIR + "/test-data-cdrom/"
34
34
        database = CURDIR + "/test-data-cdrom/cdrom.list"
39
39
            os.unlink(database)
40
40
        cdrom = AptCdrom(None, p)
41
41
        cdrom._writeDatabase()
42
 
        self.assertEqual(expect, open(database).read())
 
42
        with open(database) as f:
 
43
            self.assertEqual(expect, f.read())
43
44
 
44
45
    def testScanCD(self):
45
46
        p = CURDIR + "/test-data-cdrom"
134
135
    def test_comment_out(self):
135
136
        tmpdir = tempfile.mkdtemp()
136
137
        sourceslist = os.path.join(tmpdir, "sources.list")
137
 
        open(sourceslist, "w")
138
138
        apt_pkg.config.set("dir::etc::sourcelist", sourceslist)
139
139
        apt_pkg.config.set("dir::state::lists", tmpdir)
140
140
        view = Mock()
141
141
        cdrom = AptCdrom(view, CURDIR + "/test-data-cdrom")
142
142
        cdrom.add()
143
143
        cdrom.comment_out_cdrom_entry()
144
 
        for line in open(sourceslist):
 
144
        with open(sourceslist) as f:
 
145
            sourceslines = f.readlines()
 
146
        for line in sourceslines:
145
147
            self.assertTrue(line.startswith("#"))
146
 
        self.assertEqual(len(open(sourceslist).readlines()), 2)
 
148
        self.assertEqual(len(sourceslines), 2)
147
149
 
148
150
 
149
151
if __name__ == "__main__":