def test_copy_file_and_replace_keywords(): template = read_file(TEMPLATE_FILE) _copy_file_and_replace_keywords(BUILD_DESTINATION, template, KEYWORDS) assert path_exists(BUILD_DESTINATION) is True assert read_file(BUILD_DESTINATION) == EXPECTED_RESULT
def write_to_file(path, content): if path_exists(path) is False: raise IOError('File does not exist.') dst_f = open(path, 'w') dst_f.write(content) dst_f.close()
def create_file(path, content=None): if path_exists(path) is True: raise IOError('Files cannot be overwritten with this method.') dst_f = open(path, 'w+') if content is not None: dst_f.write(content) dst_f.close()
def _get_m_file_from_repos(mesh): m_file = None for repo in os.listdir(ROS_MESH_DATA_DIR): repo_path = join_paths(ROS_MESH_DATA_DIR, repo) mesh_path = join_paths(repo_path, mesh) if path_exists(mesh_path): m_file = mesh_path return m_file
def execute_and_check_remove(path, remove_function): remove_function(path) assert path_exists(path) is False
def assert_make_dir_function(path, make_dir_function): make_dir_function(path) assert path_exists(path) is True remove_directory_if_exists(path)
def remove_directory_if_exists(path): if path_exists(path): shutil.rmtree(path)
def _check_template_path_and_raise_error_if_does_not_exist(path): if not path_exists(path): raise PackageError("Package template could not be found.") return path
def _get_m_file_from_root(mesh): if path_exists(mesh): return mesh elif path_exists('/' + mesh): return '/' + mesh
def test_create_file(): create_file(TEMP_FILE_WITH_CONTENT, TEMP_FILE_CONTENT) assert path_exists(TEMP_FILE_WITH_CONTENT) is True assert read_file(TEMP_FILE_WITH_CONTENT) == TEMP_FILE_CONTENT
def get_user_dir(): user_dir = "/home/ros/user_data/" + session['user_container_name'] if not path_exists(user_dir): app.logger.info("Creating user directory at " + user_dir) create_directories_from_path(user_dir) return user_dir
def _create_parent_dir(dst): parent = get_parent_dir_name(dst) if not path_exists(parent): create_directories_from_path(parent)
def create_temp_dir(): if path_exists( TEMP_DIR ): # for the case that due to debugging errors teardown wasn't executed rm_nonempty_dir(TEMP_DIR) mk_dir(TEMP_DIR)
def _repository_exists(repo_name): path_exists(repo_name)
def update_meshes(): if path_exists(ROS_MESH_DATA_DIR): thread.start_new_thread(_update_meshes_run, ())
def test_path_exists(): assert path_exists(EXISTING_PATH) is True
def test_path_does_not_exist(): assert path_exists(NOT_EXISTING_PATH) is False
def _create_parent_dir(dst): parent = get_parent_dir_name(dst) if not path_exists(parent): make_dirs(parent)
def test_remove_existing_file(): remove_file(EMPTY_TEMP_FILE) assert path_exists(EMPTY_TEMP_FILE) is False
def test_create_parent_dir(): # run twice, to see if errors are thrown if parent directory already exists for x in xrange(2): _create_parent_dir(BUILD_DESTINATION) assert path_exists(PARENT_DIR) is True