Merge lp:~jelmer/brz/config-win32 into lp:brz/3.2

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/config-win32
Merge into: lp:brz/3.2
Diff against target: 94 lines (+65/-1)
2 files modified
breezy/bedding.py (+7/-1)
breezy/tests/test_bedding.py (+58/-0)
To merge this branch: bzr merge lp:~jelmer/brz/config-win32
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Aleksandr Smyshliaev (community) Approve
Review via email: mp+414133@code.launchpad.net

Commit message

Require that AppData is known on Windows. (Aleksandr Smyshliaev, Jelmer Vernooij)

Description of the change

Require that AppData is known on Windows.

Derived from lp:~a1s/brz/3.2 (and with appropriate author).

To post a comment you must log in.
Revision history for this message
Aleksandr Smyshliaev (a1s) :
review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) :
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bedding.py'
2--- breezy/bedding.py 2020-06-01 19:35:12 +0000
3+++ breezy/bedding.py 2022-01-14 14:42:31 +0000
4@@ -96,7 +96,13 @@
5 if base is None:
6 base = win32utils.get_appdata_location()
7 if base is None:
8- base = win32utils.get_home_location()
9+ # Assume that AppData location is ALWAYS DEFINED,
10+ # and don't look for %HOME%, as we aren't sure about
11+ # where the files should be stored in %HOME%:
12+ # on other platforms the directory is ~/.config/,
13+ # but that would be incompatible with older Bazaar versions.
14+ raise RuntimeError('Unable to determine AppData location')
15+
16 if base is None:
17 base = os.environ.get('XDG_CONFIG_HOME')
18 if base is None:
19
20=== modified file 'breezy/tests/test_bedding.py'
21--- breezy/tests/test_bedding.py 2020-06-01 19:35:12 +0000
22+++ breezy/tests/test_bedding.py 2022-01-14 14:42:31 +0000
23@@ -26,6 +26,8 @@
24 tests,
25 )
26
27+if sys.platform == "win32":
28+ from .. import win32utils
29
30 def override_whoami(test):
31 test.overrideEnv('EMAIL', None)
32@@ -96,6 +98,62 @@
33 self.bzr_home + '/authentication.conf')
34
35
36+class TestConfigPathFallbackWindows(tests.TestCaseInTempDir):
37+
38+ def mock_special_folder_path(self, csidl):
39+ if csidl == win32utils.CSIDL_APPDATA:
40+ return self.appdata
41+ elif csidl == win32utils.CSIDL_PERSONAL:
42+ return self.test_dir
43+ return None
44+
45+ def setUp(self):
46+ if sys.platform != 'win32':
47+ raise tests.TestNotApplicable(
48+ 'This test is specific to Windows platform')
49+ super(TestConfigPathFallbackWindows, self).setUp()
50+ # Note: No HOME fallback on Windows. The configs MUST be in AppData,
51+ # and we only fall back from breezy to bazaar configuration files.
52+ self.appdata = os.path.join(self.test_dir, 'appdata')
53+ self.appdata_bzr = os.path.join(self.appdata, 'bazaar', '2.0')
54+ os.makedirs(self.appdata_bzr)
55+ self.overrideAttr(
56+ win32utils, "_get_sh_special_folder_path",
57+ self.mock_special_folder_path)
58+ # The safety net made by super() has set BZR_HOME and BRZ_HOME
59+ # to the temporary directory. As they take precedence, we need
60+ # to erase the variables in order to check Windows special folders.
61+ self.overrideEnv('BRZ_HOME', None)
62+ self.overrideEnv('BZR_HOME', None)
63+
64+ def test_config_dir(self):
65+ self.assertIsSameRealPath(bedding.config_dir(), self.appdata_bzr)
66+
67+ def test_config_dir_is_unicode(self):
68+ self.assertIsInstance(bedding.config_dir(), str)
69+
70+ def test_config_path(self):
71+ self.assertIsSameRealPath(
72+ bedding.config_path(),
73+ self.appdata_bzr + '/bazaar.conf')
74+ self.overrideAttr(win32utils, "get_appdata_location", lambda: None)
75+ self.assertRaises(RuntimeError, bedding.config_path)
76+
77+ def test_locations_config_path(self):
78+ self.assertIsSameRealPath(
79+ bedding.locations_config_path(),
80+ self.appdata_bzr + '/locations.conf')
81+ self.overrideAttr(win32utils, "get_appdata_location", lambda: None)
82+ self.assertRaises(RuntimeError, bedding.locations_config_path)
83+
84+ def test_authentication_config_path(self):
85+ self.assertIsSameRealPath(
86+ bedding.authentication_config_path(),
87+ self.appdata_bzr + '/authentication.conf')
88+ self.overrideAttr(win32utils, "get_appdata_location", lambda: None)
89+ self.assertRaises(RuntimeError, bedding.authentication_config_path)
90+
91+
92 class TestXDGConfigDir(tests.TestCaseInTempDir):
93 # must be in temp dir because config tests for the existence of the bazaar
94 # subdirectory of $XDG_CONFIG_HOME

Subscribers

People subscribed via source and target branches