forked from spack/spack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironment.py
More file actions
50 lines (38 loc) · 1.49 KB
/
environment.py
File metadata and controls
50 lines (38 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
import pickle
import pytest
from spack.environment import Environment
from spack.environment.environment import (
SpackEnvironmentViewError,
_error_on_nonempty_view_dir,
)
def test_environment_pickle(tmpdir):
env1 = Environment(str(tmpdir))
obj = pickle.dumps(env1)
env2 = pickle.loads(obj)
assert isinstance(env2, Environment)
def test_error_on_nonempty_view_dir(tmpdir):
"""Error when the target is not an empty dir"""
with tmpdir.as_cwd():
os.mkdir("empty_dir")
os.mkdir("nonempty_dir")
with open(os.path.join("nonempty_dir", "file"), "wb"):
pass
os.symlink("empty_dir", "symlinked_empty_dir")
os.symlink("does_not_exist", "broken_link")
os.symlink("broken_link", "file")
# This is OK.
_error_on_nonempty_view_dir("empty_dir")
# This is not OK.
with pytest.raises(SpackEnvironmentViewError):
_error_on_nonempty_view_dir("nonempty_dir")
with pytest.raises(SpackEnvironmentViewError):
_error_on_nonempty_view_dir("symlinked_empty_dir")
with pytest.raises(SpackEnvironmentViewError):
_error_on_nonempty_view_dir("broken_link")
with pytest.raises(SpackEnvironmentViewError):
_error_on_nonempty_view_dir("file")