<s> import os <EOL> import pytest <EOL> import shutil <EOL> import string <EOL> from tests . integrations . base import BaseTest , pull , gitfs_log <EOL> class TestWriteCurrentView ( BaseTest ) : <EOL> def test_delete_directory_with_space_within_name ( self , gitfs_log ) : <EOL> directory = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . makedirs ( directory ) <EOL> with pull ( self . sh ) : <EOL> directory_path = "<STR_LIT>" . format ( self . repo_path ) <EOL> assert os . path . exists ( directory_path ) <EOL> keep_path = "<STR_LIT>" . format ( self . repo_path ) <EOL> assert os . path . exists ( keep_path ) <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> shutil . rmtree ( "<STR_LIT>" . format ( self . current_path ) ) <EOL> with pull ( self . sh ) : <EOL> self . assert_new_commit ( ) <EOL> assert os . path . exists ( directory ) is False <EOL> def test_delete_a_directory ( self , gitfs_log ) : <EOL> path = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . makedirs ( path ) <EOL> with pull ( self . sh ) : <EOL> self . assert_new_commit ( ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> shutil . rmtree ( "<STR_LIT>" . format ( self . current_path ) ) <EOL> with pull ( self . sh ) : <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> self . assert_new_commit ( ) <EOL> assert os . path . exists ( path ) is False <EOL> def test_rename_directory ( self , gitfs_log ) : <EOL> old_dir = "<STR_LIT>" . format ( self . current_path ) <EOL> new_dir = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . makedirs ( old_dir ) <EOL> with pull ( self . sh ) : <EOL> self . assert_new_commit ( ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . rename ( old_dir , new_dir ) <EOL> with pull ( self . sh ) : <EOL> self . assert_new_commit ( ) <EOL> assert os . path . isdir ( new_dir ) is not False <EOL> assert os . path . exists ( old_dir ) is False <EOL> def test_link_a_file ( self , gitfs_log ) : <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> link_name = "<STR_LIT>" . format ( self . current_path ) <EOL> with open ( filename , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . link ( filename , link_name ) <EOL> with pull ( self . sh ) : <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> is_link = os . path . isfile ( link_name ) <EOL> assert is_link is not False <EOL> def test_write_a_file ( self , gitfs_log ) : <EOL> content = "<STR_LIT>" <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> with open ( filename , "<STR_LIT:w>" ) as f : <EOL> f . write ( content ) <EOL> with open ( filename ) as f : <EOL> assert f . read ( ) == content <EOL> with pull ( self . sh ) : <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> def test_create_a_directory ( self , gitfs_log ) : <EOL> directory = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . makedirs ( directory ) <EOL> with pull ( self . sh ) : <EOL> directory_path = "<STR_LIT>" . format ( self . repo_path ) <EOL> assert os . path . exists ( directory_path ) <EOL> keep_path = "<STR_LIT>" . format ( self . repo_path ) <EOL> assert os . path . exists ( keep_path ) <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> def test_write_in_keep_file ( self ) : <EOL> directory = "<STR_LIT>" . format ( self . current_path ) <EOL> with pytest . raises ( IOError ) : <EOL> with open ( "<STR_LIT>" . format ( directory ) , '<STR_LIT:w>' ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> def test_create_embedded_directory ( self , gitfs_log ) : <EOL> directory = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . makedirs ( directory ) <EOL> with pull ( self . sh ) : <EOL> directory_path = "<STR_LIT>" . format ( self . repo_path ) <EOL> assert os . path . exists ( directory_path ) <EOL> keep_files = [ <EOL> "<STR_LIT>" . format ( self . repo_path ) , <EOL> "<STR_LIT>" . format ( self . repo_path ) <EOL> ] <EOL> for keep_file in keep_files : <EOL> assert os . path . exists ( keep_file ) <EOL> self . assert_new_commit ( ) <EOL> commit_msg = "<STR_LIT>" <EOL> self . assert_commit_message ( commit_msg ) <EOL> def test_create_directory_inside_an_already_existing_directory ( self , gitfs_log ) : <EOL> directory = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . makedirs ( directory ) <EOL> with pull ( self . sh ) : <EOL> directory_path = "<STR_LIT>" . format ( self . repo_path ) <EOL> assert os . path . exists ( directory_path ) <EOL> keep_files = [ <EOL> "<STR_LIT>" . format ( self . repo_path ) , <EOL> "<STR_LIT>" . format ( self . repo_path ) <EOL> ] <EOL> for keep_file in keep_files : <EOL> assert os . path . exists ( keep_file ) <EOL> self . assert_new_commit ( ) <EOL> commit_msg = "<STR_LIT>" <EOL> self . assert_commit_message ( commit_msg ) <EOL> def test_create_embedded_directory_on_multiple_levels ( self , gitfs_log ) : <EOL> directory = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . makedirs ( directory ) <EOL> with pull ( self . sh ) : <EOL> directory_path = "<STR_LIT>" . format ( self . repo_path ) <EOL> assert os . path . exists ( directory_path ) <EOL> keep_files = [ <EOL> "<STR_LIT>" . format ( self . repo_path ) , <EOL> "<STR_LIT>" . format ( self . repo_path ) , <EOL> "<STR_LIT>" . format ( self . repo_path ) , <EOL> ] <EOL> for keep_file in keep_files : <EOL> assert os . path . exists ( keep_file ) <EOL> self . assert_new_commit ( ) <EOL> commit_msg = "<STR_LIT>" . format ( len ( keep_files ) ) <EOL> self . assert_commit_message ( commit_msg ) <EOL> def test_create_embedded_directory_big_depth ( self , gitfs_log ) : <EOL> path = "<STR_LIT>" <EOL> for letter in string . ascii_lowercase : <EOL> path = os . path . join ( path , letter ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . makedirs ( os . path . join ( self . current_path , path ) ) <EOL> with pull ( self . sh ) : <EOL> directory_path = os . path . join ( self . repo_path , path ) <EOL> assert os . path . exists ( directory_path ) <EOL> keep_files = [ ] <EOL> path = self . repo_path <EOL> for letter in string . ascii_lowercase : <EOL> path = os . path . join ( path , letter ) <EOL> path_with_keep = os . path . join ( path , '<STR_LIT>' ) <EOL> keep_files . append ( path_with_keep ) <EOL> for keep_file in keep_files : <EOL> assert os . path . exists ( keep_file ) <EOL> def test_chmod_valid_mode ( self , gitfs_log ) : <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . chmod ( <EOL> filename , <EOL> <NUM_LIT> , <EOL> ) <EOL> with pull ( self . sh ) : <EOL> stats = os . stat ( filename ) <EOL> assert stats . st_mode == <NUM_LIT> <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> def test_chmod_invalid_mode ( self ) : <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> with pytest . raises ( OSError ) : <EOL> os . chmod ( <EOL> filename , <EOL> <NUM_LIT> , <EOL> ) <EOL> def test_rename ( self , gitfs_log ) : <EOL> old_filename = "<STR_LIT>" . format ( self . current_path ) <EOL> new_filename = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . rename ( old_filename , new_filename ) <EOL> with pull ( self . sh ) : <EOL> assert os . path . exists ( new_filename ) <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> def test_fsync ( self , gitfs_log ) : <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> content = "<STR_LIT>" <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> with open ( filename , "<STR_LIT:w>" ) as f : <EOL> f . write ( content ) <EOL> os . fsync ( f . fileno ( ) ) <EOL> with pull ( self . sh ) : <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> def test_create ( self , gitfs_log ) : <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> open ( filename , "<STR_LIT:a>" ) . close ( ) <EOL> with pull ( self . sh ) : <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> def test_symbolic_link ( self , gitfs_log ) : <EOL> target = "<STR_LIT>" <EOL> name = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . symlink ( target , name ) <EOL> with pull ( self . sh ) : <EOL> assert os . path . exists ( name ) <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( target ) ) <EOL> def test_edit_file ( self , gitfs_log ) : <EOL> content = "<STR_LIT>" <EOL> continuation = "<STR_LIT>" <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> with open ( filename , "<STR_LIT:w>" ) as f : <EOL> f . write ( content ) <EOL> with pull ( self . sh ) : <EOL> with open ( filename ) as f : <EOL> assert f . read ( ) == content <EOL> self . assert_new_commit ( ) <EOL> with pull ( self . sh ) : <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> with open ( filename , "<STR_LIT:w>" ) as f : <EOL> f . write ( continuation ) <EOL> with pull ( self . sh ) : <EOL> with open ( filename ) as f : <EOL> assert f . read ( ) == continuation <EOL> self . assert_new_commit ( ) <EOL> with pull ( self . sh ) : <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> def test_create_multiple_files ( self , gitfs_log ) : <EOL> content = "<STR_LIT>" <EOL> no_of_files = <NUM_LIT:10> <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> for i in range ( no_of_files ) : <EOL> with open ( filename + str ( i ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( content ) <EOL> with pull ( self . sh ) : <EOL> for i in range ( no_of_files ) : <EOL> with open ( filename + str ( i ) ) as f : <EOL> assert f . read ( ) == content <EOL> self . assert_new_commit ( ) <EOL> with pull ( self . sh ) : <EOL> self . assert_commit_message ( "<STR_LIT>" . format ( no_of_files ) ) <EOL> def test_delete_file ( self , gitfs_log ) : <EOL> filename = "<STR_LIT>" . format ( self . current_path ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> with open ( filename , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> with pull ( self . sh ) : <EOL> self . assert_new_commit ( ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) <EOL> with gitfs_log ( "<STR_LIT>" ) : <EOL> os . remove ( filename ) <EOL> with pull ( self . sh ) : <EOL> assert not os . path . exists ( filename ) <EOL> self . assert_commit_message ( "<STR_LIT>" ) </s>
