|
1 | 1 | import os.path
|
| 2 | +import re |
2 | 3 | import subprocess
|
3 | 4 | import socket
|
4 | 5 | import atexit
|
|
14 | 15 | from labgrid.util.helper import get_free_port
|
15 | 16 | from labgrid.util.ssh import ForwardError, SSHConnection, sshmanager
|
16 | 17 | from labgrid.util.proxy import proxymanager
|
17 |
| -from labgrid.util.managedfile import ManagedFile |
| 18 | +from labgrid.util.managedfile import ManagedFile, ManagedFileError |
18 | 19 | from labgrid.driver.exception import ExecutionError
|
19 | 20 | from labgrid.resource.serialport import NetworkSerialPort
|
20 | 21 | from labgrid.resource.common import Resource, NetworkResource
|
@@ -352,6 +353,47 @@ def test_local_managedfile(target, tmpdir):
|
352 | 353 | assert hash == mf.get_hash()
|
353 | 354 | assert str(t) == mf.get_remote_path()
|
354 | 355 |
|
| 356 | +def test_network_managedfile_no_sync(target, tmpdir): |
| 357 | + res = NetworkResource(target, "test", "localhost") |
| 358 | + t = tmpdir.join("test") |
| 359 | + t.write( |
| 360 | +""" |
| 361 | +Test |
| 362 | +""" |
| 363 | + ) |
| 364 | + mf = ManagedFile(t, res, detect_nfs=False) |
| 365 | + |
| 366 | + expected = re.escape("sync_to_resource() needs to be called before the remote-path can be retrieved") |
| 367 | + with pytest.raises(ManagedFileError, match=expected) as e: |
| 368 | + mf.get_remote_path() |
| 369 | + |
| 370 | +def test_local_managedfile_symlink(target, tmpdir): |
| 371 | + res = Resource(target, "test") |
| 372 | + t = tmpdir.join("test") |
| 373 | + t.write( |
| 374 | +""" |
| 375 | +Test |
| 376 | +""" |
| 377 | + ) |
| 378 | + mf = ManagedFile(t, res, detect_nfs=False) |
| 379 | + mf.sync_to_resource(symlink=tmpdir.join("link")) |
| 380 | + |
| 381 | + assert str(t) == mf.get_remote_path() |
| 382 | + assert os.path.islink(tmpdir.join("link")) |
| 383 | + |
| 384 | +@pytest.mark.localsshmanager |
| 385 | +def test_remote_managedfile_symlink(target, tmpdir): |
| 386 | + res = NetworkResource(target, "test", "localhost") |
| 387 | + t = tmpdir.join("test") |
| 388 | + t.write( |
| 389 | +""" |
| 390 | +Test |
| 391 | +""" |
| 392 | + ) |
| 393 | + mf = ManagedFile(t, res, detect_nfs=False) |
| 394 | + mf.sync_to_resource(symlink=tmpdir.join("link")) |
| 395 | + |
| 396 | + assert os.path.islink(tmpdir.join("link")) |
355 | 397 |
|
356 | 398 | def test_find_dict():
|
357 | 399 | dict_a = {"a": {"a.a": {"a.a.a": "a.a.a_val"}}, "b": "b_val"}
|
|
0 commit comments