aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authordanila-eremin <danila-eremin@yandex-team.ru>2022-02-10 16:46:21 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:21 +0300
commit9d80afb43be16931e653a688c5e0f585101ff4f8 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util
parent358e631d1a69242d3ae4d6e6b1e4f7581d03133b (diff)
downloadydb-9d80afb43be16931e653a688c5e0f585101ff4f8.tar.gz
Restoring authorship annotation for <danila-eremin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/folder/path.pxd186
-rw-r--r--util/folder/path_ut.pyx758
-rw-r--r--util/generic/deque.pxd18
-rw-r--r--util/generic/deque_ut.pyx132
-rw-r--r--util/generic/hash.pxd40
-rw-r--r--util/generic/hash_set_ut.pyx2
-rw-r--r--util/generic/hash_ut.pyx4
-rw-r--r--util/generic/ptr.pxd24
-rw-r--r--util/generic/string.pxd4
-rw-r--r--util/generic/string_ut.pyx74
-rw-r--r--util/generic/vector_ut.pyx16
-rw-r--r--util/memory/blob.pxd82
-rw-r--r--util/memory/blob_ut.pyx282
-rw-r--r--util/stream/output.pxd24
-rw-r--r--util/stream/str.pxd24
-rw-r--r--util/stream/str_ut.pyx124
-rw-r--r--util/string/cast_ut.pyx4
-rw-r--r--util/tests/cython/test_folder.py24
-rw-r--r--util/tests/cython/test_generic.py14
-rw-r--r--util/tests/cython/test_memory.py24
-rw-r--r--util/tests/cython/test_stream.py24
-rw-r--r--util/tests/cython/ya.make18
22 files changed, 951 insertions, 951 deletions
diff --git a/util/folder/path.pxd b/util/folder/path.pxd
index 9a60cd8874..85af10d746 100644
--- a/util/folder/path.pxd
+++ b/util/folder/path.pxd
@@ -1,93 +1,93 @@
-from util.generic.string cimport TString, TStringBuf
-from util.generic.vector cimport TVector
-
-
-# NOTE (danila-eremin) Currently not possible to use `const` and `except +` at the same time, so some function not marked const
-cdef extern from "util/folder/path.h" nogil:
- cdef cppclass TFsPath:
- TFsPath() except +
- TFsPath(const TString&) except +
- TFsPath(const TStringBuf) except +
- TFsPath(const char*) except +
-
- void CheckDefined() except +
-
- bint IsDefined() const
- bint operator bool() const
-
- const char* c_str() const
-
- bint operator==(const TFsPath&) const
- bint operator!=(const TFsPath&) const
-
- # NOTE (danila-eremin) operator `/=` Not supported
- # TFsPath& operator/=(const TFsPath&) const
-
- TFsPath operator/(const TFsPath&, const TFsPath&) except +
-
- # NOTE (danila-eremin) TPathSplit needed
- # const TPathSplit& PathSplit() const
-
- TFsPath& Fix() except +
-
- const TString& GetPath() const
- TString GetName() const
-
- TString GetExtension() const
-
- bint IsAbsolute() const
- bint IsRelative() const
-
- bint IsSubpathOf(const TFsPath&) const
- bint IsNonStrictSubpathOf(const TFsPath&) const
- bint IsContainerOf(const TFsPath&) const
-
- TFsPath RelativeTo(const TFsPath&) except +
- TFsPath RelativePath(const TFsPath&) except +
-
- TFsPath Parent() const
-
- TString Basename() const
- TString Dirname() const
-
- TFsPath Child(const TString&) except +
-
- void MkDir() except +
- void MkDir(const int) except +
- void MkDirs() except +
- void MkDirs(const int) except +
-
- void List(TVector[TFsPath]&) except +
- void ListNames(TVector[TString]&) except +
-
- bint Contains(const TString&) const
-
- void DeleteIfExists() except +
- void ForceDelete() except +
-
- # NOTE (danila-eremin) TFileStat needed
- # bint Stat(TFileStat&) const
-
- bint Exists() const
- bint IsDirectory() const
- bint IsFile() const
- bint IsSymlink() const
- void CheckExists() except +
-
- void RenameTo(const TString&) except +
- void RenameTo(const char*) except +
- void RenameTo(const TFsPath&) except +
- void ForceRenameTo(const TString&) except +
-
- void CopyTo(const TString&, bint) except +
-
- void Touch() except +
-
- TFsPath RealPath() except +
- TFsPath RealLocation() except +
- TFsPath ReadLink() except +
-
- @staticmethod
- TFsPath Cwd() except +
-
- void Swap(TFsPath&)
+from util.generic.string cimport TString, TStringBuf
+from util.generic.vector cimport TVector
+
+
+# NOTE (danila-eremin) Currently not possible to use `const` and `except +` at the same time, so some function not marked const
+cdef extern from "util/folder/path.h" nogil:
+ cdef cppclass TFsPath:
+ TFsPath() except +
+ TFsPath(const TString&) except +
+ TFsPath(const TStringBuf) except +
+ TFsPath(const char*) except +
+
+ void CheckDefined() except +
+
+ bint IsDefined() const
+ bint operator bool() const
+
+ const char* c_str() const
+
+ bint operator==(const TFsPath&) const
+ bint operator!=(const TFsPath&) const
+
+ # NOTE (danila-eremin) operator `/=` Not supported
+ # TFsPath& operator/=(const TFsPath&) const
+
+ TFsPath operator/(const TFsPath&, const TFsPath&) except +
+
+ # NOTE (danila-eremin) TPathSplit needed
+ # const TPathSplit& PathSplit() const
+
+ TFsPath& Fix() except +
+
+ const TString& GetPath() const
+ TString GetName() const
+
+ TString GetExtension() const
+
+ bint IsAbsolute() const
+ bint IsRelative() const
+
+ bint IsSubpathOf(const TFsPath&) const
+ bint IsNonStrictSubpathOf(const TFsPath&) const
+ bint IsContainerOf(const TFsPath&) const
+
+ TFsPath RelativeTo(const TFsPath&) except +
+ TFsPath RelativePath(const TFsPath&) except +
+
+ TFsPath Parent() const
+
+ TString Basename() const
+ TString Dirname() const
+
+ TFsPath Child(const TString&) except +
+
+ void MkDir() except +
+ void MkDir(const int) except +
+ void MkDirs() except +
+ void MkDirs(const int) except +
+
+ void List(TVector[TFsPath]&) except +
+ void ListNames(TVector[TString]&) except +
+
+ bint Contains(const TString&) const
+
+ void DeleteIfExists() except +
+ void ForceDelete() except +
+
+ # NOTE (danila-eremin) TFileStat needed
+ # bint Stat(TFileStat&) const
+
+ bint Exists() const
+ bint IsDirectory() const
+ bint IsFile() const
+ bint IsSymlink() const
+ void CheckExists() except +
+
+ void RenameTo(const TString&) except +
+ void RenameTo(const char*) except +
+ void RenameTo(const TFsPath&) except +
+ void ForceRenameTo(const TString&) except +
+
+ void CopyTo(const TString&, bint) except +
+
+ void Touch() except +
+
+ TFsPath RealPath() except +
+ TFsPath RealLocation() except +
+ TFsPath ReadLink() except +
+
+ @staticmethod
+ TFsPath Cwd() except +
+
+ void Swap(TFsPath&)
diff --git a/util/folder/path_ut.pyx b/util/folder/path_ut.pyx
index 7c1c376556..e2537683ee 100644
--- a/util/folder/path_ut.pyx
+++ b/util/folder/path_ut.pyx
@@ -1,379 +1,379 @@
-# cython: c_string_type=str, c_string_encoding=utf8
-
-from util.folder.path cimport TFsPath
-from util.generic.string cimport TString, TStringBuf
-from util.generic.vector cimport TVector
-
-import unittest
-import yatest.common
-
-import os.path
-
-
-class TestPath(unittest.TestCase):
- def test_ctor1(self):
- cdef TFsPath path = TFsPath()
- self.assertEqual(path.IsDefined(), False)
- self.assertEquals(path.c_str(), "")
-
- def test_ctor2(self):
- cdef TString str_path = "/a/b/c"
- cdef TFsPath path = TFsPath(str_path)
- self.assertEqual(path.IsDefined(), True)
- self.assertEquals(path.c_str(), "/a/b/c")
-
- def test_ctor3(self):
- cdef TStringBuf buf_path = "/a/b/c"
- cdef TFsPath path = TFsPath(buf_path)
- self.assertEqual(path.IsDefined(), True)
- self.assertEquals(path.c_str(), "/a/b/c")
-
- def test_ctor4(self):
- cdef char* char_path = "/a/b/c"
- cdef TFsPath path = TFsPath(char_path)
- self.assertEqual(path.IsDefined(), True)
- self.assertEquals(path.c_str(), "/a/b/c")
-
- def test_assignment(self):
- cdef TFsPath path1 = TFsPath("/a/b")
- cdef TFsPath path2 = TFsPath("/a/c")
-
- self.assertEquals(path1.GetPath(), "/a/b")
- self.assertEquals(path2.GetPath(), "/a/c")
-
- path2 = path1
-
- self.assertEquals(path1.GetPath(), "/a/b")
- self.assertEquals(path2.GetPath(), "/a/b")
-
- def test_check_defined(self):
- cdef TFsPath path1 = TFsPath()
- with self.assertRaises(RuntimeError):
- path1.CheckDefined()
- self.assertEqual(path1.IsDefined(), False)
- if path1:
- assert False
- else:
- pass
-
- cdef TFsPath path2 = TFsPath("")
- with self.assertRaises(RuntimeError):
- path2.CheckDefined()
- self.assertEqual(path2.IsDefined(), False)
- if path2:
- assert False
- else:
- pass
-
- cdef TFsPath path3 = TFsPath("/")
- path3.CheckDefined()
- self.assertEqual(path3.IsDefined(), True)
- if path3:
- pass
- else:
- assert False
-
- def test_comparison(self):
- cdef TFsPath path1 = TFsPath("/a/b")
- cdef TFsPath path2 = TFsPath("/a/c")
- cdef TFsPath path3 = TFsPath("/a/b")
-
- self.assertEqual(path1 == path3, True)
- self.assertEqual(path1 != path2, True)
- self.assertEqual(path3 != path2, True)
-
- def test_concatenation(self):
- cdef TFsPath path1 = TFsPath("/a")
- cdef TFsPath path2 = TFsPath("b")
- cdef TFsPath path3 = path1 / path2
- cdef TFsPath path4 = TFsPath("/a/b")
-
- self.assertEqual(path3 == path4, True)
-
- def test_fix(self):
- cdef TFsPath path = TFsPath("test_fix/b/c/../d")
- cdef TFsPath fixed = path.Fix()
- self.assertEquals(fixed.GetPath(), "test_fix/b/d")
-
- def test_parts(self):
- cdef TFsPath path = TFsPath("/a/b/c")
- self.assertEquals(path.GetPath(), "/a/b/c")
- self.assertEquals(path.GetName(), "c")
- self.assertEquals(path.GetExtension(), "")
- self.assertEquals(path.Basename(), "c")
- self.assertEquals(path.Dirname(), "/a/b")
-
- cdef TFsPath path_ext = TFsPath("/a/b/c.ext")
- self.assertEquals(path_ext.GetPath(), "/a/b/c.ext")
- self.assertEquals(path_ext.GetName(), "c.ext")
- self.assertEquals(path_ext.GetExtension(), "ext")
- self.assertEquals(path_ext.Basename(), "c.ext")
- self.assertEquals(path_ext.Dirname(), "/a/b")
-
- cdef TFsPath path_only_ext = TFsPath("/a/b/.ext")
- self.assertEquals(path_only_ext.GetPath(), "/a/b/.ext")
- self.assertEquals(path_only_ext.GetName(), ".ext")
- self.assertEquals(path_only_ext.GetExtension(), "")
- self.assertEquals(path_only_ext.Basename(), ".ext")
- self.assertEquals(path_only_ext.Dirname(), "/a/b")
-
- cdef TFsPath path_dir = TFsPath("/a/b/")
- self.assertEquals(path_dir.GetPath(), "/a/b/")
- self.assertEquals(path_dir.GetName(), "b")
- self.assertEquals(path_dir.GetExtension(), "")
- self.assertEquals(path_dir.Basename(), "b")
- self.assertEquals(path_dir.Dirname(), "/a")
-
- def test_absolute(self):
- cdef TFsPath path_absolute = TFsPath("/a/b/c")
- self.assertEquals(path_absolute.IsAbsolute(), True)
- self.assertEquals(path_absolute.IsRelative(), False)
-
- self.assertEquals(path_absolute.IsSubpathOf(TFsPath("/a/b")), True)
- self.assertEquals(path_absolute.IsNonStrictSubpathOf(TFsPath("/a/b")), True)
- self.assertEquals(TFsPath("/a/b").IsContainerOf(path_absolute), True)
-
- self.assertEquals(path_absolute.IsSubpathOf(TFsPath("/a/b/c")), False)
- self.assertEquals(path_absolute.IsNonStrictSubpathOf(TFsPath("/a/b/c")), True)
- self.assertEquals(TFsPath("/a/b/c").IsContainerOf(path_absolute), False)
-
- self.assertEquals(path_absolute.IsSubpathOf(TFsPath("/a/c")), False)
- self.assertEquals(path_absolute.IsNonStrictSubpathOf(TFsPath("/a/c")), False)
- self.assertEquals(TFsPath("/a/c").IsContainerOf(path_absolute), False)
-
- with self.assertRaises(RuntimeError):
- path_absolute.RelativeTo(TFsPath("/a/c"))
- self.assertEquals(path_absolute.RelativePath(TFsPath("/a/с")).GetPath(), "../b/c")
- self.assertEquals(path_absolute.RelativeTo(TFsPath("/a")).GetPath(), "b/c")
- self.assertEquals(path_absolute.RelativePath(TFsPath("/a")).GetPath(), "b/c")
- self.assertEquals(path_absolute.RelativeTo(TFsPath("/")).GetPath(), "a/b/c")
- self.assertEquals(path_absolute.RelativePath(TFsPath("/")).GetPath(), "a/b/c")
-
- with self.assertRaises(RuntimeError):
- path_absolute.RelativeTo(TFsPath("./a"))
- with self.assertRaises(RuntimeError):
- path_absolute.RelativePath(TFsPath("d"))
- self.assertEquals(path_absolute.RelativePath(TFsPath("./a")).GetPath(), "b/c")
-
- self.assertEquals(path_absolute.Parent().GetPath(), "/a/b")
- self.assertEquals(path_absolute.Child("d").GetPath(), "/a/b/c/d")
-
- def test_relative(self):
- cdef TFsPath path_relative_1 = TFsPath("a/b/c")
- self.assertEquals(path_relative_1.IsAbsolute(), False)
- self.assertEquals(path_relative_1.IsRelative(), True)
-
- self.assertEquals(path_relative_1.IsSubpathOf(TFsPath("a/b")), True)
- self.assertEquals(path_relative_1.IsNonStrictSubpathOf(TFsPath("a/b")), True)
- self.assertEquals(TFsPath("a/b").IsContainerOf(path_relative_1), True)
-
- self.assertEquals(path_relative_1.IsSubpathOf(TFsPath("a/b/c")), False)
- self.assertEquals(path_relative_1.IsNonStrictSubpathOf(TFsPath("a/b/c")), True)
- self.assertEquals(TFsPath("a/b/c").IsContainerOf(path_relative_1), False)
-
- self.assertEquals(path_relative_1.IsSubpathOf(TFsPath("a/c")), False)
- self.assertEquals(path_relative_1.IsNonStrictSubpathOf(TFsPath("a/c")), False)
- self.assertEquals(TFsPath("a/c").IsContainerOf(path_relative_1), False)
-
- self.assertEquals(path_relative_1.Parent().GetPath(), "a/b")
- self.assertEquals(path_relative_1.Child("d").GetPath(), "a/b/c/d")
-
- cdef TFsPath path_relative_2 = TFsPath("./a/b/c")
- self.assertEquals(path_relative_2.IsAbsolute(), False)
- self.assertEquals(path_relative_2.IsRelative(), True)
-
- self.assertEquals(path_relative_2.IsSubpathOf(TFsPath("a/b")), True)
- self.assertEquals(path_relative_2.IsNonStrictSubpathOf(TFsPath("a/b")), True)
- self.assertEquals(TFsPath("a/b").IsContainerOf(path_relative_2), True)
-
- self.assertEquals(path_relative_2.IsSubpathOf(TFsPath("a/b/c")), False)
- self.assertEquals(path_relative_2.IsNonStrictSubpathOf(TFsPath("a/b/c")), True)
- self.assertEquals(TFsPath("a/b/c").IsContainerOf(path_relative_2), False)
-
- self.assertEquals(path_relative_2.IsSubpathOf(TFsPath("a/c")), False)
- self.assertEquals(path_relative_2.IsNonStrictSubpathOf(TFsPath("a/c")), False)
- self.assertEquals(TFsPath("a/c").IsContainerOf(path_relative_2), False)
-
- with self.assertRaises(RuntimeError):
- path_relative_2.RelativeTo(TFsPath("a/c"))
- self.assertEquals(path_relative_2.RelativePath(TFsPath("a/с")).GetPath(), "../b/c")
- self.assertEquals(path_relative_2.RelativeTo(TFsPath("a")).GetPath(), "b/c")
- self.assertEquals(path_relative_2.RelativePath(TFsPath("a")).GetPath(), "b/c")
- self.assertEquals(path_relative_2.RelativeTo(TFsPath("./")).GetPath(), "a/b/c")
- self.assertEquals(path_relative_2.RelativePath(TFsPath("/a")).GetPath(), "b/c")
-
- with self.assertRaises(RuntimeError):
- self.assertEquals(path_relative_2.RelativePath(TFsPath("./")).GetPath(), "a/b/c")
-
- with self.assertRaises(RuntimeError):
- path_relative_2.RelativeTo(TFsPath("/d"))
- with self.assertRaises(RuntimeError):
- path_relative_2.RelativePath(TFsPath("/d"))
- with self.assertRaises(RuntimeError):
- path_relative_2.RelativePath(TFsPath("/"))
-
- self.assertEquals(path_relative_2.Parent().GetPath(), "a/b")
- self.assertEquals(path_relative_2.Child("d").GetPath(), "a/b/c/d")
-
- def test_mkdir(self):
- cdef TFsPath directory = TFsPath("test_mkdir")
- cdef TFsPath full = directory / directory
- cdef TFsPath internal = full / directory
- with self.assertRaises(RuntimeError):
- full.MkDir()
- full.MkDirs()
- internal.MkDir()
-
- def test_list(self):
- cdef TFsPath dir = TFsPath("test_list")
- dir.MkDir()
- TFsPath("test_list/b").Touch()
- TFsPath("test_list/c").Touch()
-
- cdef TVector[TFsPath] files
- cdef TVector[TString] names
-
- dir.List(files)
- dir.ListNames(names)
-
- self.assertEquals(files.size(), 2)
- self.assertEquals(sorted([files[0].GetPath(), files[1].GetPath()]), ["test_list/b", "test_list/c"])
- self.assertEquals(names.size(), 2)
- self.assertEquals(sorted(list(names)), ["b", "c"])
-
- def test_contains(self):
- cdef TFsPath path = TFsPath("a/b/c")
- self.assertEquals(path.Contains("c"), True)
- self.assertEquals(path.Contains("b"), True)
- self.assertEquals(path.Contains("d"), False)
-
- def test_delete(self):
- cdef TFsPath root = TFsPath("/")
- with self.assertRaises(RuntimeError):
- root.DeleteIfExists()
- with self.assertRaises(RuntimeError):
- root.ForceDelete()
-
- cdef TFsPath directory = TFsPath("test_delete")
- cdef TFsPath full = directory / directory
- full.MkDirs()
-
- self.assertEquals(full.Exists(), True)
- with self.assertRaises(RuntimeError):
- directory.DeleteIfExists()
- self.assertEquals(directory.Exists(), True)
- directory.ForceDelete()
- self.assertEquals(directory.Exists(), False)
-
- cdef TFsPath local_file = TFsPath("test_delete_1")
- self.assertEquals(local_file.Exists(), False)
- local_file.DeleteIfExists()
- self.assertEquals(local_file.Exists(), False)
- local_file.ForceDelete()
- self.assertEquals(local_file.Exists(), False)
-
- local_file.Touch()
- self.assertEquals(local_file.Exists(), True)
- local_file.DeleteIfExists()
- self.assertEquals(local_file.Exists(), False)
-
- local_file.Touch()
- self.assertEquals(local_file.Exists(), True)
- local_file.ForceDelete()
- self.assertEquals(local_file.Exists(), False)
-
- full.MkDirs()
- self.assertEquals(full.Exists(), True)
- full.DeleteIfExists()
- self.assertEquals(full.Exists(), False)
- self.assertEquals(directory.Exists(), True)
- directory.DeleteIfExists()
- self.assertEquals(directory.Exists(), False)
-
- def test_checks(self):
- cdef TFsPath local_file = TFsPath("test_checks")
- with self.assertRaises(RuntimeError):
- local_file.CheckExists()
- local_file.Touch()
- self.assertEquals(local_file.Exists(), True)
- self.assertEquals(local_file.IsDirectory(), False)
- self.assertEquals(local_file.IsFile(), True)
- self.assertEquals(local_file.IsSymlink(), False)
- local_file.CheckExists()
-
- local_file.DeleteIfExists()
- local_file.MkDir()
- self.assertEquals(local_file.Exists(), True)
- self.assertEquals(local_file.IsDirectory(), True)
- self.assertEquals(local_file.IsFile(), False)
- self.assertEquals(local_file.IsSymlink(), False)
- local_file.CheckExists()
-
- def test_rename(self):
- cdef TFsPath path = TFsPath("test_rename_a")
- path.Touch()
-
- cdef TString path_str = "test_rename_b"
- cdef TFsPath path_from_str = TFsPath(path_str)
- self.assertEquals(path.Exists(), True)
- self.assertEquals(path_from_str.Exists(), False)
- path.RenameTo(path_str)
- self.assertEquals(path.Exists(), False)
- self.assertEquals(path_from_str.Exists(), True)
-
- cdef const char* path_char = "test_rename_c"
- cdef TFsPath path_from_char = TFsPath(path_char)
- self.assertEquals(path_from_str.Exists(), True)
- self.assertEquals(path_from_char.Exists(), False)
- path_from_str.RenameTo(path_char)
- self.assertEquals(path_from_str.Exists(), False)
- self.assertEquals(path_from_char.Exists(), True)
-
- path_from_char.RenameTo(path)
-
- self.assertEquals(path_from_char.Exists(), False)
- self.assertEquals(path.Exists(), True)
-
- path.ForceRenameTo(path_str)
-
- self.assertEquals(path_from_str.Exists(), True)
- self.assertEquals(path.Exists(), False)
-
- with self.assertRaises(RuntimeError):
- path_from_str.RenameTo("")
-
- def test_copy(self):
- cdef TString dst = "test_copy_dst"
- cdef TFsPath src_path = TFsPath("test_copy_src")
- cdef TFsPath dst_path = TFsPath(dst)
- self.assertEquals(src_path.Exists(), False)
- src_path.Touch()
- self.assertEquals(src_path.Exists(), True)
- src_path.CopyTo(dst, False)
- self.assertEquals(src_path.Exists(), True)
- self.assertEquals(dst_path.Exists(), True)
-
- def test_real_path(self):
- cdef TFsPath path = TFsPath("test_real_path_a")
- path.Touch()
- self.assertEquals(path.RealPath().GetPath(), os.path.join(yatest.common.work_path(), "test_real_path_a"))
- self.assertEquals(path.RealLocation().GetPath(), os.path.join(yatest.common.work_path(), "test_real_path_a"))
- with self.assertRaises(RuntimeError):
- path.ReadLink()
-
- def test_cwd(self):
- cdef TFsPath path = TFsPath.Cwd()
- self.assertEquals(path.GetPath(), yatest.common.work_path())
-
- def test_swap(self):
- cdef TFsPath first = TFsPath("first")
- cdef TFsPath second = TFsPath("second")
-
- self.assertEquals(first.GetPath(), "first")
- self.assertEquals(second.GetPath(), "second")
- first.Swap(second)
- self.assertEquals(first.GetPath(), "second")
- self.assertEquals(second.GetPath(), "first")
- second.Swap(first)
- self.assertEquals(first.GetPath(), "first")
- self.assertEquals(second.GetPath(), "second")
+# cython: c_string_type=str, c_string_encoding=utf8
+
+from util.folder.path cimport TFsPath
+from util.generic.string cimport TString, TStringBuf
+from util.generic.vector cimport TVector
+
+import unittest
+import yatest.common
+
+import os.path
+
+
+class TestPath(unittest.TestCase):
+ def test_ctor1(self):
+ cdef TFsPath path = TFsPath()
+ self.assertEqual(path.IsDefined(), False)
+ self.assertEquals(path.c_str(), "")
+
+ def test_ctor2(self):
+ cdef TString str_path = "/a/b/c"
+ cdef TFsPath path = TFsPath(str_path)
+ self.assertEqual(path.IsDefined(), True)
+ self.assertEquals(path.c_str(), "/a/b/c")
+
+ def test_ctor3(self):
+ cdef TStringBuf buf_path = "/a/b/c"
+ cdef TFsPath path = TFsPath(buf_path)
+ self.assertEqual(path.IsDefined(), True)
+ self.assertEquals(path.c_str(), "/a/b/c")
+
+ def test_ctor4(self):
+ cdef char* char_path = "/a/b/c"
+ cdef TFsPath path = TFsPath(char_path)
+ self.assertEqual(path.IsDefined(), True)
+ self.assertEquals(path.c_str(), "/a/b/c")
+
+ def test_assignment(self):
+ cdef TFsPath path1 = TFsPath("/a/b")
+ cdef TFsPath path2 = TFsPath("/a/c")
+
+ self.assertEquals(path1.GetPath(), "/a/b")
+ self.assertEquals(path2.GetPath(), "/a/c")
+
+ path2 = path1
+
+ self.assertEquals(path1.GetPath(), "/a/b")
+ self.assertEquals(path2.GetPath(), "/a/b")
+
+ def test_check_defined(self):
+ cdef TFsPath path1 = TFsPath()
+ with self.assertRaises(RuntimeError):
+ path1.CheckDefined()
+ self.assertEqual(path1.IsDefined(), False)
+ if path1:
+ assert False
+ else:
+ pass
+
+ cdef TFsPath path2 = TFsPath("")
+ with self.assertRaises(RuntimeError):
+ path2.CheckDefined()
+ self.assertEqual(path2.IsDefined(), False)
+ if path2:
+ assert False
+ else:
+ pass
+
+ cdef TFsPath path3 = TFsPath("/")
+ path3.CheckDefined()
+ self.assertEqual(path3.IsDefined(), True)
+ if path3:
+ pass
+ else:
+ assert False
+
+ def test_comparison(self):
+ cdef TFsPath path1 = TFsPath("/a/b")
+ cdef TFsPath path2 = TFsPath("/a/c")
+ cdef TFsPath path3 = TFsPath("/a/b")
+
+ self.assertEqual(path1 == path3, True)
+ self.assertEqual(path1 != path2, True)
+ self.assertEqual(path3 != path2, True)
+
+ def test_concatenation(self):
+ cdef TFsPath path1 = TFsPath("/a")
+ cdef TFsPath path2 = TFsPath("b")
+ cdef TFsPath path3 = path1 / path2
+ cdef TFsPath path4 = TFsPath("/a/b")
+
+ self.assertEqual(path3 == path4, True)
+
+ def test_fix(self):
+ cdef TFsPath path = TFsPath("test_fix/b/c/../d")
+ cdef TFsPath fixed = path.Fix()
+ self.assertEquals(fixed.GetPath(), "test_fix/b/d")
+
+ def test_parts(self):
+ cdef TFsPath path = TFsPath("/a/b/c")
+ self.assertEquals(path.GetPath(), "/a/b/c")
+ self.assertEquals(path.GetName(), "c")
+ self.assertEquals(path.GetExtension(), "")
+ self.assertEquals(path.Basename(), "c")
+ self.assertEquals(path.Dirname(), "/a/b")
+
+ cdef TFsPath path_ext = TFsPath("/a/b/c.ext")
+ self.assertEquals(path_ext.GetPath(), "/a/b/c.ext")
+ self.assertEquals(path_ext.GetName(), "c.ext")
+ self.assertEquals(path_ext.GetExtension(), "ext")
+ self.assertEquals(path_ext.Basename(), "c.ext")
+ self.assertEquals(path_ext.Dirname(), "/a/b")
+
+ cdef TFsPath path_only_ext = TFsPath("/a/b/.ext")
+ self.assertEquals(path_only_ext.GetPath(), "/a/b/.ext")
+ self.assertEquals(path_only_ext.GetName(), ".ext")
+ self.assertEquals(path_only_ext.GetExtension(), "")
+ self.assertEquals(path_only_ext.Basename(), ".ext")
+ self.assertEquals(path_only_ext.Dirname(), "/a/b")
+
+ cdef TFsPath path_dir = TFsPath("/a/b/")
+ self.assertEquals(path_dir.GetPath(), "/a/b/")
+ self.assertEquals(path_dir.GetName(), "b")
+ self.assertEquals(path_dir.GetExtension(), "")
+ self.assertEquals(path_dir.Basename(), "b")
+ self.assertEquals(path_dir.Dirname(), "/a")
+
+ def test_absolute(self):
+ cdef TFsPath path_absolute = TFsPath("/a/b/c")
+ self.assertEquals(path_absolute.IsAbsolute(), True)
+ self.assertEquals(path_absolute.IsRelative(), False)
+
+ self.assertEquals(path_absolute.IsSubpathOf(TFsPath("/a/b")), True)
+ self.assertEquals(path_absolute.IsNonStrictSubpathOf(TFsPath("/a/b")), True)
+ self.assertEquals(TFsPath("/a/b").IsContainerOf(path_absolute), True)
+
+ self.assertEquals(path_absolute.IsSubpathOf(TFsPath("/a/b/c")), False)
+ self.assertEquals(path_absolute.IsNonStrictSubpathOf(TFsPath("/a/b/c")), True)
+ self.assertEquals(TFsPath("/a/b/c").IsContainerOf(path_absolute), False)
+
+ self.assertEquals(path_absolute.IsSubpathOf(TFsPath("/a/c")), False)
+ self.assertEquals(path_absolute.IsNonStrictSubpathOf(TFsPath("/a/c")), False)
+ self.assertEquals(TFsPath("/a/c").IsContainerOf(path_absolute), False)
+
+ with self.assertRaises(RuntimeError):
+ path_absolute.RelativeTo(TFsPath("/a/c"))
+ self.assertEquals(path_absolute.RelativePath(TFsPath("/a/с")).GetPath(), "../b/c")
+ self.assertEquals(path_absolute.RelativeTo(TFsPath("/a")).GetPath(), "b/c")
+ self.assertEquals(path_absolute.RelativePath(TFsPath("/a")).GetPath(), "b/c")
+ self.assertEquals(path_absolute.RelativeTo(TFsPath("/")).GetPath(), "a/b/c")
+ self.assertEquals(path_absolute.RelativePath(TFsPath("/")).GetPath(), "a/b/c")
+
+ with self.assertRaises(RuntimeError):
+ path_absolute.RelativeTo(TFsPath("./a"))
+ with self.assertRaises(RuntimeError):
+ path_absolute.RelativePath(TFsPath("d"))
+ self.assertEquals(path_absolute.RelativePath(TFsPath("./a")).GetPath(), "b/c")
+
+ self.assertEquals(path_absolute.Parent().GetPath(), "/a/b")
+ self.assertEquals(path_absolute.Child("d").GetPath(), "/a/b/c/d")
+
+ def test_relative(self):
+ cdef TFsPath path_relative_1 = TFsPath("a/b/c")
+ self.assertEquals(path_relative_1.IsAbsolute(), False)
+ self.assertEquals(path_relative_1.IsRelative(), True)
+
+ self.assertEquals(path_relative_1.IsSubpathOf(TFsPath("a/b")), True)
+ self.assertEquals(path_relative_1.IsNonStrictSubpathOf(TFsPath("a/b")), True)
+ self.assertEquals(TFsPath("a/b").IsContainerOf(path_relative_1), True)
+
+ self.assertEquals(path_relative_1.IsSubpathOf(TFsPath("a/b/c")), False)
+ self.assertEquals(path_relative_1.IsNonStrictSubpathOf(TFsPath("a/b/c")), True)
+ self.assertEquals(TFsPath("a/b/c").IsContainerOf(path_relative_1), False)
+
+ self.assertEquals(path_relative_1.IsSubpathOf(TFsPath("a/c")), False)
+ self.assertEquals(path_relative_1.IsNonStrictSubpathOf(TFsPath("a/c")), False)
+ self.assertEquals(TFsPath("a/c").IsContainerOf(path_relative_1), False)
+
+ self.assertEquals(path_relative_1.Parent().GetPath(), "a/b")
+ self.assertEquals(path_relative_1.Child("d").GetPath(), "a/b/c/d")
+
+ cdef TFsPath path_relative_2 = TFsPath("./a/b/c")
+ self.assertEquals(path_relative_2.IsAbsolute(), False)
+ self.assertEquals(path_relative_2.IsRelative(), True)
+
+ self.assertEquals(path_relative_2.IsSubpathOf(TFsPath("a/b")), True)
+ self.assertEquals(path_relative_2.IsNonStrictSubpathOf(TFsPath("a/b")), True)
+ self.assertEquals(TFsPath("a/b").IsContainerOf(path_relative_2), True)
+
+ self.assertEquals(path_relative_2.IsSubpathOf(TFsPath("a/b/c")), False)
+ self.assertEquals(path_relative_2.IsNonStrictSubpathOf(TFsPath("a/b/c")), True)
+ self.assertEquals(TFsPath("a/b/c").IsContainerOf(path_relative_2), False)
+
+ self.assertEquals(path_relative_2.IsSubpathOf(TFsPath("a/c")), False)
+ self.assertEquals(path_relative_2.IsNonStrictSubpathOf(TFsPath("a/c")), False)
+ self.assertEquals(TFsPath("a/c").IsContainerOf(path_relative_2), False)
+
+ with self.assertRaises(RuntimeError):
+ path_relative_2.RelativeTo(TFsPath("a/c"))
+ self.assertEquals(path_relative_2.RelativePath(TFsPath("a/с")).GetPath(), "../b/c")
+ self.assertEquals(path_relative_2.RelativeTo(TFsPath("a")).GetPath(), "b/c")
+ self.assertEquals(path_relative_2.RelativePath(TFsPath("a")).GetPath(), "b/c")
+ self.assertEquals(path_relative_2.RelativeTo(TFsPath("./")).GetPath(), "a/b/c")
+ self.assertEquals(path_relative_2.RelativePath(TFsPath("/a")).GetPath(), "b/c")
+
+ with self.assertRaises(RuntimeError):
+ self.assertEquals(path_relative_2.RelativePath(TFsPath("./")).GetPath(), "a/b/c")
+
+ with self.assertRaises(RuntimeError):
+ path_relative_2.RelativeTo(TFsPath("/d"))
+ with self.assertRaises(RuntimeError):
+ path_relative_2.RelativePath(TFsPath("/d"))
+ with self.assertRaises(RuntimeError):
+ path_relative_2.RelativePath(TFsPath("/"))
+
+ self.assertEquals(path_relative_2.Parent().GetPath(), "a/b")
+ self.assertEquals(path_relative_2.Child("d").GetPath(), "a/b/c/d")
+
+ def test_mkdir(self):
+ cdef TFsPath directory = TFsPath("test_mkdir")
+ cdef TFsPath full = directory / directory
+ cdef TFsPath internal = full / directory
+ with self.assertRaises(RuntimeError):
+ full.MkDir()
+ full.MkDirs()
+ internal.MkDir()
+
+ def test_list(self):
+ cdef TFsPath dir = TFsPath("test_list")
+ dir.MkDir()
+ TFsPath("test_list/b").Touch()
+ TFsPath("test_list/c").Touch()
+
+ cdef TVector[TFsPath] files
+ cdef TVector[TString] names
+
+ dir.List(files)
+ dir.ListNames(names)
+
+ self.assertEquals(files.size(), 2)
+ self.assertEquals(sorted([files[0].GetPath(), files[1].GetPath()]), ["test_list/b", "test_list/c"])
+ self.assertEquals(names.size(), 2)
+ self.assertEquals(sorted(list(names)), ["b", "c"])
+
+ def test_contains(self):
+ cdef TFsPath path = TFsPath("a/b/c")
+ self.assertEquals(path.Contains("c"), True)
+ self.assertEquals(path.Contains("b"), True)
+ self.assertEquals(path.Contains("d"), False)
+
+ def test_delete(self):
+ cdef TFsPath root = TFsPath("/")
+ with self.assertRaises(RuntimeError):
+ root.DeleteIfExists()
+ with self.assertRaises(RuntimeError):
+ root.ForceDelete()
+
+ cdef TFsPath directory = TFsPath("test_delete")
+ cdef TFsPath full = directory / directory
+ full.MkDirs()
+
+ self.assertEquals(full.Exists(), True)
+ with self.assertRaises(RuntimeError):
+ directory.DeleteIfExists()
+ self.assertEquals(directory.Exists(), True)
+ directory.ForceDelete()
+ self.assertEquals(directory.Exists(), False)
+
+ cdef TFsPath local_file = TFsPath("test_delete_1")
+ self.assertEquals(local_file.Exists(), False)
+ local_file.DeleteIfExists()
+ self.assertEquals(local_file.Exists(), False)
+ local_file.ForceDelete()
+ self.assertEquals(local_file.Exists(), False)
+
+ local_file.Touch()
+ self.assertEquals(local_file.Exists(), True)
+ local_file.DeleteIfExists()
+ self.assertEquals(local_file.Exists(), False)
+
+ local_file.Touch()
+ self.assertEquals(local_file.Exists(), True)
+ local_file.ForceDelete()
+ self.assertEquals(local_file.Exists(), False)
+
+ full.MkDirs()
+ self.assertEquals(full.Exists(), True)
+ full.DeleteIfExists()
+ self.assertEquals(full.Exists(), False)
+ self.assertEquals(directory.Exists(), True)
+ directory.DeleteIfExists()
+ self.assertEquals(directory.Exists(), False)
+
+ def test_checks(self):
+ cdef TFsPath local_file = TFsPath("test_checks")
+ with self.assertRaises(RuntimeError):
+ local_file.CheckExists()
+ local_file.Touch()
+ self.assertEquals(local_file.Exists(), True)
+ self.assertEquals(local_file.IsDirectory(), False)
+ self.assertEquals(local_file.IsFile(), True)
+ self.assertEquals(local_file.IsSymlink(), False)
+ local_file.CheckExists()
+
+ local_file.DeleteIfExists()
+ local_file.MkDir()
+ self.assertEquals(local_file.Exists(), True)
+ self.assertEquals(local_file.IsDirectory(), True)
+ self.assertEquals(local_file.IsFile(), False)
+ self.assertEquals(local_file.IsSymlink(), False)
+ local_file.CheckExists()
+
+ def test_rename(self):
+ cdef TFsPath path = TFsPath("test_rename_a")
+ path.Touch()
+
+ cdef TString path_str = "test_rename_b"
+ cdef TFsPath path_from_str = TFsPath(path_str)
+ self.assertEquals(path.Exists(), True)
+ self.assertEquals(path_from_str.Exists(), False)
+ path.RenameTo(path_str)
+ self.assertEquals(path.Exists(), False)
+ self.assertEquals(path_from_str.Exists(), True)
+
+ cdef const char* path_char = "test_rename_c"
+ cdef TFsPath path_from_char = TFsPath(path_char)
+ self.assertEquals(path_from_str.Exists(), True)
+ self.assertEquals(path_from_char.Exists(), False)
+ path_from_str.RenameTo(path_char)
+ self.assertEquals(path_from_str.Exists(), False)
+ self.assertEquals(path_from_char.Exists(), True)
+
+ path_from_char.RenameTo(path)
+
+ self.assertEquals(path_from_char.Exists(), False)
+ self.assertEquals(path.Exists(), True)
+
+ path.ForceRenameTo(path_str)
+
+ self.assertEquals(path_from_str.Exists(), True)
+ self.assertEquals(path.Exists(), False)
+
+ with self.assertRaises(RuntimeError):
+ path_from_str.RenameTo("")
+
+ def test_copy(self):
+ cdef TString dst = "test_copy_dst"
+ cdef TFsPath src_path = TFsPath("test_copy_src")
+ cdef TFsPath dst_path = TFsPath(dst)
+ self.assertEquals(src_path.Exists(), False)
+ src_path.Touch()
+ self.assertEquals(src_path.Exists(), True)
+ src_path.CopyTo(dst, False)
+ self.assertEquals(src_path.Exists(), True)
+ self.assertEquals(dst_path.Exists(), True)
+
+ def test_real_path(self):
+ cdef TFsPath path = TFsPath("test_real_path_a")
+ path.Touch()
+ self.assertEquals(path.RealPath().GetPath(), os.path.join(yatest.common.work_path(), "test_real_path_a"))
+ self.assertEquals(path.RealLocation().GetPath(), os.path.join(yatest.common.work_path(), "test_real_path_a"))
+ with self.assertRaises(RuntimeError):
+ path.ReadLink()
+
+ def test_cwd(self):
+ cdef TFsPath path = TFsPath.Cwd()
+ self.assertEquals(path.GetPath(), yatest.common.work_path())
+
+ def test_swap(self):
+ cdef TFsPath first = TFsPath("first")
+ cdef TFsPath second = TFsPath("second")
+
+ self.assertEquals(first.GetPath(), "first")
+ self.assertEquals(second.GetPath(), "second")
+ first.Swap(second)
+ self.assertEquals(first.GetPath(), "second")
+ self.assertEquals(second.GetPath(), "first")
+ second.Swap(first)
+ self.assertEquals(first.GetPath(), "first")
+ self.assertEquals(second.GetPath(), "second")
diff --git a/util/generic/deque.pxd b/util/generic/deque.pxd
index ae3b31fb5f..62834ac2ad 100644
--- a/util/generic/deque.pxd
+++ b/util/generic/deque.pxd
@@ -1,9 +1,9 @@
-from libcpp.deque cimport deque
-
-
-cdef extern from "<util/generic/deque.h>" nogil:
- cdef cppclass TDeque[T](deque):
- TDeque() except +
- TDeque(size_t) except +
- TDeque(size_t, const T&) except +
- TDeque(const TDeque&) except +
+from libcpp.deque cimport deque
+
+
+cdef extern from "<util/generic/deque.h>" nogil:
+ cdef cppclass TDeque[T](deque):
+ TDeque() except +
+ TDeque(size_t) except +
+ TDeque(size_t, const T&) except +
+ TDeque(const TDeque&) except +
diff --git a/util/generic/deque_ut.pyx b/util/generic/deque_ut.pyx
index 5c8e985d8b..42cec42647 100644
--- a/util/generic/deque_ut.pyx
+++ b/util/generic/deque_ut.pyx
@@ -1,66 +1,66 @@
-from libcpp.deque cimport deque
-from util.generic.deque cimport TDeque
-
-import pytest
-import unittest
-
-
-class TestDeque(unittest.TestCase):
- def test_ctor1(self):
- cdef TDeque[int] tmp = TDeque[int]()
- self.assertEqual(tmp.size(), 0)
-
- def test_ctor2(self):
- cdef TDeque[int] tmp = TDeque[int](10)
- self.assertEqual(tmp.size(), 10)
- self.assertEqual(tmp[0], 0)
-
- def test_ctor3(self):
- cdef TDeque[int] tmp = TDeque[int](10, 42)
- self.assertEqual(tmp.size(), 10)
- self.assertEqual(tmp[0], 42)
-
- def test_ctor4(self):
- cdef TDeque[int] tmp = TDeque[int](10, 42)
- cdef TDeque[int] tmp2 = TDeque[int](tmp)
- self.assertEqual(tmp2.size(), 10)
- self.assertEqual(tmp2[0], 42)
-
- def test_operator_assign(self):
- cdef TDeque[int] tmp2
- tmp2.push_back(1)
- tmp2.push_back(2)
-
- cdef TDeque[int] tmp3
- tmp3.push_back(1)
- tmp3.push_back(3)
-
- self.assertEqual(tmp2[1], 2)
- self.assertEqual(tmp3[1], 3)
-
- tmp3 = tmp2
-
- self.assertEqual(tmp2[1], 2)
- self.assertEqual(tmp3[1], 2)
-
- def test_compare(self):
- cdef TDeque[int] tmp1
- tmp1.push_back(1)
- tmp1.push_back(2)
-
- cdef TDeque[int] tmp2
- tmp2.push_back(1)
- tmp2.push_back(2)
-
- cdef TDeque[int] tmp3
- tmp3.push_back(1)
- tmp3.push_back(3)
-
- self.assertTrue(tmp1 == tmp2)
- self.assertTrue(tmp1 != tmp3)
-
- self.assertTrue(tmp1 < tmp3)
- self.assertTrue(tmp1 <= tmp3)
-
- self.assertTrue(tmp3 > tmp1)
- self.assertTrue(tmp3 >= tmp1) \ No newline at end of file
+from libcpp.deque cimport deque
+from util.generic.deque cimport TDeque
+
+import pytest
+import unittest
+
+
+class TestDeque(unittest.TestCase):
+ def test_ctor1(self):
+ cdef TDeque[int] tmp = TDeque[int]()
+ self.assertEqual(tmp.size(), 0)
+
+ def test_ctor2(self):
+ cdef TDeque[int] tmp = TDeque[int](10)
+ self.assertEqual(tmp.size(), 10)
+ self.assertEqual(tmp[0], 0)
+
+ def test_ctor3(self):
+ cdef TDeque[int] tmp = TDeque[int](10, 42)
+ self.assertEqual(tmp.size(), 10)
+ self.assertEqual(tmp[0], 42)
+
+ def test_ctor4(self):
+ cdef TDeque[int] tmp = TDeque[int](10, 42)
+ cdef TDeque[int] tmp2 = TDeque[int](tmp)
+ self.assertEqual(tmp2.size(), 10)
+ self.assertEqual(tmp2[0], 42)
+
+ def test_operator_assign(self):
+ cdef TDeque[int] tmp2
+ tmp2.push_back(1)
+ tmp2.push_back(2)
+
+ cdef TDeque[int] tmp3
+ tmp3.push_back(1)
+ tmp3.push_back(3)
+
+ self.assertEqual(tmp2[1], 2)
+ self.assertEqual(tmp3[1], 3)
+
+ tmp3 = tmp2
+
+ self.assertEqual(tmp2[1], 2)
+ self.assertEqual(tmp3[1], 2)
+
+ def test_compare(self):
+ cdef TDeque[int] tmp1
+ tmp1.push_back(1)
+ tmp1.push_back(2)
+
+ cdef TDeque[int] tmp2
+ tmp2.push_back(1)
+ tmp2.push_back(2)
+
+ cdef TDeque[int] tmp3
+ tmp3.push_back(1)
+ tmp3.push_back(3)
+
+ self.assertTrue(tmp1 == tmp2)
+ self.assertTrue(tmp1 != tmp3)
+
+ self.assertTrue(tmp1 < tmp3)
+ self.assertTrue(tmp1 <= tmp3)
+
+ self.assertTrue(tmp3 > tmp1)
+ self.assertTrue(tmp3 >= tmp1) \ No newline at end of file
diff --git a/util/generic/hash.pxd b/util/generic/hash.pxd
index 1eabe0e380..385c10d805 100644
--- a/util/generic/hash.pxd
+++ b/util/generic/hash.pxd
@@ -12,16 +12,16 @@ cdef extern from "util/generic/hash.h" nogil:
cppclass const_iterator(iterator):
pass
- cppclass reverse_iterator:
- pair[T, U]& operator*()
- iterator operator++()
- iterator operator--()
- bint operator==(reverse_iterator)
- bint operator!=(reverse_iterator)
-
- cppclass const_reverse_iterator(reverse_iterator):
- pass
-
+ cppclass reverse_iterator:
+ pair[T, U]& operator*()
+ iterator operator++()
+ iterator operator--()
+ bint operator==(reverse_iterator)
+ bint operator!=(reverse_iterator)
+
+ cppclass const_reverse_iterator(reverse_iterator):
+ pass
+
THashMap() except +
THashMap(THashMap&) except +
U& operator[](T&)
@@ -54,13 +54,13 @@ cdef extern from "util/generic/hash.h" nogil:
size_t max_size()
size_t size()
void swap(THashMap&)
- iterator lower_bound(T&)
- const_iterator const_lower_bound "lower_bound"(T&)
- reverse_iterator rbegin()
- const_reverse_iterator const_rbegin "rbegin"()
- reverse_iterator rend()
- const_reverse_iterator const_rend "rend"()
- iterator upper_bound(T&)
- const_iterator const_upper_bound "upper_bound"(T&)
- void max_load_factor(float)
- float max_load_factor()
+ iterator lower_bound(T&)
+ const_iterator const_lower_bound "lower_bound"(T&)
+ reverse_iterator rbegin()
+ const_reverse_iterator const_rbegin "rbegin"()
+ reverse_iterator rend()
+ const_reverse_iterator const_rend "rend"()
+ iterator upper_bound(T&)
+ const_iterator const_upper_bound "upper_bound"(T&)
+ void max_load_factor(float)
+ float max_load_factor()
diff --git a/util/generic/hash_set_ut.pyx b/util/generic/hash_set_ut.pyx
index 275ffddd3f..bdcf6284af 100644
--- a/util/generic/hash_set_ut.pyx
+++ b/util/generic/hash_set_ut.pyx
@@ -9,7 +9,7 @@ import unittest
from cython.operator cimport dereference as deref
-class TestHashSet(unittest.TestCase):
+class TestHashSet(unittest.TestCase):
def test_simple_constructor_equality_operator(self):
cdef THashSet[int] c1
diff --git a/util/generic/hash_ut.pyx b/util/generic/hash_ut.pyx
index d714288da1..ecf6dac2e6 100644
--- a/util/generic/hash_ut.pyx
+++ b/util/generic/hash_ut.pyx
@@ -1,5 +1,5 @@
-# cython: c_string_type=str, c_string_encoding=utf8
-
+# cython: c_string_type=str, c_string_encoding=utf8
+
from util.generic.hash cimport THashMap
from util.generic.string cimport TString
diff --git a/util/generic/ptr.pxd b/util/generic/ptr.pxd
index 7eb3171aab..16e8d19144 100644
--- a/util/generic/ptr.pxd
+++ b/util/generic/ptr.pxd
@@ -8,10 +8,10 @@ cdef extern from "<util/generic/ptr.h>" nogil:
void Reset(T*)
void Swap(THolder[T])
-
+
cdef THolder[T] MakeHolder[T](...)
-
+
cdef cppclass TIntrusivePtr[T]:
TIntrusivePtr()
TIntrusivePtr(T*)
@@ -21,16 +21,16 @@ cdef extern from "<util/generic/ptr.h>" nogil:
T* Release()
void Drop()
-
- cdef cppclass TIntrusiveConstPtr[T]:
- TIntrusiveConstPtr()
- TIntrusiveConstPtr(T*)
- TIntrusiveConstPtr& operator=(...)
- void Reset(T*)
- const T* Get()
- void Drop()
-
-
+
+ cdef cppclass TIntrusiveConstPtr[T]:
+ TIntrusiveConstPtr()
+ TIntrusiveConstPtr(T*)
+ TIntrusiveConstPtr& operator=(...)
+ void Reset(T*)
+ const T* Get()
+ void Drop()
+
+
cdef cppclass TAtomicSharedPtr[T]:
TAtomicSharedPtr()
TAtomicSharedPtr(T*)
diff --git a/util/generic/string.pxd b/util/generic/string.pxd
index 2ae1555c21..c25f7392a1 100644
--- a/util/generic/string.pxd
+++ b/util/generic/string.pxd
@@ -6,9 +6,9 @@ cdef extern from "<util/generic/strbuf.h>" nogil:
TStringBuf() except +
TStringBuf(const char*) except +
TStringBuf(const char*, size_t) except +
- const char* data()
+ const char* data()
char* Data()
- size_t size()
+ size_t size()
size_t Size()
diff --git a/util/generic/string_ut.pyx b/util/generic/string_ut.pyx
index c7428f857a..5407f5b4c1 100644
--- a/util/generic/string_ut.pyx
+++ b/util/generic/string_ut.pyx
@@ -1,14 +1,14 @@
-# cython: c_string_type=str, c_string_encoding=utf8
-
+# cython: c_string_type=str, c_string_encoding=utf8
+
from libcpp.string cimport string as std_string
from util.generic.string cimport TString, npos
import pytest
import unittest
-import sys
+import sys
+
-
class TestStroka(unittest.TestCase):
def test_unicode(self):
cdef TString x = "привет"
@@ -18,38 +18,38 @@ class TestStroka(unittest.TestCase):
def test_ctor1(self):
cdef TString tmp = TString()
cdef TString tmp2 = TString(tmp)
- self.assertEquals(tmp2, "")
+ self.assertEquals(tmp2, "")
def test_ctor2(self):
cdef std_string tmp = b"hello"
cdef TString tmp2 = TString(tmp)
- self.assertEquals(tmp2, "hello")
+ self.assertEquals(tmp2, "hello")
def test_ctor3(self):
cdef TString tmp = b"hello"
cdef TString tmp2 = TString(tmp, 0, 4)
- self.assertEquals(tmp2, "hell")
+ self.assertEquals(tmp2, "hell")
def test_ctor4(self):
cdef TString tmp = TString(<char*>b"hello")
- self.assertEquals(tmp, "hello")
+ self.assertEquals(tmp, "hello")
def test_ctor5(self):
cdef TString tmp = TString(<char*>b"hello", 4)
- self.assertEquals(tmp, "hell")
+ self.assertEquals(tmp, "hell")
def test_ctor6(self):
cdef TString tmp = TString(<char*>b"hello", 1, 3)
- self.assertEquals(tmp, "ell")
+ self.assertEquals(tmp, "ell")
def test_ctor7(self):
cdef TString tmp = TString(3, <char>'x')
- self.assertEquals(tmp, "xxx")
+ self.assertEquals(tmp, "xxx")
def test_ctor8(self):
cdef bytes tmp = b"hello"
cdef TString tmp2 = TString(<char*>tmp, <char*>tmp + 4)
- self.assertEquals(tmp2, "hell")
+ self.assertEquals(tmp2, "hell")
def test_compare(self):
cdef TString tmp1 = b"abacab"
@@ -72,18 +72,18 @@ class TestStroka(unittest.TestCase):
def test_operator_assign(self):
cdef TString tmp = b"hello"
cdef TString tmp2 = tmp
- self.assertEquals(tmp2, "hello")
+ self.assertEquals(tmp2, "hello")
def test_operator_plus(self):
cdef TString tmp = TString(b"hello ") + TString(b"world")
- self.assertEquals(tmp, "hello world")
+ self.assertEquals(tmp, "hello world")
def test_c_str(self):
cdef TString tmp = b"hello"
- if sys.version_info.major == 2:
- self.assertEquals(bytes(tmp.c_str()), b"hello")
- else:
- self.assertEquals(bytes(tmp.c_str(), 'utf8'), b"hello")
+ if sys.version_info.major == 2:
+ self.assertEquals(bytes(tmp.c_str()), b"hello")
+ else:
+ self.assertEquals(bytes(tmp.c_str(), 'utf8'), b"hello")
def test_length(self):
cdef TString tmp = b"hello"
@@ -107,70 +107,70 @@ class TestStroka(unittest.TestCase):
cdef TString tmp2 = b"fuu"
tmp.append(tmp2)
- self.assertEquals(tmp, "fuu")
+ self.assertEquals(tmp, "fuu")
tmp.append(tmp2, 1, 2)
- self.assertEquals(tmp, "fuuuu")
+ self.assertEquals(tmp, "fuuuu")
tmp.append(<char*>"ll ")
- self.assertEquals(tmp, "fuuuull ")
+ self.assertEquals(tmp, "fuuuull ")
tmp.append(<char*>"of greatness", 4)
- self.assertEquals(tmp, "fuuuull of g")
+ self.assertEquals(tmp, "fuuuull of g")
tmp.append(2, <char>b'o')
- self.assertEquals(tmp, "fuuuull of goo")
+ self.assertEquals(tmp, "fuuuull of goo")
tmp.push_back(b'z')
- self.assertEquals(tmp, "fuuuull of gooz")
+ self.assertEquals(tmp, "fuuuull of gooz")
def test_assign(self):
cdef TString tmp
tmp.assign(b"one")
- self.assertEquals(tmp, "one")
+ self.assertEquals(tmp, "one")
tmp.assign(b"two hundred", 0, 3)
- self.assertEquals(tmp, "two")
+ self.assertEquals(tmp, "two")
tmp.assign(<char*>b"three")
- self.assertEquals(tmp, "three")
+ self.assertEquals(tmp, "three")
tmp.assign(<char*>b"three fiddy", 5)
- self.assertEquals(tmp, "three")
+ self.assertEquals(tmp, "three")
def test_insert(self):
cdef TString tmp
tmp = b"xx"
tmp.insert(1, b"foo")
- self.assertEquals(tmp, "xfoox")
+ self.assertEquals(tmp, "xfoox")
tmp = b"xx"
tmp.insert(1, b"haxor", 1, 3)
- self.assertEquals(tmp, "xaxox")
+ self.assertEquals(tmp, "xaxox")
tmp = b"xx"
tmp.insert(1, <char*>b"foo")
- self.assertEquals(tmp, "xfoox")
+ self.assertEquals(tmp, "xfoox")
tmp = b"xx"
tmp.insert(1, <char*>b"foozzy", 3)
- self.assertEquals(tmp, "xfoox")
+ self.assertEquals(tmp, "xfoox")
tmp = b"xx"
tmp.insert(1, 2, <char>b'u')
- self.assertEquals(tmp, "xuux")
+ self.assertEquals(tmp, "xuux")
def test_copy(self):
cdef char buf[16]
cdef TString tmp = b"hello"
tmp.copy(buf, 5, 0)
- self.assertEquals(buf[:5], "hello")
+ self.assertEquals(buf[:5], "hello")
def test_find(self):
cdef TString haystack = b"whole lotta bytes"
- cdef TString needle = "hole"
+ cdef TString needle = "hole"
self.assertEquals(haystack.find(needle), 1)
self.assertEquals(haystack.find(needle, 3), npos)
@@ -221,5 +221,5 @@ class TestStroka(unittest.TestCase):
def test_substr(self):
cdef TString tmp = b"foobar"
- self.assertEquals(tmp.substr(1), "oobar")
- self.assertEquals(tmp.substr(1, 4), "ooba")
+ self.assertEquals(tmp.substr(1), "oobar")
+ self.assertEquals(tmp.substr(1, 4), "ooba")
diff --git a/util/generic/vector_ut.pyx b/util/generic/vector_ut.pyx
index 8bdcf7d16e..904e67733b 100644
--- a/util/generic/vector_ut.pyx
+++ b/util/generic/vector_ut.pyx
@@ -1,5 +1,5 @@
-# cython: c_string_type=str, c_string_encoding=utf8
-
+# cython: c_string_type=str, c_string_encoding=utf8
+
from util.generic.vector cimport TVector
from util.generic.string cimport TString
@@ -42,14 +42,14 @@ class TestVector(unittest.TestCase):
tmp3.push_back(1)
tmp3.push_back(3)
- self.assertEqual(tmp2[1], 2)
- self.assertEqual(tmp3[1], 3)
-
+ self.assertEqual(tmp2[1], 2)
+ self.assertEqual(tmp3[1], 3)
+
tmp3 = tmp2
- self.assertEqual(tmp2[1], 2)
- self.assertEqual(tmp3[1], 2)
-
+ self.assertEqual(tmp2[1], 2)
+ self.assertEqual(tmp3[1], 2)
+
def test_compare(self):
cdef TVector[int] tmp1
tmp1.push_back(1)
diff --git a/util/memory/blob.pxd b/util/memory/blob.pxd
index d71591a198..c68525024a 100644
--- a/util/memory/blob.pxd
+++ b/util/memory/blob.pxd
@@ -1,41 +1,41 @@
-from libcpp cimport bool as bool_t
-
-from util.generic.string cimport TString
-from util.system.types cimport ui8
-
-
-cdef extern from "util/memory/blob.h" nogil:
- cdef cppclass TBlob:
- TBlob()
- TBlob(const TBlob&)
- void Swap(TBlob& r)
- const void* Data() const
- size_t Size() const
- bool_t Empty() const
- bool_t IsNull() const
- const char* AsCharPtr() const
- const unsigned char* AsUnsignedCharPtr() const
- void Drop()
- TBlob SubBlob(size_t len) except +
- TBlob SubBlob(size_t begin, size_t end) except +
- TBlob DeepCopy() except +
-
- @staticmethod
- TBlob NoCopy(const void* data, size_t length) except +
-
- @staticmethod
- TBlob Copy(const void* data, size_t length) except +
-
- @staticmethod
- TBlob FromFile(const TString& path) except +
-
- @staticmethod
- TBlob PrechargedFromFile(const TString& path) except +
-
- @staticmethod
- TBlob FromString(const TString& s) except +
-
- ui8& operator[](size_t) const
- TBlob& operator=(TBlob&)
-
-
+from libcpp cimport bool as bool_t
+
+from util.generic.string cimport TString
+from util.system.types cimport ui8
+
+
+cdef extern from "util/memory/blob.h" nogil:
+ cdef cppclass TBlob:
+ TBlob()
+ TBlob(const TBlob&)
+ void Swap(TBlob& r)
+ const void* Data() const
+ size_t Size() const
+ bool_t Empty() const
+ bool_t IsNull() const
+ const char* AsCharPtr() const
+ const unsigned char* AsUnsignedCharPtr() const
+ void Drop()
+ TBlob SubBlob(size_t len) except +
+ TBlob SubBlob(size_t begin, size_t end) except +
+ TBlob DeepCopy() except +
+
+ @staticmethod
+ TBlob NoCopy(const void* data, size_t length) except +
+
+ @staticmethod
+ TBlob Copy(const void* data, size_t length) except +
+
+ @staticmethod
+ TBlob FromFile(const TString& path) except +
+
+ @staticmethod
+ TBlob PrechargedFromFile(const TString& path) except +
+
+ @staticmethod
+ TBlob FromString(const TString& s) except +
+
+ ui8& operator[](size_t) const
+ TBlob& operator=(TBlob&)
+
+
diff --git a/util/memory/blob_ut.pyx b/util/memory/blob_ut.pyx
index e72ec8f930..2332e6fa20 100644
--- a/util/memory/blob_ut.pyx
+++ b/util/memory/blob_ut.pyx
@@ -1,141 +1,141 @@
-# cython: c_string_type=str, c_string_encoding=utf8
-
-from libcpp.string cimport string as std_string
-from util.generic.string cimport TString
-from util.memory.blob cimport TBlob
-
-import pytest
-import unittest
-
-
-class TestBlob(unittest.TestCase):
- def test_ctor(self):
- cdef TBlob tmp = TBlob()
- cdef TBlob tmp2 = TBlob(tmp)
- self.assertEquals(tmp.Size(), 0)
- self.assertEquals(tmp2.Size(), 0)
-
- def test_empty_data(self):
- cdef TBlob tmp = TBlob()
- self.assertEquals(tmp.Data() == NULL, True)
- self.assertEquals(tmp.AsCharPtr() == NULL, True)
- self.assertEquals(tmp.AsUnsignedCharPtr() == NULL, True)
- self.assertEquals(tmp.Empty(), True)
- self.assertEquals(tmp.IsNull(), True)
-
- def test_empty_is_null(self):
- cdef TBlob tmp = TBlob.NoCopy("", 0)
- self.assertEquals(tmp.Empty(), True)
- self.assertEquals(tmp.IsNull(), False)
-
- def test_data_types(self):
- cdef const char* char_data = TBlob().AsCharPtr()
- cdef const unsigned char* uchar_data = TBlob().AsUnsignedCharPtr()
- cdef const void* void_data = TBlob().Data()
-
- def test_no_copy(self):
- cdef const char* txt = "hello world"
- cdef TBlob tmp = TBlob.NoCopy(txt, len(txt))
- self.assertEquals(tmp.AsCharPtr() - txt, 0)
- self.assertEquals(tmp.Size(), 11)
- self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
- self.assertEquals(tmp.Empty(), False)
- self.assertEquals(tmp.IsNull(), False)
-
- def test_copy(self):
- cdef const char* txt = "hello world"
- cdef TBlob tmp = TBlob.Copy(txt, len(txt))
- self.assertNotEquals(tmp.AsCharPtr() - txt, 0)
- self.assertEquals(tmp.Size(), 11)
- self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
- self.assertEquals(tmp.Empty(), False)
- self.assertEquals(tmp.IsNull(), False)
-
- def test_from_string(self):
- cdef TBlob tmp = TBlob.FromString(TString("hello world"))
- self.assertEquals(tmp.Size(), 11)
- self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
- self.assertEquals(tmp.Empty(), False)
- self.assertEquals(tmp.IsNull(), False)
-
- def test_from_file(self):
- with open("file", "w") as f:
- f.write("hello world")
- cdef TBlob tmp = TBlob.FromFile("file")
- self.assertEquals(tmp.Size(), 11)
- self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
- self.assertEquals(tmp.Empty(), False)
- self.assertEquals(tmp.IsNull(), False)
-
- def test_precharged_from_file(self):
- with open("precharged", "w") as f:
- f.write("hello world")
- cdef TBlob tmp = TBlob.PrechargedFromFile("precharged")
- self.assertEquals(tmp.Size(), 11)
- self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
- self.assertEquals(tmp.Empty(), False)
- self.assertEquals(tmp.IsNull(), False)
-
- def test_swap_drop(self):
- cdef TBlob tmp = TBlob.NoCopy("hello world", 11)
- cdef TBlob tmp2
- tmp2.Swap(tmp)
- self.assertEquals(tmp2.Size(), 11)
- self.assertEquals(tmp.Size(), 0)
- self.assertEquals(tmp2.AsCharPtr()[:tmp2.Size()], "hello world")
- tmp2.Swap(tmp)
- self.assertEquals(tmp2.Size(), 0)
- self.assertEquals(tmp.Size(), 11)
- tmp.Drop()
- self.assertEquals(tmp.Size(), 0)
-
- def test_operator_brackets(self):
- cdef TBlob tmp = TBlob.NoCopy("hello world", 11)
- self.assertEquals(tmp[0], ord('h'))
- self.assertEquals(tmp[1], ord('e'))
- self.assertEquals(tmp[2], ord('l'))
- self.assertEquals(tmp[3], ord('l'))
- self.assertEquals(tmp[4], ord('o'))
- self.assertEquals(tmp[5], ord(' '))
- self.assertEquals(tmp[6], ord('w'))
- self.assertEquals(tmp[7], ord('o'))
- self.assertEquals(tmp[8], ord('r'))
- self.assertEquals(tmp[9], ord('l'))
- self.assertEquals(tmp[10], ord('d'))
-
- def test_operator_equal(self):
- cdef TBlob foo = TBlob.NoCopy("foo", 3)
- cdef TBlob bar = TBlob.NoCopy("bar", 3)
- self.assertEquals(foo.AsCharPtr(), "foo")
- self.assertEquals(bar.AsCharPtr(), "bar")
- bar = foo
- self.assertEquals(foo.AsCharPtr(), "foo")
- self.assertEquals(bar.AsCharPtr(), "foo")
-
- def test_sub_blob(self):
- cdef TBlob tmp = TBlob.NoCopy("hello world", 11)
- self.assertEquals(tmp.SubBlob(0).Size(), 0)
- self.assertEquals(tmp.SubBlob(1).Size(), 1)
- self.assertEquals(tmp.SubBlob(5).Size(), 5)
- self.assertEquals(tmp.AsCharPtr() - tmp.SubBlob(0).AsCharPtr(), 0)
-
- self.assertEquals(tmp.SubBlob(0, 0).Size(), 0)
- self.assertEquals(tmp.SubBlob(0, 1).Size(), 1)
- self.assertEquals(tmp.SubBlob(0, 5).Size(), 5)
- self.assertEquals(tmp.AsCharPtr() - tmp.SubBlob(0, 0).AsCharPtr(), 0)
-
- self.assertEquals(tmp.SubBlob(1, 1).Size(), 0)
- self.assertEquals(tmp.SubBlob(1, 2).Size(), 1)
- self.assertEquals(tmp.SubBlob(1, 6).Size(), 5)
- self.assertEquals(tmp.SubBlob(1, 1).AsCharPtr() - tmp.AsCharPtr(), 1)
-
- with self.assertRaises(Exception):
- tmp.SubBlob(2, 1)
-
- def test_deep_copy(self):
- cdef TBlob tmp = TBlob.NoCopy("hello world", 11)
- cdef TBlob tmp2 = tmp.DeepCopy()
- self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
- self.assertEquals(tmp2.AsCharPtr()[:tmp2.Size()], "hello world")
- self.assertNotEquals(tmp2.AsCharPtr() - tmp.AsCharPtr(), 0)
-
+# cython: c_string_type=str, c_string_encoding=utf8
+
+from libcpp.string cimport string as std_string
+from util.generic.string cimport TString
+from util.memory.blob cimport TBlob
+
+import pytest
+import unittest
+
+
+class TestBlob(unittest.TestCase):
+ def test_ctor(self):
+ cdef TBlob tmp = TBlob()
+ cdef TBlob tmp2 = TBlob(tmp)
+ self.assertEquals(tmp.Size(), 0)
+ self.assertEquals(tmp2.Size(), 0)
+
+ def test_empty_data(self):
+ cdef TBlob tmp = TBlob()
+ self.assertEquals(tmp.Data() == NULL, True)
+ self.assertEquals(tmp.AsCharPtr() == NULL, True)
+ self.assertEquals(tmp.AsUnsignedCharPtr() == NULL, True)
+ self.assertEquals(tmp.Empty(), True)
+ self.assertEquals(tmp.IsNull(), True)
+
+ def test_empty_is_null(self):
+ cdef TBlob tmp = TBlob.NoCopy("", 0)
+ self.assertEquals(tmp.Empty(), True)
+ self.assertEquals(tmp.IsNull(), False)
+
+ def test_data_types(self):
+ cdef const char* char_data = TBlob().AsCharPtr()
+ cdef const unsigned char* uchar_data = TBlob().AsUnsignedCharPtr()
+ cdef const void* void_data = TBlob().Data()
+
+ def test_no_copy(self):
+ cdef const char* txt = "hello world"
+ cdef TBlob tmp = TBlob.NoCopy(txt, len(txt))
+ self.assertEquals(tmp.AsCharPtr() - txt, 0)
+ self.assertEquals(tmp.Size(), 11)
+ self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
+ self.assertEquals(tmp.Empty(), False)
+ self.assertEquals(tmp.IsNull(), False)
+
+ def test_copy(self):
+ cdef const char* txt = "hello world"
+ cdef TBlob tmp = TBlob.Copy(txt, len(txt))
+ self.assertNotEquals(tmp.AsCharPtr() - txt, 0)
+ self.assertEquals(tmp.Size(), 11)
+ self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
+ self.assertEquals(tmp.Empty(), False)
+ self.assertEquals(tmp.IsNull(), False)
+
+ def test_from_string(self):
+ cdef TBlob tmp = TBlob.FromString(TString("hello world"))
+ self.assertEquals(tmp.Size(), 11)
+ self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
+ self.assertEquals(tmp.Empty(), False)
+ self.assertEquals(tmp.IsNull(), False)
+
+ def test_from_file(self):
+ with open("file", "w") as f:
+ f.write("hello world")
+ cdef TBlob tmp = TBlob.FromFile("file")
+ self.assertEquals(tmp.Size(), 11)
+ self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
+ self.assertEquals(tmp.Empty(), False)
+ self.assertEquals(tmp.IsNull(), False)
+
+ def test_precharged_from_file(self):
+ with open("precharged", "w") as f:
+ f.write("hello world")
+ cdef TBlob tmp = TBlob.PrechargedFromFile("precharged")
+ self.assertEquals(tmp.Size(), 11)
+ self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
+ self.assertEquals(tmp.Empty(), False)
+ self.assertEquals(tmp.IsNull(), False)
+
+ def test_swap_drop(self):
+ cdef TBlob tmp = TBlob.NoCopy("hello world", 11)
+ cdef TBlob tmp2
+ tmp2.Swap(tmp)
+ self.assertEquals(tmp2.Size(), 11)
+ self.assertEquals(tmp.Size(), 0)
+ self.assertEquals(tmp2.AsCharPtr()[:tmp2.Size()], "hello world")
+ tmp2.Swap(tmp)
+ self.assertEquals(tmp2.Size(), 0)
+ self.assertEquals(tmp.Size(), 11)
+ tmp.Drop()
+ self.assertEquals(tmp.Size(), 0)
+
+ def test_operator_brackets(self):
+ cdef TBlob tmp = TBlob.NoCopy("hello world", 11)
+ self.assertEquals(tmp[0], ord('h'))
+ self.assertEquals(tmp[1], ord('e'))
+ self.assertEquals(tmp[2], ord('l'))
+ self.assertEquals(tmp[3], ord('l'))
+ self.assertEquals(tmp[4], ord('o'))
+ self.assertEquals(tmp[5], ord(' '))
+ self.assertEquals(tmp[6], ord('w'))
+ self.assertEquals(tmp[7], ord('o'))
+ self.assertEquals(tmp[8], ord('r'))
+ self.assertEquals(tmp[9], ord('l'))
+ self.assertEquals(tmp[10], ord('d'))
+
+ def test_operator_equal(self):
+ cdef TBlob foo = TBlob.NoCopy("foo", 3)
+ cdef TBlob bar = TBlob.NoCopy("bar", 3)
+ self.assertEquals(foo.AsCharPtr(), "foo")
+ self.assertEquals(bar.AsCharPtr(), "bar")
+ bar = foo
+ self.assertEquals(foo.AsCharPtr(), "foo")
+ self.assertEquals(bar.AsCharPtr(), "foo")
+
+ def test_sub_blob(self):
+ cdef TBlob tmp = TBlob.NoCopy("hello world", 11)
+ self.assertEquals(tmp.SubBlob(0).Size(), 0)
+ self.assertEquals(tmp.SubBlob(1).Size(), 1)
+ self.assertEquals(tmp.SubBlob(5).Size(), 5)
+ self.assertEquals(tmp.AsCharPtr() - tmp.SubBlob(0).AsCharPtr(), 0)
+
+ self.assertEquals(tmp.SubBlob(0, 0).Size(), 0)
+ self.assertEquals(tmp.SubBlob(0, 1).Size(), 1)
+ self.assertEquals(tmp.SubBlob(0, 5).Size(), 5)
+ self.assertEquals(tmp.AsCharPtr() - tmp.SubBlob(0, 0).AsCharPtr(), 0)
+
+ self.assertEquals(tmp.SubBlob(1, 1).Size(), 0)
+ self.assertEquals(tmp.SubBlob(1, 2).Size(), 1)
+ self.assertEquals(tmp.SubBlob(1, 6).Size(), 5)
+ self.assertEquals(tmp.SubBlob(1, 1).AsCharPtr() - tmp.AsCharPtr(), 1)
+
+ with self.assertRaises(Exception):
+ tmp.SubBlob(2, 1)
+
+ def test_deep_copy(self):
+ cdef TBlob tmp = TBlob.NoCopy("hello world", 11)
+ cdef TBlob tmp2 = tmp.DeepCopy()
+ self.assertEquals(tmp.AsCharPtr()[:tmp.Size()], "hello world")
+ self.assertEquals(tmp2.AsCharPtr()[:tmp2.Size()], "hello world")
+ self.assertNotEquals(tmp2.AsCharPtr() - tmp.AsCharPtr(), 0)
+
diff --git a/util/stream/output.pxd b/util/stream/output.pxd
index 9e8198167b..2fccc26d9b 100644
--- a/util/stream/output.pxd
+++ b/util/stream/output.pxd
@@ -1,12 +1,12 @@
-from util.generic.string cimport TStringBuf
-
-
-cdef extern from "<util/stream/output.h>" nogil:
- cdef cppclass IOutputStream:
- IOutputStream()
- void Flush() except+
- void Finish() except+
-
- void WriteChar "Write"(char) except+
- void WriteBuf "Write"(const TStringBuf) except+
- void Write(const void*, size_t) except+
+from util.generic.string cimport TStringBuf
+
+
+cdef extern from "<util/stream/output.h>" nogil:
+ cdef cppclass IOutputStream:
+ IOutputStream()
+ void Flush() except+
+ void Finish() except+
+
+ void WriteChar "Write"(char) except+
+ void WriteBuf "Write"(const TStringBuf) except+
+ void Write(const void*, size_t) except+
diff --git a/util/stream/str.pxd b/util/stream/str.pxd
index bfdb071559..76dc16a822 100644
--- a/util/stream/str.pxd
+++ b/util/stream/str.pxd
@@ -1,12 +1,12 @@
-from util.generic.ptr cimport THolder
-from util.generic.string cimport TString, TStringBuf
-from util.stream.output cimport IOutputStream
-
-
-cdef extern from "<util/stream/str.h>" nogil:
- cdef cppclass TStringOutput(IOutputStream):
- TStringOutput() except+
- TStringOutput(TString&) except+
- void Reserve(size_t) except+
-
-ctypedef THolder[TStringOutput] TStringOutputPtr
+from util.generic.ptr cimport THolder
+from util.generic.string cimport TString, TStringBuf
+from util.stream.output cimport IOutputStream
+
+
+cdef extern from "<util/stream/str.h>" nogil:
+ cdef cppclass TStringOutput(IOutputStream):
+ TStringOutput() except+
+ TStringOutput(TString&) except+
+ void Reserve(size_t) except+
+
+ctypedef THolder[TStringOutput] TStringOutputPtr
diff --git a/util/stream/str_ut.pyx b/util/stream/str_ut.pyx
index 17bf222250..2ae617303f 100644
--- a/util/stream/str_ut.pyx
+++ b/util/stream/str_ut.pyx
@@ -1,62 +1,62 @@
-# cython: c_string_type=str, c_string_encoding=utf8
-
-from cython.operator cimport dereference
-
-from util.generic.ptr cimport THolder
-from util.generic.string cimport TString, TStringBuf
-from util.stream.str cimport TStringOutput, TStringOutputPtr
-
-import unittest
-
-
-class TestStringOutput(unittest.TestCase):
- def test_ctor1(self):
- cdef TStringOutput output
-
- def test_ctor2(self):
- cdef TString string
- cdef THolder[TStringOutput] string_output = THolder[TStringOutput](new TStringOutput(string))
-
- def test_write_char(self):
- cdef TString string
- cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string))
-
- self.assertEqual(string, "")
- dereference(string_output.Get()).WriteChar('1')
- self.assertEqual(string, "1")
- dereference(string_output.Get()).WriteChar('2')
- self.assertEqual(string, "12")
- dereference(string_output.Get()).WriteChar('3')
- self.assertEqual(string, "123")
-
- def test_write_void(self):
- cdef TString string
- cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string))
-
- self.assertEqual(string, "")
- dereference(string_output.Get()).Write("1", 1)
- self.assertEqual(string, "1")
- dereference(string_output.Get()).Write("2", 1)
- self.assertEqual(string, "12")
- dereference(string_output.Get()).Write("34", 2)
- self.assertEqual(string, "1234")
-
- def test_write_buf(self):
- cdef TString string
- cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string))
-
- self.assertEqual(string, "")
- dereference(string_output.Get()).WriteBuf(TStringBuf("1"))
- self.assertEqual(string, "1")
- dereference(string_output.Get()).WriteBuf(TStringBuf("2"))
- self.assertEqual(string, "12")
- dereference(string_output.Get()).WriteBuf(TStringBuf("34"))
- self.assertEqual(string, "1234")
-
- def test_reserve(self):
- cdef TString string
- cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string))
- self.assertEqual(string, "")
- dereference(string_output.Get()).Reserve(50)
- self.assertEqual(string, "")
- self.assertLessEqual(50, string.capacity())
+# cython: c_string_type=str, c_string_encoding=utf8
+
+from cython.operator cimport dereference
+
+from util.generic.ptr cimport THolder
+from util.generic.string cimport TString, TStringBuf
+from util.stream.str cimport TStringOutput, TStringOutputPtr
+
+import unittest
+
+
+class TestStringOutput(unittest.TestCase):
+ def test_ctor1(self):
+ cdef TStringOutput output
+
+ def test_ctor2(self):
+ cdef TString string
+ cdef THolder[TStringOutput] string_output = THolder[TStringOutput](new TStringOutput(string))
+
+ def test_write_char(self):
+ cdef TString string
+ cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string))
+
+ self.assertEqual(string, "")
+ dereference(string_output.Get()).WriteChar('1')
+ self.assertEqual(string, "1")
+ dereference(string_output.Get()).WriteChar('2')
+ self.assertEqual(string, "12")
+ dereference(string_output.Get()).WriteChar('3')
+ self.assertEqual(string, "123")
+
+ def test_write_void(self):
+ cdef TString string
+ cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string))
+
+ self.assertEqual(string, "")
+ dereference(string_output.Get()).Write("1", 1)
+ self.assertEqual(string, "1")
+ dereference(string_output.Get()).Write("2", 1)
+ self.assertEqual(string, "12")
+ dereference(string_output.Get()).Write("34", 2)
+ self.assertEqual(string, "1234")
+
+ def test_write_buf(self):
+ cdef TString string
+ cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string))
+
+ self.assertEqual(string, "")
+ dereference(string_output.Get()).WriteBuf(TStringBuf("1"))
+ self.assertEqual(string, "1")
+ dereference(string_output.Get()).WriteBuf(TStringBuf("2"))
+ self.assertEqual(string, "12")
+ dereference(string_output.Get()).WriteBuf(TStringBuf("34"))
+ self.assertEqual(string, "1234")
+
+ def test_reserve(self):
+ cdef TString string
+ cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string))
+ self.assertEqual(string, "")
+ dereference(string_output.Get()).Reserve(50)
+ self.assertEqual(string, "")
+ self.assertLessEqual(50, string.capacity())
diff --git a/util/string/cast_ut.pyx b/util/string/cast_ut.pyx
index c925000f90..88e86ef961 100644
--- a/util/string/cast_ut.pyx
+++ b/util/string/cast_ut.pyx
@@ -1,5 +1,5 @@
-# cython: c_string_type=str, c_string_encoding=utf8
-
+# cython: c_string_type=str, c_string_encoding=utf8
+
from util.string.cast cimport FromString, ToString
import unittest
diff --git a/util/tests/cython/test_folder.py b/util/tests/cython/test_folder.py
index 25c94e6311..ca176ab2a5 100644
--- a/util/tests/cython/test_folder.py
+++ b/util/tests/cython/test_folder.py
@@ -1,12 +1,12 @@
-# -*- coding: utf-8 -*-
-
-from __future__ import print_function, absolute_import, division
-
-from util.folder.path_ut import TestPath
-
-# Test discovery does not work in cython modules.
-# Reexporting test classes here to satisfy pylint and pytest.
-
-__all__ = [
- 'TestPath',
-]
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function, absolute_import, division
+
+from util.folder.path_ut import TestPath
+
+# Test discovery does not work in cython modules.
+# Reexporting test classes here to satisfy pylint and pytest.
+
+__all__ = [
+ 'TestPath',
+]
diff --git a/util/tests/cython/test_generic.py b/util/tests/cython/test_generic.py
index d1f48c17bf..a0d61339cc 100644
--- a/util/tests/cython/test_generic.py
+++ b/util/tests/cython/test_generic.py
@@ -2,10 +2,10 @@
from __future__ import print_function, absolute_import, division
-from util.generic.deque_ut import TestDeque
+from util.generic.deque_ut import TestDeque
from util.generic.hash_ut import TestHash
-from util.generic.hash_set_ut import TestHashSet
-from util.generic.list_ut import TestList
+from util.generic.hash_set_ut import TestHashSet
+from util.generic.list_ut import TestList
from util.generic.maybe_ut import TestMaybe
from util.generic.ptr_ut import TestHolder
from util.generic.string_ut import TestStroka
@@ -16,11 +16,11 @@ from util.string.cast_ut import TestFromString, TestToString
# Reexporting test classes here to satisfy pylint and pytest.
__all__ = [
- 'TestDeque',
+ 'TestDeque',
'TestHash',
- 'TestHashSet',
- 'TestHolder',
- 'TestList',
+ 'TestHashSet',
+ 'TestHolder',
+ 'TestList',
'TestMaybe',
'TestStroka',
'TestVector',
diff --git a/util/tests/cython/test_memory.py b/util/tests/cython/test_memory.py
index 02d00dc422..705f384726 100644
--- a/util/tests/cython/test_memory.py
+++ b/util/tests/cython/test_memory.py
@@ -1,12 +1,12 @@
-# -*- coding: utf-8 -*-
-
-from __future__ import print_function, absolute_import, division
-
-from util.memory.blob_ut import TestBlob
-
-# Test discovery does not work in cython modules.
-# Reexporting test classes here to satisfy pylint and pytest.
-
-__all__ = [
- 'TestBlob',
-]
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function, absolute_import, division
+
+from util.memory.blob_ut import TestBlob
+
+# Test discovery does not work in cython modules.
+# Reexporting test classes here to satisfy pylint and pytest.
+
+__all__ = [
+ 'TestBlob',
+]
diff --git a/util/tests/cython/test_stream.py b/util/tests/cython/test_stream.py
index ff0a052b4c..6abfe1de0d 100644
--- a/util/tests/cython/test_stream.py
+++ b/util/tests/cython/test_stream.py
@@ -1,12 +1,12 @@
-# -*- coding: utf-8 -*-
-
-from __future__ import print_function, absolute_import, division
-
-from util.stream.str_ut import TestStringOutput
-
-# Test discovery does not work in cython modules.
-# Reexporting test classes here to satisfy pylint and pytest.
-
-__all__ = [
- 'TestStringOutput',
-]
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function, absolute_import, division
+
+from util.stream.str_ut import TestStringOutput
+
+# Test discovery does not work in cython modules.
+# Reexporting test classes here to satisfy pylint and pytest.
+
+__all__ = [
+ 'TestStringOutput',
+]
diff --git a/util/tests/cython/ya.make b/util/tests/cython/ya.make
index 231338b6a4..b928c19026 100644
--- a/util/tests/cython/ya.make
+++ b/util/tests/cython/ya.make
@@ -1,4 +1,4 @@
-PY23_TEST()
+PY23_TEST()
OWNER(g:util)
SUBSCRIBER(g:util-subscribers)
@@ -10,9 +10,9 @@ NO_WSHADOW()
PY_SRCS(
NAMESPACE
util
- folder/path_ut.pyx
+ folder/path_ut.pyx
generic/array_ref_ut.pyx
- generic/deque_ut.pyx
+ generic/deque_ut.pyx
generic/maybe_ut.pyx
generic/ptr_ut.pyx
generic/string_ut.pyx
@@ -20,19 +20,19 @@ PY_SRCS(
generic/list_ut.pyx
generic/hash_set_ut.pyx
generic/hash_ut.pyx
- memory/blob_ut.pyx
- stream/str_ut.pyx
+ memory/blob_ut.pyx
+ stream/str_ut.pyx
string/cast_ut.pyx
system/types_ut.pyx
digest/multi_ut.pyx
)
TEST_SRCS(
- test_digest.py
- test_folder.py
+ test_digest.py
+ test_folder.py
test_generic.py
- test_memory.py
- test_stream.py
+ test_memory.py
+ test_stream.py
test_system.py
)