Skip to content
Extraits de code Groupes Projets
Valider d4343e0b rédigé par Patrick Watrin's avatar Patrick Watrin
Parcourir les fichiers

IO unit test

parent adf344c8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
/* /*
* NOTE: some parts of this file are an adaptation of the 'fr_umlv_unitex_jni_UnitexJni.cpp' file * NOTE: some parts of this file are an adaptation of the 'fr_umlv_unitex_jni_UnitexJni.cpp' file
* which is included in the Unitex source distribution. * which is included in the Unitex source distribution.
*
*/ */
#include <Python.h> #include <Python.h>
...@@ -25,7 +26,7 @@ static char unitex_docstring[] = ...@@ -25,7 +26,7 @@ static char unitex_docstring[] =
* UNITEX TOOL FUNCTION * * UNITEX TOOL FUNCTION *
************************/ ************************/
/* 'unitex_tool' function*/ /* 'unitex_tool' function */
static char unitex_tool_docstring[] = static char unitex_tool_docstring[] =
"This function launches an Unitex command."; "This function launches an Unitex command.";
static PyObject *unitex_tool(PyObject *self, PyObject *args); static PyObject *unitex_tool(PyObject *self, PyObject *args);
...@@ -47,7 +48,7 @@ PyObject *unitex_tool(PyObject *self, PyObject *args) { ...@@ -47,7 +48,7 @@ PyObject *unitex_tool(PyObject *self, PyObject *args) {
* PERSISTENCE FUNCTIONS * * PERSISTENCE FUNCTIONS *
*************************/ *************************/
/*'unitex_load_persistent_dictionary' function*/ /* 'unitex_load_persistent_dictionary' function */
static char unitex_load_persistent_dictionary_docstring[] = static char unitex_load_persistent_dictionary_docstring[] =
"This function loads a dictionary in the persistent space."; "This function loads a dictionary in the persistent space.";
static PyObject *unitex_load_persistent_dictionary(PyObject *self, PyObject *args); static PyObject *unitex_load_persistent_dictionary(PyObject *self, PyObject *args);
...@@ -73,7 +74,7 @@ PyObject *unitex_load_persistent_dictionary(PyObject *self, PyObject *args) { ...@@ -73,7 +74,7 @@ PyObject *unitex_load_persistent_dictionary(PyObject *self, PyObject *args) {
return result; return result;
} }
/*'unitex_load_persistent_fst2' function*/ /* 'unitex_load_persistent_fst2' function */
static char unitex_load_persistent_fst2_docstring[] = static char unitex_load_persistent_fst2_docstring[] =
"This function loads a fst2 in the persistent space."; "This function loads a fst2 in the persistent space.";
static PyObject *unitex_load_persistent_fst2(PyObject *self, PyObject *args); static PyObject *unitex_load_persistent_fst2(PyObject *self, PyObject *args);
...@@ -99,7 +100,7 @@ PyObject *unitex_load_persistent_fst2(PyObject *self, PyObject *args) { ...@@ -99,7 +100,7 @@ PyObject *unitex_load_persistent_fst2(PyObject *self, PyObject *args) {
return result; return result;
} }
/*'unitex_load_persistent_alphabet' function*/ /* 'unitex_load_persistent_alphabet' function */
static char unitex_load_persistent_alphabet_docstring[] = static char unitex_load_persistent_alphabet_docstring[] =
"This function loads an alphabet in the persistent space."; "This function loads an alphabet in the persistent space.";
static PyObject *unitex_load_persistent_alphabet(PyObject *self, PyObject *args); static PyObject *unitex_load_persistent_alphabet(PyObject *self, PyObject *args);
...@@ -127,7 +128,7 @@ PyObject *unitex_load_persistent_alphabet(PyObject *self, PyObject *args) { ...@@ -127,7 +128,7 @@ PyObject *unitex_load_persistent_alphabet(PyObject *self, PyObject *args) {
/*'unitex_free_persistent_dictionary' function*/ /* 'unitex_free_persistent_dictionary' function */
static char unitex_free_persistent_dictionary_docstring[] = static char unitex_free_persistent_dictionary_docstring[] =
"This function removes a dictionary from the persistent space."; "This function removes a dictionary from the persistent space.";
static PyObject *unitex_free_persistent_dictionary(PyObject *self, PyObject *args); static PyObject *unitex_free_persistent_dictionary(PyObject *self, PyObject *args);
...@@ -142,7 +143,7 @@ PyObject *unitex_free_persistent_dictionary(PyObject *self, PyObject *args) { ...@@ -142,7 +143,7 @@ PyObject *unitex_free_persistent_dictionary(PyObject *self, PyObject *args) {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
/*'unitex_free_persistent_fst2' function*/ /* 'unitex_free_persistent_fst2' function */
static char unitex_free_persistent_fst2_docstring[] = static char unitex_free_persistent_fst2_docstring[] =
"This function removes a fst2 from the persistent space."; "This function removes a fst2 from the persistent space.";
static PyObject *unitex_free_persistent_fst2(PyObject *self, PyObject *args); static PyObject *unitex_free_persistent_fst2(PyObject *self, PyObject *args);
...@@ -157,7 +158,7 @@ PyObject *unitex_free_persistent_fst2(PyObject *self, PyObject *args) { ...@@ -157,7 +158,7 @@ PyObject *unitex_free_persistent_fst2(PyObject *self, PyObject *args) {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
/*'unitex_free_persistent_alphabet' function*/ /* 'unitex_free_persistent_alphabet' function */
static char unitex_free_persistent_alphabet_docstring[] = static char unitex_free_persistent_alphabet_docstring[] =
"This function removes an alphabet from the persistent space."; "This function removes an alphabet from the persistent space.";
static PyObject *unitex_free_persistent_alphabet(PyObject *self, PyObject *args); static PyObject *unitex_free_persistent_alphabet(PyObject *self, PyObject *args);
...@@ -174,7 +175,7 @@ PyObject *unitex_free_persistent_alphabet(PyObject *self, PyObject *args) { ...@@ -174,7 +175,7 @@ PyObject *unitex_free_persistent_alphabet(PyObject *self, PyObject *args) {
/*'unitex_is_persistent_dictionary' function*/ /* 'unitex_is_persistent_dictionary' function */
static char unitex_is_persistent_dictionary_docstring[] = static char unitex_is_persistent_dictionary_docstring[] =
"This function checks if a dictionary is in the persistent space."; "This function checks if a dictionary is in the persistent space.";
static PyObject *unitex_is_persistent_dictionary(PyObject *self, PyObject *args); static PyObject *unitex_is_persistent_dictionary(PyObject *self, PyObject *args);
...@@ -190,7 +191,7 @@ PyObject *unitex_is_persistent_dictionary(PyObject *self, PyObject *args) { ...@@ -190,7 +191,7 @@ PyObject *unitex_is_persistent_dictionary(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ret ? Py_True: Py_False); return Py_BuildValue("O", ret ? Py_True: Py_False);
} }
/*'unitex_is_persistent_fst2' function*/ /* 'unitex_is_persistent_fst2' function */
static char unitex_is_persistent_fst2_docstring[] = static char unitex_is_persistent_fst2_docstring[] =
"This function checks if a fst2 is in the persistent space."; "This function checks if a fst2 is in the persistent space.";
static PyObject *unitex_is_persistent_fst2(PyObject *self, PyObject *args); static PyObject *unitex_is_persistent_fst2(PyObject *self, PyObject *args);
...@@ -206,7 +207,7 @@ PyObject *unitex_is_persistent_fst2(PyObject *self, PyObject *args) { ...@@ -206,7 +207,7 @@ PyObject *unitex_is_persistent_fst2(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ret ? Py_True: Py_False); return Py_BuildValue("O", ret ? Py_True: Py_False);
} }
/*'unitex_is_persistent_alphabet' function*/ /* 'unitex_is_persistent_alphabet' function */
static char unitex_is_persistent_alphabet_docstring[] = static char unitex_is_persistent_alphabet_docstring[] =
"This function checks if an alphabet is in the persistent space."; "This function checks if an alphabet is in the persistent space.";
static PyObject *unitex_is_persistent_alphabet(PyObject *self, PyObject *args); static PyObject *unitex_is_persistent_alphabet(PyObject *self, PyObject *args);
...@@ -228,7 +229,7 @@ PyObject *unitex_is_persistent_alphabet(PyObject *self, PyObject *args) { ...@@ -228,7 +229,7 @@ PyObject *unitex_is_persistent_alphabet(PyObject *self, PyObject *args) {
* I/O FUNCTIONS * * I/O FUNCTIONS *
*****************/ *****************/
/* 'unitex_enable_stdout' function*/ /* 'unitex_enable_stdout' function */
static char unitex_enable_stdout_docstring[] = static char unitex_enable_stdout_docstring[] =
"This function enable the standard output."; "This function enable the standard output.";
static PyObject *unitex_enable_stdout(PyObject *self, PyObject *noarg); static PyObject *unitex_enable_stdout(PyObject *self, PyObject *noarg);
...@@ -242,7 +243,7 @@ PyObject *unitex_enable_stdout(PyObject *self, PyObject *noarg) { ...@@ -242,7 +243,7 @@ PyObject *unitex_enable_stdout(PyObject *self, PyObject *noarg) {
return Py_BuildValue("O", ret ? Py_True: Py_False); return Py_BuildValue("O", ret ? Py_True: Py_False);
} }
/* 'unitex_enable_stderr' function*/ /* 'unitex_enable_stderr' function */
static char unitex_enable_stderr_docstring[] = static char unitex_enable_stderr_docstring[] =
"This function enable the error output."; "This function enable the error output.";
static PyObject *unitex_enable_stderr(PyObject *self, PyObject *noarg); static PyObject *unitex_enable_stderr(PyObject *self, PyObject *noarg);
...@@ -256,7 +257,7 @@ PyObject *unitex_enable_stderr(PyObject *self, PyObject *noarg) { ...@@ -256,7 +257,7 @@ PyObject *unitex_enable_stderr(PyObject *self, PyObject *noarg) {
return Py_BuildValue("O", ret ? Py_True: Py_False); return Py_BuildValue("O", ret ? Py_True: Py_False);
} }
/* 'unitex_disable_stdout' function*/ /* 'unitex_disable_stdout' function */
static char unitex_disable_stdout_docstring[] = static char unitex_disable_stdout_docstring[] =
"This function disable the standard output."; "This function disable the standard output.";
static PyObject *unitex_disable_stdout(PyObject *self, PyObject *noarg); static PyObject *unitex_disable_stdout(PyObject *self, PyObject *noarg);
...@@ -270,7 +271,7 @@ PyObject *unitex_disable_stdout(PyObject *self, PyObject *noarg) { ...@@ -270,7 +271,7 @@ PyObject *unitex_disable_stdout(PyObject *self, PyObject *noarg) {
return Py_BuildValue("O", ret ? Py_True: Py_False); return Py_BuildValue("O", ret ? Py_True: Py_False);
} }
/* 'unitex_disable_stderr' function*/ /* 'unitex_disable_stderr' function */
static char unitex_disable_stderr_docstring[] = static char unitex_disable_stderr_docstring[] =
"This function disable the error output."; "This function disable the error output.";
static PyObject *unitex_disable_stderr(PyObject *self, PyObject *noarg); static PyObject *unitex_disable_stderr(PyObject *self, PyObject *noarg);
...@@ -284,7 +285,7 @@ PyObject *unitex_disable_stderr(PyObject *self, PyObject *noarg) { ...@@ -284,7 +285,7 @@ PyObject *unitex_disable_stderr(PyObject *self, PyObject *noarg) {
return Py_BuildValue("O", ret ? Py_True: Py_False); return Py_BuildValue("O", ret ? Py_True: Py_False);
} }
/* 'unitex_cp' function*/ /* 'unitex_cp' function */
static char unitex_cp_docstring[] = static char unitex_cp_docstring[] =
"This function copies a file to the (virtual) filesystem."; "This function copies a file to the (virtual) filesystem.";
static PyObject *unitex_cp(PyObject *self, PyObject *args); static PyObject *unitex_cp(PyObject *self, PyObject *args);
...@@ -301,7 +302,7 @@ PyObject *unitex_cp(PyObject *self, PyObject *args) { ...@@ -301,7 +302,7 @@ PyObject *unitex_cp(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ret ? Py_False: Py_True); return Py_BuildValue("O", ret ? Py_False: Py_True);
} }
/* 'unitex_rm' function*/ /* 'unitex_rm' function */
static char unitex_rm_docstring[] = static char unitex_rm_docstring[] =
"This function removes a file from the (virtual) filesystem."; "This function removes a file from the (virtual) filesystem.";
static PyObject *unitex_rm(PyObject *self, PyObject *args); static PyObject *unitex_rm(PyObject *self, PyObject *args);
...@@ -317,7 +318,7 @@ PyObject *unitex_rm(PyObject *self, PyObject *args) { ...@@ -317,7 +318,7 @@ PyObject *unitex_rm(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ret ? Py_False: Py_True); return Py_BuildValue("O", ret ? Py_False: Py_True);
} }
/* 'unitex_mv' function*/ /* 'unitex_mv' function */
static char unitex_mv_docstring[] = static char unitex_mv_docstring[] =
"This function renames (and potentially moves) a (virtual) file."; "This function renames (and potentially moves) a (virtual) file.";
static PyObject *unitex_mv(PyObject *self, PyObject *args); static PyObject *unitex_mv(PyObject *self, PyObject *args);
...@@ -334,7 +335,7 @@ PyObject *unitex_mv(PyObject *self, PyObject *args) { ...@@ -334,7 +335,7 @@ PyObject *unitex_mv(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ret ? Py_False: Py_True); return Py_BuildValue("O", ret ? Py_False: Py_True);
} }
/* 'unitex_mkdir' function*/ /* 'unitex_mkdir' function */
static char unitex_mkdir_docstring[] = static char unitex_mkdir_docstring[] =
"This function creates a directory on the disk."; "This function creates a directory on the disk.";
static PyObject *unitex_mkdir(PyObject *self, PyObject *args); static PyObject *unitex_mkdir(PyObject *self, PyObject *args);
...@@ -350,7 +351,7 @@ PyObject *unitex_mkdir(PyObject *self, PyObject *args) { ...@@ -350,7 +351,7 @@ PyObject *unitex_mkdir(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ret ? Py_False: Py_True); return Py_BuildValue("O", ret ? Py_False: Py_True);
} }
/* 'unitex_rmdir' function*/ /* 'unitex_rmdir' function */
static char unitex_rmdir_docstring[] = static char unitex_rmdir_docstring[] =
"This function removes a directory from disk (and all its content)."; "This function removes a directory from disk (and all its content).";
static PyObject *unitex_rmdir(PyObject *self, PyObject *args); static PyObject *unitex_rmdir(PyObject *self, PyObject *args);
...@@ -366,9 +367,7 @@ PyObject *unitex_rmdir(PyObject *self, PyObject *args) { ...@@ -366,9 +367,7 @@ PyObject *unitex_rmdir(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ret ? Py_False: Py_True); return Py_BuildValue("O", ret ? Py_False: Py_True);
} }
/* 'unitex_ls' function /* 'unitex_ls' function */
* -> adapted from the function 'getFileList' developped
* by Gilles Vollant and distributed with Unitex */
static char unitex_ls_docstring[] = static char unitex_ls_docstring[] =
"This function list (disk or virtual) directory contents."; "This function list (disk or virtual) directory contents.";
static PyObject *unitex_ls(PyObject *self, PyObject *args); static PyObject *unitex_ls(PyObject *self, PyObject *args);
...@@ -402,9 +401,7 @@ PyObject *unitex_ls(PyObject *self, PyObject *args) { ...@@ -402,9 +401,7 @@ PyObject *unitex_ls(PyObject *self, PyObject *args) {
return file_list; return file_list;
} }
/* 'unitex_read_file' function (UTF-8 encoding only) /* 'unitex_read_file' function (UTF-8 encoding only)*/
* -> adapted from the function 'getUnitexFileString' developped
* by Gilles Vollant and distributed with Unitex */
static char unitex_read_file_docstring[] = static char unitex_read_file_docstring[] =
"This function read a (virtual) file."; "This function read a (virtual) file.";
static PyObject *unitex_read_file(PyObject *self, PyObject *args); static PyObject *unitex_read_file(PyObject *self, PyObject *args);
...@@ -442,9 +439,7 @@ PyObject *unitex_read_file(PyObject *self, PyObject *args) { ...@@ -442,9 +439,7 @@ PyObject *unitex_read_file(PyObject *self, PyObject *args) {
return content; return content;
} }
/* 'unitex_write_file' function (UTF-8 encoding only) /* 'unitex_write_file' function (UTF-8 encoding only)*/
* -> adapted from the function 'doWriteUnitexFileUtf' developped
* by Gilles Vollant and distributed with Unitex */
static char unitex_write_file_docstring[] = static char unitex_write_file_docstring[] =
"This function write a (virtual) file."; "This function write a (virtual) file.";
static PyObject *unitex_write_file(PyObject *self, PyObject *args); static PyObject *unitex_write_file(PyObject *self, PyObject *args);
...@@ -464,7 +459,7 @@ PyObject *unitex_write_file(PyObject *self, PyObject *args) { ...@@ -464,7 +459,7 @@ PyObject *unitex_write_file(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ret ? Py_False: Py_True); return Py_BuildValue("O", ret ? Py_False: Py_True);
} }
/* 'unitex_append_to_file' function*/ /* 'unitex_append_to_file' function */
static char unitex_append_to_file_docstring[] = static char unitex_append_to_file_docstring[] =
"This function append_to a (virtual) file."; "This function append_to a (virtual) file.";
static PyObject *unitex_append_to_file(PyObject *self, PyObject *args); static PyObject *unitex_append_to_file(PyObject *self, PyObject *args);
...@@ -484,10 +479,10 @@ PyObject *unitex_append_to_file(PyObject *self, PyObject *args) { ...@@ -484,10 +479,10 @@ PyObject *unitex_append_to_file(PyObject *self, PyObject *args) {
static PyMethodDef unitex_methods[] = { static PyMethodDef unitex_methods[] = {
/*Unitex Tool function*/ /* Unitex Tool function */
{"unitex_tool", unitex_tool, METH_VARARGS, unitex_tool_docstring}, {"unitex_tool", unitex_tool, METH_VARARGS, unitex_tool_docstring},
/*Persistence functions*/ /* Persistence functions */
{"unitex_load_persistent_dictionary", unitex_load_persistent_dictionary, METH_VARARGS, unitex_load_persistent_dictionary_docstring}, {"unitex_load_persistent_dictionary", unitex_load_persistent_dictionary, METH_VARARGS, unitex_load_persistent_dictionary_docstring},
{"unitex_load_persistent_fst2", unitex_load_persistent_fst2, METH_VARARGS, unitex_load_persistent_fst2_docstring}, {"unitex_load_persistent_fst2", unitex_load_persistent_fst2, METH_VARARGS, unitex_load_persistent_fst2_docstring},
{"unitex_load_persistent_alphabet", unitex_load_persistent_alphabet, METH_VARARGS, unitex_load_persistent_alphabet_docstring}, {"unitex_load_persistent_alphabet", unitex_load_persistent_alphabet, METH_VARARGS, unitex_load_persistent_alphabet_docstring},
...@@ -500,7 +495,7 @@ static PyMethodDef unitex_methods[] = { ...@@ -500,7 +495,7 @@ static PyMethodDef unitex_methods[] = {
{"unitex_is_persistent_fst2", unitex_is_persistent_fst2, METH_VARARGS, unitex_is_persistent_fst2_docstring}, {"unitex_is_persistent_fst2", unitex_is_persistent_fst2, METH_VARARGS, unitex_is_persistent_fst2_docstring},
{"unitex_is_persistent_alphabet", unitex_is_persistent_alphabet, METH_VARARGS, unitex_is_persistent_alphabet_docstring}, {"unitex_is_persistent_alphabet", unitex_is_persistent_alphabet, METH_VARARGS, unitex_is_persistent_alphabet_docstring},
/*I/O functions*/ /* I/O functions */
{"unitex_enable_stdout", unitex_enable_stdout, METH_NOARGS, unitex_enable_stdout_docstring}, {"unitex_enable_stdout", unitex_enable_stdout, METH_NOARGS, unitex_enable_stdout_docstring},
{"unitex_disable_stdout", unitex_disable_stdout, METH_NOARGS, unitex_disable_stdout_docstring}, {"unitex_disable_stdout", unitex_disable_stdout, METH_NOARGS, unitex_disable_stdout_docstring},
{"unitex_enable_stderr", unitex_enable_stderr, METH_NOARGS, unitex_enable_stderr_docstring}, {"unitex_enable_stderr", unitex_enable_stderr, METH_NOARGS, unitex_enable_stderr_docstring},
......
...@@ -8,28 +8,28 @@ from unitex.tools import compress ...@@ -8,28 +8,28 @@ from unitex.tools import compress
class Values: class Arguments:
def __init__(self, language=None): def __init__(self, language=None):
self.__values = {} self.__arguments = {}
self.__values["dic"] = "data/dictionary.dic" self.__arguments["dic"] = "data/dictionary.dic"
self.__values["bin"] = "data/dictionary.bin" self.__arguments["bin"] = "data/dictionary.bin"
self.__values["inf"] = "data/dictionary.inf" self.__arguments["inf"] = "data/dictionary.inf"
self.__values["fst2"] = "data/Sentence.fst2" self.__arguments["fst2"] = "data/Sentence.fst2"
self.__values["alphabet"] = "data/Alphabet.txt" self.__arguments["alphabet"] = "data/Alphabet.txt"
def __getitem__(self, key): def __getitem__(self, key):
if key not in self.__values: if key not in self.__arguments:
raise KeyError("Value key '%s' not found..." % key) raise KeyError("Value key '%s' not found..." % key)
return self.__values[key] return self.__arguments[key]
def __setitem__(self, key, value): def __setitem__(self, key, value):
if key in self.__values: if key in self.__arguments:
raise KeyError("Value key '%s' already exists" % key) raise KeyError("Value key '%s' already exists" % key)
self.__values[key] = value self.__arguments[key] = value
...@@ -37,18 +37,18 @@ class TestUnitexResources(unittest.TestCase): ...@@ -37,18 +37,18 @@ class TestUnitexResources(unittest.TestCase):
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
self._values = Values() self._arguments = Arguments()
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(self):
# Removing output file from the 'compress' command. # Removing output file from the 'compress' command.
if os.path.exists(self._values["bin"]): if os.path.exists(self._arguments["bin"]):
os.remove(self._values["bin"]) os.remove(self._arguments["bin"])
if os.path.exists(self._values["inf"]): if os.path.exists(self._arguments["inf"]):
os.remove(self._values["inf"]) os.remove(self._arguments["inf"])
def test_01_load_dictionary(self): def test_01_load_dictionary(self):
args = [self._values["dic"]] args = [self._arguments["dic"]]
kwargs = {} kwargs = {}
kwargs["flip"] = False kwargs["flip"] = False
...@@ -57,17 +57,17 @@ class TestUnitexResources(unittest.TestCase): ...@@ -57,17 +57,17 @@ class TestUnitexResources(unittest.TestCase):
ret = compress(*args, **kwargs) ret = compress(*args, **kwargs)
path = self._values["bin"] path = self._arguments["bin"]
output = load_persistent_dictionary(path) output = load_persistent_dictionary(path)
self._values["persistent-dictionary"] = output self._arguments["persistent-dictionary"] = output
ok = is_persistent_dictionary(output) ok = is_persistent_dictionary(output)
self.assertTrue(ok, "Dictionary loading failed!") self.assertTrue(ok, "Dictionary loading failed!")
def test_02_unload_dictionary(self): def test_02_unload_dictionary(self):
path = self._values["persistent-dictionary"] path = self._arguments["persistent-dictionary"]
free_persistent_dictionary(path) free_persistent_dictionary(path)
ok = not is_persistent_dictionary(path) ok = not is_persistent_dictionary(path)
...@@ -75,17 +75,17 @@ class TestUnitexResources(unittest.TestCase): ...@@ -75,17 +75,17 @@ class TestUnitexResources(unittest.TestCase):
self.assertTrue(ok, "Dictionary freeing failed!") self.assertTrue(ok, "Dictionary freeing failed!")
def test_03_load_fst2(self): def test_03_load_fst2(self):
path = self._values["fst2"] path = self._arguments["fst2"]
output = load_persistent_fst2(path) output = load_persistent_fst2(path)
self._values["persistent-fst2"] = output self._arguments["persistent-fst2"] = output
ok = is_persistent_fst2(output) ok = is_persistent_fst2(output)
self.assertTrue(ok, "Fst2 loading failed!") self.assertTrue(ok, "Fst2 loading failed!")
def test_04_unload_fst2(self): def test_04_unload_fst2(self):
path = self._values["persistent-fst2"] path = self._arguments["persistent-fst2"]
free_persistent_fst2(path) free_persistent_fst2(path)
ok = not is_persistent_fst2(path) ok = not is_persistent_fst2(path)
...@@ -93,17 +93,17 @@ class TestUnitexResources(unittest.TestCase): ...@@ -93,17 +93,17 @@ class TestUnitexResources(unittest.TestCase):
self.assertTrue(ok, "Fst2 freeing failed!") self.assertTrue(ok, "Fst2 freeing failed!")
def test_05_load_alphabet(self): def test_05_load_alphabet(self):
path = self._values["alphabet"] path = self._arguments["alphabet"]
output = load_persistent_alphabet(path) output = load_persistent_alphabet(path)
self._values["persistent-alphabet"] = output self._arguments["persistent-alphabet"] = output
ok = is_persistent_alphabet(output) ok = is_persistent_alphabet(output)
self.assertTrue(ok, "Alphabet loading failed!") self.assertTrue(ok, "Alphabet loading failed!")
def test_06_unload_alphabet(self): def test_06_unload_alphabet(self):
path = self._values["persistent-alphabet"] path = self._arguments["persistent-alphabet"]
free_persistent_alphabet(path) free_persistent_alphabet(path)
ok = not is_persistent_alphabet(path) ok = not is_persistent_alphabet(path)
......
...@@ -18,10 +18,14 @@ class Arguments: ...@@ -18,10 +18,14 @@ class Arguments:
self.__arguments["file_target_vfs_01"] = "%sdata/corpus-vfs-01.txt" % UnitexIOConstants.VFS_PREFIX self.__arguments["file_target_vfs_01"] = "%sdata/corpus-vfs-01.txt" % UnitexIOConstants.VFS_PREFIX
self.__arguments["file_target_vfs_02"] = "%sdata/corpus-vfs-02.txt" % UnitexIOConstants.VFS_PREFIX self.__arguments["file_target_vfs_02"] = "%sdata/corpus-vfs-02.txt" % UnitexIOConstants.VFS_PREFIX
self.__arguments["virtual_file_hdd_01"] = "data/corpus-virtual-file-01.txt" self.__arguments["hdd_root"] = "data/"
self.__arguments["virtual_file_hdd_02"] = "data/corpus-virtual-file-02.txt" self.__arguments["vfs_root"] = "%sdata/" % UnitexIOConstants.VFS_PREFIX
self.__arguments["virtual_file_vfs_01"] = "%sdata/corpus-virtual-file-01.txt" % UnitexIOConstants.VFS_PREFIX
self.__arguments["virtual_file_vfs_02"] = "%sdata/corpus-virtual-file-02.txt" % UnitexIOConstants.VFS_PREFIX self.__arguments["hdd_name"] = "corpus.txt"
self.__arguments["vfs_name"] = "$:data/unitex-file-corpus.txt"
self.__arguments["unitex_file_hdd"] = "data/unitex-file-corpus.txt"
self.__arguments["unitex_file_vfs"] = "%sdata/unitex-file-corpus.txt" % UnitexIOConstants.VFS_PREFIX
self.__arguments["directory"] = "data/biniou/" self.__arguments["directory"] = "data/biniou/"
...@@ -49,69 +53,223 @@ class TestUnitexIO(unittest.TestCase): ...@@ -49,69 +53,223 @@ class TestUnitexIO(unittest.TestCase):
if os.path.exists(self._arguments["directory"]): if os.path.exists(self._arguments["directory"]):
shutil.rmtree(self._arguments["directory"]) shutil.rmtree(self._arguments["directory"])
if os.path.exists(self._arguments["unitex_file_hdd"]):
os.remove(self._arguments["unitex_file_hdd"])
def test_01_enable_stdout(self): def test_01_enable_stdout(self):
ret = enable_stdout() ret = enable_stdout()
self.assertTrue(ok, "STDOUT enabling failed!") self.assertTrue(ret, "STDOUT enabling failed!")
def test_02_disable_stdout(self): def test_02_disable_stdout(self):
ret = disable_stdout() ret = disable_stdout()
self.assertTrue(ok, "STDOUT disabling failed!") self.assertTrue(ret, "STDOUT disabling failed!")
def test_03_enable_stderr(self): def test_03_enable_stderr(self):
ret = enable_stderr() ret = enable_stderr()
self.assertTrue(ok, "STDERR enabling failed!") self.assertTrue(ret, "STDERR enabling failed!")
def test_04_disable_stderr(self): def test_04_disable_stderr(self):
ret = disable_stderr() ret = disable_stderr()
self.assertTrue(ok, "STDERR disabling failed!") self.assertTrue(ret, "STDERR disabling failed!")
def test_05_01_cp_hdd(self): def test_05_01_cp_hdd(self):
raise NotImplementedError ret = cp(self._arguments["file_source"], self._arguments["file_target_hdd_01"])
ok = ret and os.path.exists(self._arguments["file_target_hdd_01"])
self.assertTrue(ok, "Copy to disk failed!")
def test_05_02_cp_vfs(self): def test_05_02_cp_vfs(self):
raise NotImplementedError ret = cp(self._arguments["file_source"], self._arguments["file_target_vfs_01"])
# Note that this check needs the 'ls' function working...
vfs_content = ls(self._arguments["vfs_root"])
ok = ret and self._arguments["file_target_vfs_01"] in vfs_content
self.assertTrue(ok, "Copy to VFS failed!")
def test_06_01_mv_hdd(self):
ret = mv(self._arguments["file_target_hdd_01"], self._arguments["file_target_hdd_02"])
ok = ret
ok = ok and not os.path.exists(self._arguments["file_target_hdd_01"])
ok = ok and os.path.exists(self._arguments["file_target_hdd_02"])
self.assertTrue(ok, "Move from/to disk failed!")
def test_06_02_mv_vfs(self):
ret = mv(self._arguments["file_target_vfs_01"], self._arguments["file_target_vfs_02"])
# Note that this check needs the 'ls' function working...
vfs_content = ls(self._arguments["vfs_root"])
ok = ret
ok = ok and not self._arguments["file_target_vfs_01"] in vfs_content
ok = ok and self._arguments["file_target_vfs_02"] in vfs_content
def test_06_01_rm_hdd(self): self.assertTrue(ok, "Move from/to VFS failed!")
raise NotImplementedError
def test_06_02_rm_vfs(self): def test_07_01_rm_hdd(self):
raise NotImplementedError ret = rm(self._arguments["file_target_hdd_02"])
def test_07_01_mv_hdd(self): ok = ret
raise NotImplementedError ok = ok and not os.path.exists(self._arguments["file_target_hdd_02"])
def test_07_02_mv_vfs(self): self.assertTrue(ok, "Remove from disk failed!")
raise NotImplementedError
def test_07_02_rm_vfs(self):
ret = rm(self._arguments["file_target_vfs_02"])
# Note that this check needs the 'ls' function working...
vfs_content = ls(self._arguments["vfs_root"])
ok = ret
ok = ok and not self._arguments["file_target_vfs_02"] in vfs_content
self.assertTrue(ok, "Remove from disk failed!")
def test_08_mkdir(self): def test_08_mkdir(self):
raise NotImplementedError ret = mkdir(self._arguments["directory"])
ok = ret and os.path.exists(self._arguments["directory"])
self.assertTrue(ok, "Make disk directory failed!")
def test_09_rmdir(self): def test_09_rmdir(self):
raise NotImplementedError ret = rmdir(self._arguments["directory"])
ok = ret and not os.path.exists(self._arguments["directory"])
self.assertTrue(ok, "Remove disk directory failed!")
def test_10_ls_hdd(self): def test_10_ls_hdd(self):
raise NotImplementedError hdd_content = ls(self._arguments["hdd_root"])
ok = self._arguments["hdd_name"] in hdd_content
self.assertTrue(ok, "Listing disk directory failed!")
def test_10_ls_vfs(self): def test_10_ls_vfs(self):
raise NotImplementedError ret = cp(self._arguments["file_source"], self._arguments["unitex_file_vfs"])
vfs_content = ls(self._arguments["vfs_root"])
ret = rm(self._arguments["unitex_file_vfs"])
ok = self._arguments["vfs_name"] in vfs_content
self.assertTrue(ok, "Listing VFS directory failed!")
def test_11_01_01_unitex_file_read_hdd(self):
rf = open(self._arguments["file_source"], "r", encoding="utf-8")
original = rf.read()
rf.close()
uf = UnitexFile()
uf.open(self._arguments["file_source"], "r")
content = uf.read()
uf.close()
ok = original == content
self.assertTrue(ok, "UnitexFile disk read failed!")
def test_11_01_02_unitex_file_read_vfs(self):
rf = open(self._arguments["file_source"], "r", encoding="utf-8")
original = rf.read()
rf.close()
ret = cp(self._arguments["file_source"], self._arguments["unitex_file_vfs"])
uf = UnitexFile()
uf.open(self._arguments["unitex_file_vfs"], "r")
content = uf.read()
uf.close()
ret = rm(self._arguments["unitex_file_vfs"])
ok = original == content
self.assertTrue(ok, "UnitexFile VFS read failed!")
def test_11_02_01_unitex_file_write_hdd(self):
rf = open(self._arguments["file_source"], "r", encoding="utf-8")
original = rf.read()
rf.close()
uf = UnitexFile()
uf.open(self._arguments["unitex_file_hdd"], "w")
uf.write(original)
uf.close()
uf = UnitexFile()
uf.open(self._arguments["unitex_file_hdd"], "r")
content = uf.read()
uf.close()
ok = original == content
self.assertTrue(ok, "UnitexFile disk write failed!")
def test_11_02_02_unitex_file_write_vfs(self):
rf = open(self._arguments["file_source"], "r", encoding="utf-8")
original = rf.read()
rf.close()
uf = UnitexFile()
uf.open(self._arguments["unitex_file_vfs"], "w")
uf.write(original)
uf.close()
uf = UnitexFile()
uf.open(self._arguments["unitex_file_vfs"], "r")
content = uf.read()
uf.close()
ok = original == content
self.assertTrue(ok, "UnitexFile VFS write failed!")
def test_11_03_01_unitex_file_append_hdd(self):
rf = open(self._arguments["file_source"], "r", encoding="utf-8")
original = rf.read()
rf.close()
uf = UnitexFile()
uf.open(self._arguments["unitex_file_hdd"], "a")
uf.write(original)
uf.close()
uf = UnitexFile()
uf.open(self._arguments["unitex_file_hdd"], "r")
content = uf.read()
uf.close()
ok = (original+original) == content
self.assertTrue(ok, "UnitexFile disk append failed!")
def test_11_01_01_virtual_file_read_hdd(self): def test_11_03_02_unitex_file_append_vfs(self):
raise NotImplementedError rf = open(self._arguments["file_source"], "r", encoding="utf-8")
original = rf.read()
rf.close()
def test_11_01_02_virtual_file_read_vfs(self): uf = UnitexFile()
raise NotImplementedError uf.open(self._arguments["unitex_file_vfs"], "a")
uf.write(original)
uf.close()
def test_11_02_01_virtual_file_write_hdd(self): uf = UnitexFile()
raise NotImplementedError uf.open(self._arguments["unitex_file_vfs"], "r")
content = uf.read()
uf.close()
def test_11_02_02_virtual_file_write_vfs(self): ret = rm(self._arguments["unitex_file_vfs"])
raise NotImplementedError
def test_11_03_01_virtual_file_append_hdd(self): ok = (original+original) == content
raise NotImplementedError
def test_11_03_02_virtual_file_append_vfs(self): self.assertTrue(ok, "UnitexFile VFS append failed!")
raise NotImplementedError
......
...@@ -183,12 +183,16 @@ class UnitexFile(object): ...@@ -183,12 +183,16 @@ class UnitexFile(object):
""" """
def __init__(self): def __init__(self):
self.__use_bom = None
self.__file = None self.__file = None
self.__mode = None self.__mode = None
def open(self, file, mode=None): def open(self, file, mode=None, use_bom=False):
if self.__file is not None: if self.__file is not None:
raise UnitexException("You must close the current file (%s) before open another one..." % self.__file) raise UnitexException("You must close the current file (%s) before open another one..." % self.__file)
self.__use_bom = use_bom
self.__file = file self.__file = file
self.__mode = mode self.__mode = mode
...@@ -205,7 +209,8 @@ class UnitexFile(object): ...@@ -205,7 +209,8 @@ class UnitexFile(object):
raise UnitexException("You must open a file before writing...") raise UnitexException("You must open a file before writing...")
if self.__mode == "w": if self.__mode == "w":
unitex_write_file(self.__file, data, 1) bom = 1 if self.__use_bom is True else 0
unitex_write_file(self.__file, data, bom)
else: else:
unitex_append_to_file(self.__file, data) unitex_append_to_file(self.__file, data)
......
...@@ -1071,7 +1071,7 @@ def txt2tfst(*args, **kwargs): ...@@ -1071,7 +1071,7 @@ def txt2tfst(*args, **kwargs):
Another file named text.tind is also produced. Another file named text.tind is also produced.
Arguments (length: 1): Arguments (length: 1):
0 -- the full path to the text file in snt format. 0 -- the path to the text file in snt format.
Keyword arguments: Keyword arguments:
alphabet [str] -- the alphabet file of the language of the text alphabet [str] -- the alphabet file of the language of the text
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter