Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better UX error for migrations (#7966)
* Better UX error for migrations Signed-off-by: Uilian Ries <uilianries@gmail.com> * File already exists is not an error Signed-off-by: Uilian Ries <uilianries@gmail.com> * Print dir path name for makedirs error Signed-off-by: Uilian Ries <uilianries@gmail.com> * Fix cache attribute Signed-off-by: Uilian Ries <uilianries@gmail.com> * Run migration test Signed-off-by: Uilian Ries <uilianries@gmail.com> * Fix expected string Signed-off-by: Uilian Ries <uilianries@gmail.com> * Improve migration error message Signed-off-by: Uilian Ries <uilianries@gmail.com> * Filter error message for utils.file.save Signed-off-by: Uilian Ries <uilianries@gmail.com> * Exclude errno.ENOENT from file errors Signed-off-by: Uilian Ries <uilianries@gmail.com> * Could not apply chmod on Windows There is a note on chmod docs: https://docs.python.org/2.7/library/os.html#os.chmod "Although Windows supports chmod(), you can only set the file’s read-only flag with it (via the stat.S_IWRITE and stat.S_IREAD constants or a corresponding integer value). All other bits are ignored." However, it works for files, not for folder. Signed-off-by: Uilian Ries <uilianries@gmail.com>
- Loading branch information
1 parent
fabef25
commit c7f6749
Showing
4 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# coding=utf-8 | ||
|
||
import unittest | ||
import os | ||
import platform | ||
|
||
from conans.migrations import Migrator | ||
from conans.test.utils.mocks import TestBufferConanOutput | ||
from conans.test.utils.test_files import temp_folder | ||
from conans.errors import ConanMigrationError | ||
|
||
|
||
class FakeMigrator(Migrator): | ||
|
||
def __init__(self, cache_folder, current_version, out): | ||
self.cache_folder = cache_folder | ||
super(FakeMigrator, self).__init__(cache_folder, current_version, out) | ||
|
||
def _make_migrations(self, old_version): | ||
pass | ||
|
||
|
||
class MigratorPermissionTest(unittest.TestCase): | ||
|
||
@unittest.skipIf(platform.system() == "Windows", "Can't apply chmod on Windows") | ||
def test_invalid_permission(self): | ||
out = TestBufferConanOutput() | ||
conf_path = temp_folder(False) | ||
os.chmod(conf_path, 0o444) | ||
conf_path = os.path.join(conf_path, "foo") | ||
migrator = FakeMigrator(conf_path, "latest", out) | ||
with self.assertRaises(ConanMigrationError) as error: | ||
migrator.migrate() | ||
self.assertEqual("Can't write version file in '{0}/version.txt': The folder {0} does not " | ||
"exist and could not be created (Permission denied).".format(conf_path), | ||
str(error.exception)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters