Exemplo n.º 1
0
    def test_dir_exists(self):
        # for existing dir returns true
        existing_test_dir = self.TEST_DATA_DIR + '/lollyhelpers'
        assert lolly_helpers.dir_exists(existing_test_dir)

        # for existing file returns false
        existing_test_file = self.TEST_DATA_DIR + '/lollyhelpers/existing_test_file.txt'
        assert not lolly_helpers.dir_exists(existing_test_file)
Exemplo n.º 2
0
 def test_silent_move_dir(self):
     self.__create_test_dir_if_not_exists()
     dest = self.TMP_DIR + '/moved'
     # sad path
     bad_origin = self.TMP_DIR + '/non_existent'
     assert lolly_helpers.silent_move_dir(bad_origin, dest)['error']
     # happy path
     origin = self.TMP_DIR + '/move_origin'
     lolly_helpers.silent_create_path(origin)
     assert not lolly_helpers.silent_move_dir(origin, dest)['error']
     assert not lolly_helpers.dir_exists(origin)
     assert lolly_helpers.dir_exists(dest)
Exemplo n.º 3
0
    def test_silent_remove_dir(self):
        self.__create_test_dir_if_not_exists()
        # sad path can't be easily tested

        # happy path
        non_existent_dir = self.TMP_DIR + '/non_existent_dir'
        assert not lolly_helpers.silent_remove_dir(non_existent_dir)['error']
        existent_dir = self.TMP_DIR + '/existent'
        lolly_helpers.silent_create_path(existent_dir)
        assert lolly_helpers.dir_exists(existent_dir)
        assert not lolly_helpers.silent_remove_dir(existent_dir)['error']
        assert not lolly_helpers.dir_exists(existent_dir)
Exemplo n.º 4
0
    def _execute_inst(self, i):
        """
        Instantiates single template file
        :param i: string list
        :return: None
        """
        # append src and dest root parts to names (must be done once)
        if not self._is_instr_file_parsed:
            i['args'][0] = self.src_root_dir + self.PATH_DELIMITER_CHAR + i['args'][0]
            i['args'][1] = self.dest_root_dir + self.PATH_DELIMITER_CHAR + i['args'][1]

        src_filename = i['args'][0]
        dest_filename = i['args'][1]
        split_df = lolly_helpers.path_base_and_leaf(dest_filename)
        contents = lolly_helpers.silent_read_text_file(src_filename)
        if contents['error']:
            self._report_file_operation_error("can't read file '" + src_filename + "'.")
            return
        # process conditions
        contents = self._process_conditional_directives(contents['contents'], src_filename)
        contents = lolly_helpers.replace_keys(contents, self.replacement_dict)
        # make sure dest directory exists
        lolly_helpers.silent_create_path(split_df['base'])
        if not lolly_helpers.dir_exists(split_df['base']):
            self._report_file_operation_error("can't create folder: '" + split_df['base'] + "'")
            return
        lolly_helpers.silent_write_text_file(dest_filename, contents)
        if not lolly_helpers.file_exists(dest_filename):
            self._report_file_operation_error("can't write file: '" + dest_filename +
                                              "'")
            return
Exemplo n.º 5
0
    def test_execute_remove(self):
        self.__create_test_dir_if_not_exists()
        src_dir = self.TEST_DATA_DIR + '/lollywiz/generic_tests'
        dest_dir = self.TMP_DIR
        wiz = LollyWiz(src_dir, dest_dir)

        test_dir = dest_dir + '/test_dir'
        lolly_helpers.silent_create_path(test_dir)
        assert lolly_helpers.dir_exists(test_dir)

        wiz._instr_file_full_path = 'dummy_test_data'
        # override original instruction file with test data
        wiz._is_instr_file_read = True
        wiz._instr_file_data = "LOLLYWIZ_TEXTFILE_VERSION = 0.1.0\n" \
                               "#instructions_begin\n" \
                               "remove 'test_dir'\n" \
                               "#instructions_end\n"
        wiz.instantiate()
        assert not lolly_helpers.dir_exists(test_dir)
Exemplo n.º 6
0
    def test_silent_create_path(self):
        # sad path can't be easily tested because python replaces illegal characters in file names with legal
        # some_wrong_path = self.TMP_DIR + "/:::"
        # assert lollyhelpers.silent_create_path(some_wrong_path)['error']

        # happy path
        path = self.TMP_DIR + '/some/test/directory'
        assert not lolly_helpers.silent_create_path(path)['error']
        assert lolly_helpers.dir_exists(path)
        # create a file inside that directory
        filepath = path + '/testfile.txt'
        lolly_helpers.silent_write_text_file(filepath, 'TEST')
Exemplo n.º 7
0
 def set_src(self, src_dir):
     """
     Sets template source folder. 'src_dir' must exist and contain file lollywiz.txt.
     :param src_dir: string
     :return: None
     """
     self._is_src_dir_set = False
     self._is_instr_file_parsed = False
     self._clear_error()
     self.src_root_dir = src_dir
     self._instr_file_full_path = self.src_root_dir + self.PATH_DELIMITER_CHAR + self.INSTRUCTION_FILE_NAME
     src_root_dir_exists = lolly_helpers.dir_exists(self.src_root_dir)
     if not src_root_dir_exists:
         self._report_file_operation_error("template source directory '" + self.src_root_dir
                                           + "' does not exist")
     if not lolly_helpers.file_exists(self._instr_file_full_path):
         self._report_file_operation_error("instruction file '" + self._instr_file_full_path
                                           + "' does not exist")
         return
     self._is_src_dir_set = True
Exemplo n.º 8
0
 def __create_test_dir_if_not_exists(self):
     if not lolly_helpers.dir_exists(self.TMP_DIR):
         lolly_helpers.silent_create_path(self.TMP_DIR)
         # print("* temp test dir was created")
     if not lolly_helpers.dir_exists(self.TMP_DIR):
         raise OSError("Test 'TestLollyhelpers' error: can't create temporary directory '" + self.TMP_DIR + "'")