File: test_system_utils.py

package info (click to toggle)
dijitso 2018.1.1~git1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 420 kB
  • sloc: python: 1,672; makefile: 194; sh: 53; ansic: 1
file content (57 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download | duplicates (4)
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
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
# Copyright (C) 2015-2016 Martin Sandve Alnæs
#
# This file is part of DIJITSO.
#
# DIJITSO is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DIJITSO is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DIJITSO. If not, see <http://www.gnu.org/licenses/>.

import io
import os
import uuid
from dijitso.system import lockfree_move_file, make_dirs


def test_get_status_output():
    pass  # FIXME


def test_lockfree_move_file():
    # Running this loop in multiple processes with mpi is perhaps a
    # decent test?

    # Fixed directory independent of mpi rank
    tmpdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".test_lockfree_move_file")
    make_dirs(tmpdir)

    # source is different for each process and loop iteration
    n = 3
    u = uuid.uuid4().int
    srcs = [os.path.join(tmpdir, "test_lockfree_move_file-%d.src-%d" % (u, i))
            for i in range(n)]

    # fixed destination
    dst = os.path.join(tmpdir, "test_lockfree_move_file.dst")
    # try_delete_file(dst)   # can't do this when testing with mpi!

    for src in srcs:
        with io.open(src, "w", encoding="utf-8") as f:
            f.write("dummy")
        assert os.path.exists(src)
        lockfree_move_file(src, dst)
        assert os.path.exists(dst)
        assert not os.path.exists(src)

    with io.open(dst, encoding="utf-8") as f:
        dummy = f.read()
    assert dummy == "dummy"