Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def change_xdg_path(key, value=None, remove=False):
if value:
os.environ[key] = value
if remove:
with suppress(KeyError):
os.environ.pop(key)
import umake.tools
importlib.reload(xdg.BaseDirectory)
with suppress(KeyError):
umake.tools.Singleton._instances.pop(umake.tools.ConfigHandler)
umake.tools.xdg_config_home = xdg.BaseDirectory.xdg_config_home
umake.tools.xdg_data_home = xdg.BaseDirectory.xdg_data_home
def _parts_dir(self):
parts_uri = "https://parts.snapcraft.io/v1/parts.yaml"
return os.path.join(
xdg.BaseDirectory.save_data_path("snapcraft"),
hashlib.sha384(parts_uri.encode(sys.getfilesystemencoding())).hexdigest(),
)
def test_load_first_config(self):
tmpdir = tempfile.mkdtemp()
tmpdir2 = tempfile.mkdtemp()
tmpdir3 = tempfile.mkdtemp()
path = os.path.join(tmpdir3, "wpokewefketnrhruit")
os.mkdir(path)
try:
environ['XDG_CONFIG_HOME'] = tmpdir
environ['XDG_CONFIG_DIRS'] = ":".join([tmpdir2, tmpdir3])
reload(BaseDirectory)
configdir = BaseDirectory.load_first_config("wpokewefketnrhruit")
self.assertEqual(configdir, path)
finally:
shutil.rmtree(tmpdir)
shutil.rmtree(tmpdir2)
shutil.rmtree(tmpdir3)
def print_dir(entry, l):
i = " " * l
pu(i + "+==MENU")
pu(i, "|- name: " + repr(entry.getName()))
pu(i + "|- id:", entry.Name)
pu(i + "|- icon:", entry.getIcon())
de = entry.Directory
pu(i + "|- file:" + (de and de.DesktopEntry.filename or "None"))
pu(i + "|")
pu(i + " \\")
for e in entry.getEntries():
if isinstance(e, xdg.Menu.Separator):
print_sep(e, l+1)
elif isinstance(e, xdg.Menu.Menu):
print_dir(e, l+1)
elif isinstance(e, xdg.Menu.MenuEntry):
print_app(e, l+1)
# File that does exist - get type by contents
imgpng = Mime.get_type(example_file("png_file"))
self.check_mimetype(imgpng, 'image', 'png')
# Directory - special case
inodedir = Mime.get_type(example_file("subdir"))
self.check_mimetype(inodedir, 'inode', 'directory')
# Mystery files
mystery_text = Mime.get_type(example_file('mystery_text'))
self.check_mimetype(mystery_text, 'text', 'plain')
mystery_exe = Mime.get_type(example_file('mystery_exe'))
self.check_mimetype(mystery_exe, 'application', 'executable')
# Symlink
self.check_mimetype(Mime.get_type(example_file("png_symlink")),
'image', 'png')
self.check_mimetype(Mime.get_type(example_file("png_symlink"), follow=False),
'inode', 'symlink')
def test_get_type(self):
# File that doesn't exist - get type by name
imgpng = Mime.get_type(example_file("test.gif"))
self.check_mimetype(imgpng, 'image', 'gif')
# File that does exist - get type by contents
imgpng = Mime.get_type(example_file("png_file"))
self.check_mimetype(imgpng, 'image', 'png')
# Directory - special case
inodedir = Mime.get_type(example_file("subdir"))
self.check_mimetype(inodedir, 'inode', 'directory')
# Mystery files
mystery_text = Mime.get_type(example_file('mystery_text'))
self.check_mimetype(mystery_text, 'text', 'plain')
mystery_exe = Mime.get_type(example_file('mystery_exe'))
self.check_mimetype(mystery_exe, 'application', 'executable')
# Symlink
self.check_mimetype(Mime.get_type(example_file("png_symlink")),
'image', 'png')
self.check_mimetype(Mime.get_type(example_file("png_symlink"), follow=False),
'inode', 'symlink')
def test_get_type(self):
# File that doesn't exist - get type by name
imgpng = Mime.get_type(example_file("test.gif"))
self.check_mimetype(imgpng, 'image', 'gif')
# File that does exist - get type by contents
imgpng = Mime.get_type(example_file("png_file"))
self.check_mimetype(imgpng, 'image', 'png')
# Directory - special case
inodedir = Mime.get_type(example_file("subdir"))
self.check_mimetype(inodedir, 'inode', 'directory')
# Mystery files
mystery_text = Mime.get_type(example_file('mystery_text'))
self.check_mimetype(mystery_text, 'text', 'plain')
mystery_exe = Mime.get_type(example_file('mystery_exe'))
self.check_mimetype(mystery_exe, 'application', 'executable')
def test_unicode_menuentry(self):
test_file = os.path.join(self.tmpdir, "unicode.desktop")
with io.open(test_file, 'w', encoding='utf-8') as f:
f.write(resources.unicode_desktop)
entry = xdg.Menu.MenuEntry(test_file)
assert entry == entry
assert not entry < entry
def test_lookup(self):
pdf1 = Mime.lookup("application/pdf")
pdf2 = Mime.lookup("application", "pdf")
self.assertEqual(pdf1, pdf2)
self.check_mimetype(pdf1, 'application', 'pdf')
def test_inheritance(self):
text_python = Mime.lookup('text/x-python')
self.check_mimetype(text_python, 'text', 'x-python')
text_plain = Mime.lookup('text/plain')
app_executable = Mime.lookup('application/x-executable')
self.assertEqual(text_python.inherits_from(), set([text_plain, app_executable]))