Example #1
0
def test_attributes_without_path_return_correct_values():
    # save the actual working dir
    working_dir = os.getcwd()

    # Go to the test dir and populate with files
    populate_test_dir()

    # run attrib and get values
    attrib = Attrib()
    attributes = attrib.attributes

    # all files have an A attribute when created
    filename = os.path.join(TEST_DIR, 'archive')
    assert attributes[filename] == ['A']

    filename = os.path.join(TEST_DIR, 'hidden')
    assert attributes[filename] == ['A', ATTR_HIDDEN]

    filename = os.path.join(TEST_DIR, 'read_only')
    assert attributes[filename] == ['A', ATTR_READ_ONLY]

    filename = os.path.join(TEST_DIR, 'system')
    assert attributes[filename] == ['A', ATTR_SYSTEM_FILE]

    # make some changes
    os.system('attrib -a archive')
    attrib = Attrib()
    attributes = attrib.attributes
    filename = os.path.join(TEST_DIR, 'archive')
    assert attributes[filename] == []
Example #2
0
def test_attributes_recursive_true():
    working_dir = os.getcwd()
    populate_test_dir()

    attrib = Attrib(recursive=True)
    attr = attrib.attributes
    print(attr)
    assert len(attr) == 5
Example #3
0
def test_attributes_recursive_true_apply_directory_true():
    working_dir = os.getcwd()
    populate_test_dir()

    attrib = Attrib(recursive=True, apply_directories=True)
    attr = attrib.attributes
    print(attr)
    assert len(attr) == 6

    # assert there is one dir
    dir_count = sum(os.path.isdir(i) for i in attr)
    assert dir_count == 1
Example #4
0
def test_attributes_without_path_return_dict_correct_lenght():

    # save the actual working dir
    working_dir = os.getcwd()

    # Go to the test dir and populate with files
    os.chdir(TEST_DIR)
    create_file_with_attribute('archive', 'a')
    create_file_with_attribute('hidden', 'h')
    create_file_with_attribute('read_only', 'r')
    create_file_with_attribute('system', 's')

    # run attrib
    attrib = Attrib()
    assert len(attrib.attributes) == 4
Example #5
0
def test_attributes_without_path_return_dict():
    # Should return a dict with information from files in the current folder
    # if not recursive

    # save the actual working dir
    working_dir = os.getcwd()

    # Go to the test dir and populate with files
    os.chdir(TEST_DIR)
    create_file_with_attribute('archive', 'a')
    create_file_with_attribute('hidden', 'h')
    create_file_with_attribute('read_only', 'r')
    create_file_with_attribute('system', 's')

    # run attrib
    attrib = Attrib()
    assert isinstance(attrib.attributes, dict)
Example #6
0
def test_clear_all_attributes_recursive():
    os.chdir(TEST_DIR)
    open('file1.txt', 'w').close()
    #subdir
    foo = os.path.join(TEST_DIR, 'foo')
    os.mkdir(foo)

    file2 = os.path.join(foo, 'file2')
    open(os.path.join(foo, 'file2'), 'w').close()
    a = Attrib(recursive=True)

    a.set_attributes(ATTR_HIDDEN)
    assert len(a.attributes) == 2

    test_file2 = Attrib(file2)
    assert test_file2.attributes == ['A', ATTR_HIDDEN]

    test_file1 = Attrib(os.path.join(TEST_DIR, 'file1.txt'))
    assert test_file1.attributes == ['A', ATTR_HIDDEN]

    a.clear_all()
    assert test_file1.attributes == []
    assert test_file2.attributes == []
Example #7
0
def attrib():
    from pyattrib import Attrib
    attrib = Attrib(TEST_DIR)
    return attrib