~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to tests/test_changelog.py

  • Committer: Benjamin Drung
  • Date: 2023-02-13 12:45:23 UTC
  • Revision ID: benjamin.drung@canonical.com-20230213124523-4f1nv2fyvsdl35jb
Fix pycodestyle complains by formatting Python code with black

```
black -C -l 79 .
```

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import sys
8
8
import unittest
9
9
import glob
 
10
 
10
11
try:
11
12
    from urllib.error import HTTPError
12
13
except ImportError:
18
19
 
19
20
 
20
21
class TestChangelogs(unittest.TestCase):
21
 
 
22
22
    def setUp(self):
23
23
        # Whenever a test will initialize apt_pkg, we must set the architecture
24
24
        # to amd64, because our various test files assume that.  Even if this
27
27
        real_arch = apt.apt_pkg.config.find("APT::Architecture")
28
28
        apt.apt_pkg.config.set("APT::Architecture", "amd64")
29
29
        self.addCleanup(
30
 
            lambda: apt.apt_pkg.config.set("APT::Architecture", real_arch))
 
30
            lambda: apt.apt_pkg.config.set("APT::Architecture", real_arch)
 
31
        )
31
32
 
32
33
        self.aptroot = os.path.join(CURDIR, "aptroot-changelog")
33
34
 
34
 
        self.cache = MyCache(apt.progress.base.OpProgress(),
35
 
                             rootdir=self.aptroot)
 
35
        self.cache = MyCache(
 
36
            apt.progress.base.OpProgress(), rootdir=self.aptroot
 
37
        )
36
38
        self.cache.open()
37
39
 
38
40
    def tearDown(self):
48
50
        # test binary changelogs
49
51
        uri = self.cache._guess_third_party_changelogs_uri_by_binary(pkgname)
50
52
        pkg = self.cache[pkgname]
51
 
        self.assertEqual(uri,
52
 
                         pkg.candidate.uri.replace(".deb", ".changelog"))
 
53
        self.assertEqual(uri, pkg.candidate.uri.replace(".deb", ".changelog"))
53
54
        # test source changelogs
54
55
        uri = self.cache._guess_third_party_changelogs_uri_by_source(pkgname)
55
56
        self.assertTrue("gcc-defaults_" in uri)
67
68
    def test_changelog_not_supported(self):
68
69
        def monkey_patched_get_changelogs(name, what, ver, uri):
69
70
            with open("/dev/zero") as zero:
70
 
                raise HTTPError(
71
 
                    "url", "code", "msg", "hdrs", zero)
 
71
                raise HTTPError("url", "code", "msg", "hdrs", zero)
 
72
 
72
73
        pkgname = "gcc"
73
74
        # patch origin
74
75
        real_origin = self.cache.CHANGELOG_ORIGIN
80
81
        error = "This update does not come from a source that "
81
82
        error += "supports changelogs."
82
83
        # verify that we don't have the lines twice
83
 
        self.assertEqual(self.cache.all_changes[pkgname].split("\n")[-1],
84
 
                         error)
 
84
        self.assertEqual(
 
85
            self.cache.all_changes[pkgname].split("\n")[-1], error
 
86
        )
85
87
        self.assertEqual(len(self.cache.all_changes[pkgname].split("\n")), 5)
86
88
        self.assertEqual(self.cache.all_changes[pkgname].count(error), 1)
87
89
        self.cache.CHANGELOG_ORIGIN = real_origin
88
90
 
89
91
 
90
 
if __name__ == '__main__':
 
92
if __name__ == "__main__":
91
93
    if len(sys.argv) > 1 and sys.argv[1] == "-v":
92
94
        logging.basicConfig(level=logging.DEBUG)
93
95
    unittest.main()