Esempio n. 1
0
def test_back_up_file_bad_input(mock_link):
    # GIVEN I have an integer or None
    file1 = 123
    file2 = None

    # WHEN I back it up
    # THEN we explode and do not attempt to link
    try:
        # Python 3.6
        with pytest.raises(TypeError):
            ops_utils.back_up_file(file1)
    except:
        # Python 2.7 - 3.5
        with pytest.raises(AttributeError):
            ops_utils.back_up_file(file1)
    assert mock_link.called is False

    try:
        # Python 3.6
        with pytest.raises(TypeError):
            ops_utils.back_up_file(file2)
    except:
        # Python 2.7 - 3.5
        with pytest.raises(AttributeError):
            ops_utils.back_up_file(file2)
    assert mock_link.called is False
Esempio n. 2
0
def test_back_up_file_bad_input(mock_link):
    # GIVEN I have an integer
    file = 123

    # WHEN I back it up
    # THEN we explode and do not attempt to link
    with pytest.raises(AttributeError):
        ops_utils.back_up_file(file)

    assert mock_link.called is False

    file = None
    with pytest.raises(AttributeError):
        ops_utils.back_up_file(file)

    assert mock_link.called is False
Esempio n. 3
0
def test_back_up_file_bad_file(mock_link):
    # GIVEN I have a path to a directory
    file = "/foo/bar/"

    # WHEN I back it up
    backup_file = ops_utils.back_up_file(file)

    # THEN we do not attempt to link
    assert backup_file is False
    assert mock_link.called is False
Esempio n. 4
0
def test_back_up_file_rel_success(mock_link):
    # GIVEN I have a relative file to back up
    file = "baz.py"

    # WHEN I back it up
    backup_file = ops_utils.back_up_file(file)

    # THEN I get the full path to the backup
    assert backup_file == os.path.join(os.getcwd(), file + "_orig")
    mock_link.assert_called_with(file, backup_file)
Esempio n. 5
0
def test_back_up_file_success(mock_link):
    # GIVEN I have a legitimate file to back up
    file = "/foo/bar/baz.py"

    # WHEN I back it up
    backup_file = ops_utils.back_up_file(file)

    # THEN I get the path to the backup
    assert backup_file == "/foo/bar/baz.py_orig"
    mock_link.assert_called_with(file, backup_file)
Esempio n. 6
0
def test_back_up_file_bad_file(mock_link):
    # GIVEN I have a path to a directory
    file = "/foo/bar/"

    # WHEN I back it up
    backup_file = ops_utils.back_up_file(file)

    # THEN we do not attempt to link
    assert backup_file is False
    assert mock_link.called is False
Esempio n. 7
0
def test_back_up_file_rel_success(mock_link):
    # GIVEN I have a relative file to back up
    file = "baz.py"

    # WHEN I back it up
    backup_file = ops_utils.back_up_file(file)

    # THEN I get the full path to the backup
    assert backup_file == os.path.join(os.getcwd(), file + "_orig")
    mock_link.assert_called_with(file, backup_file)
Esempio n. 8
0
def test_back_up_file_success(mock_link):
    # GIVEN I have a legitimate file to back up
    file = "/foo/bar/baz.py"

    # WHEN I back it up
    backup_file = ops_utils.back_up_file(file)

    # THEN I get the path to the backup
    assert backup_file == "/foo/bar/baz.py_orig"
    mock_link.assert_called_with(file, backup_file)
Esempio n. 9
0
def test_back_up_file_custom_suffix(mock_link):
    # GIVEN I have a legitimate file to back up
    file = "baz.py"
    suffix = "_bak"
    target_dir = "/foo/bar/"

    # WHEN I specify a custom dir and suffix
    backup_file = ops_utils.back_up_file(file, target_dir, suffix)

    # THEN the backup path reflects them
    assert backup_file == os.path.join(target_dir, file + suffix)
    mock_link.assert_called_with(file, backup_file)
Esempio n. 10
0
def test_back_up_file_custom_suffix(mock_link):
    # GIVEN I have a legitimate file to back up
    file = "baz.py"
    suffix = "_bak"
    target_dir = "/foo/bar/"

    # WHEN I specify a custom dir and suffix
    backup_file = ops_utils.back_up_file(file, target_dir, suffix)

    # THEN the backup path reflects them
    assert backup_file == os.path.join(target_dir, file + suffix)
    mock_link.assert_called_with(file, backup_file)