aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/runtime_py3/test
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/python/runtime_py3/test
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/python/runtime_py3/test')
-rw-r--r--library/python/runtime_py3/test/.dist-info/METADATA14
-rw-r--r--library/python/runtime_py3/test/.dist-info/RECORD1
-rw-r--r--library/python/runtime_py3/test/.dist-info/entry_points.txt2
-rw-r--r--library/python/runtime_py3/test/.dist-info/top_level.txt1
-rw-r--r--library/python/runtime_py3/test/canondata/result.json62
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-default_/stderr.txt12
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-default_/stdout.txt2
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_color_/stderr.txt13
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_color_/stdout.txt2
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_verbose_/stderr.txt41
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_verbose_/stdout.txt2
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-default_/stderr.txt12
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-default_/stdout.txt2
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_color_/stderr.txt13
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_color_/stdout.txt2
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_verbose_/stderr.txt41
-rw-r--r--library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_verbose_/stdout.txt2
-rw-r--r--library/python/runtime_py3/test/resources/__init__.py0
-rw-r--r--library/python/runtime_py3/test/resources/foo.txt1
-rw-r--r--library/python/runtime_py3/test/resources/submodule/__init__.py0
-rw-r--r--library/python/runtime_py3/test/resources/submodule/bar.txt1
-rw-r--r--library/python/runtime_py3/test/test_arcadia_source_finder.py317
-rw-r--r--library/python/runtime_py3/test/test_metadata.py44
-rw-r--r--library/python/runtime_py3/test/test_resources.py60
-rw-r--r--library/python/runtime_py3/test/test_traceback.py63
-rw-r--r--library/python/runtime_py3/test/traceback/__main__.py4
-rw-r--r--library/python/runtime_py3/test/traceback/crash.py44
-rw-r--r--library/python/runtime_py3/test/traceback/mod/__init__.py3
-rw-r--r--library/python/runtime_py3/test/traceback/ya.make19
-rw-r--r--library/python/runtime_py3/test/ya.make40
30 files changed, 820 insertions, 0 deletions
diff --git a/library/python/runtime_py3/test/.dist-info/METADATA b/library/python/runtime_py3/test/.dist-info/METADATA
new file mode 100644
index 0000000000..bb36162199
--- /dev/null
+++ b/library/python/runtime_py3/test/.dist-info/METADATA
@@ -0,0 +1,14 @@
+Metadata-Version: 2.1
+Name: foo-bar
+Version: 1.2.3
+Summary:
+Home-page: https://foo.org/
+Author: Foo
+Author-email: foo@ya.com
+License: UNKNOWN
+Platform: any
+Classifier: Development Status :: 4 - Beta
+Classifier: Programming Language :: Python :: 3
+Requires-Python: >=3.8
+Requires-Dist: Werkzeug (>=0.15)
+Requires-Dist: Jinja2 (>=2.10.1)
diff --git a/library/python/runtime_py3/test/.dist-info/RECORD b/library/python/runtime_py3/test/.dist-info/RECORD
new file mode 100644
index 0000000000..dabbbff80d
--- /dev/null
+++ b/library/python/runtime_py3/test/.dist-info/RECORD
@@ -0,0 +1 @@
+foo_bar.py,sha256=0000000000000000000000000000000000000000000,20
diff --git a/library/python/runtime_py3/test/.dist-info/entry_points.txt b/library/python/runtime_py3/test/.dist-info/entry_points.txt
new file mode 100644
index 0000000000..f5e2fd2657
--- /dev/null
+++ b/library/python/runtime_py3/test/.dist-info/entry_points.txt
@@ -0,0 +1,2 @@
+[console_scripts]
+foo_cli = foo_bar:cli
diff --git a/library/python/runtime_py3/test/.dist-info/top_level.txt b/library/python/runtime_py3/test/.dist-info/top_level.txt
new file mode 100644
index 0000000000..d2c068bc6b
--- /dev/null
+++ b/library/python/runtime_py3/test/.dist-info/top_level.txt
@@ -0,0 +1 @@
+foo_bar
diff --git a/library/python/runtime_py3/test/canondata/result.json b/library/python/runtime_py3/test/canondata/result.json
new file mode 100644
index 0000000000..a7d045fc9c
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/result.json
@@ -0,0 +1,62 @@
+{
+ "test_traceback.test_traceback[custom-default]": {
+ "stderr": {
+ "checksum": "6c1a9b47baa51cc6903b85fd43c529b5",
+ "uri": "file://test_traceback.test_traceback_custom-default_/stderr.txt"
+ },
+ "stdout": {
+ "checksum": "e120a1e0b7fdddc8e6b4d4b506403e89",
+ "uri": "file://test_traceback.test_traceback_custom-default_/stdout.txt"
+ }
+ },
+ "test_traceback.test_traceback[custom-ultratb_color]": {
+ "stderr": {
+ "checksum": "048e27049fb8db64bd295b17f505b0ad",
+ "uri": "file://test_traceback.test_traceback_custom-ultratb_color_/stderr.txt"
+ },
+ "stdout": {
+ "checksum": "e120a1e0b7fdddc8e6b4d4b506403e89",
+ "uri": "file://test_traceback.test_traceback_custom-ultratb_color_/stdout.txt"
+ }
+ },
+ "test_traceback.test_traceback[custom-ultratb_verbose]": {
+ "stderr": {
+ "checksum": "e9af42aa3736141d9b67a1652eea412e",
+ "uri": "file://test_traceback.test_traceback_custom-ultratb_verbose_/stderr.txt"
+ },
+ "stdout": {
+ "checksum": "e120a1e0b7fdddc8e6b4d4b506403e89",
+ "uri": "file://test_traceback.test_traceback_custom-ultratb_verbose_/stdout.txt"
+ }
+ },
+ "test_traceback.test_traceback[main-default]": {
+ "stderr": {
+ "checksum": "6c1a9b47baa51cc6903b85fd43c529b5",
+ "uri": "file://test_traceback.test_traceback_main-default_/stderr.txt"
+ },
+ "stdout": {
+ "checksum": "e120a1e0b7fdddc8e6b4d4b506403e89",
+ "uri": "file://test_traceback.test_traceback_main-default_/stdout.txt"
+ }
+ },
+ "test_traceback.test_traceback[main-ultratb_color]": {
+ "stderr": {
+ "checksum": "048e27049fb8db64bd295b17f505b0ad",
+ "uri": "file://test_traceback.test_traceback_main-ultratb_color_/stderr.txt"
+ },
+ "stdout": {
+ "checksum": "e120a1e0b7fdddc8e6b4d4b506403e89",
+ "uri": "file://test_traceback.test_traceback_main-ultratb_color_/stdout.txt"
+ }
+ },
+ "test_traceback.test_traceback[main-ultratb_verbose]": {
+ "stderr": {
+ "checksum": "e9af42aa3736141d9b67a1652eea412e",
+ "uri": "file://test_traceback.test_traceback_main-ultratb_verbose_/stderr.txt"
+ },
+ "stdout": {
+ "checksum": "e120a1e0b7fdddc8e6b4d4b506403e89",
+ "uri": "file://test_traceback.test_traceback_main-ultratb_verbose_/stdout.txt"
+ }
+ }
+} \ No newline at end of file
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-default_/stderr.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-default_/stderr.txt
new file mode 100644
index 0000000000..5eb7da170a
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-default_/stderr.txt
@@ -0,0 +1,12 @@
+Traceback (most recent call last):
+ File "library/python/runtime_py3/test/traceback/crash.py", line 44, in main
+ one()
+ File "library/python/runtime_py3/test/traceback/crash.py", line 12, in one
+ modfunc(two) # aaa
+ File "library/python/runtime_py3/test/traceback/mod/__init__.py", line 3, in modfunc
+ f() # call back to caller
+ File "library/python/runtime_py3/test/traceback/crash.py", line 16, in two
+ three(42)
+ File "library/python/runtime_py3/test/traceback/crash.py", line 20, in three
+ raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
+RuntimeError: Kaboom! I'm dead: 42
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-default_/stdout.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-default_/stdout.txt
new file mode 100644
index 0000000000..2c9793eb14
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-default_/stdout.txt
@@ -0,0 +1,2 @@
+__name__ = library.python.runtime_py3.test.traceback.crash
+__file__ = library/python/runtime_py3/test/traceback/crash.py
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_color_/stderr.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_color_/stderr.txt
new file mode 100644
index 0000000000..9e5a474cbd
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_color_/stderr.txt
@@ -0,0 +1,13 @@
+Traceback (most recent call last):
+ File "library/python/runtime_py3/test/traceback/crash.py", line 44, in main
+ one()
+ File "library/python/runtime_py3/test/traceback/crash.py", line 12, in one
+ modfunc(two) # aaa
+ File "library/python/runtime_py3/test/traceback/mod/__init__.py", line 3, in modfunc
+ f() # call back to caller
+ File "library/python/runtime_py3/test/traceback/crash.py", line 16, in two
+ three(42)
+ File "library/python/runtime_py3/test/traceback/crash.py", line 20, in three
+ raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
+RuntimeError: Kaboom! I'm dead: 42
+
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_color_/stdout.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_color_/stdout.txt
new file mode 100644
index 0000000000..2c9793eb14
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_color_/stdout.txt
@@ -0,0 +1,2 @@
+__name__ = library.python.runtime_py3.test.traceback.crash
+__file__ = library/python/runtime_py3/test/traceback/crash.py
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_verbose_/stderr.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_verbose_/stderr.txt
new file mode 100644
index 0000000000..b0b299ebe6
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_verbose_/stderr.txt
@@ -0,0 +1,41 @@
+---------------------------------------------------------------------------
+RuntimeError Traceback (most recent call last)
+library/python/runtime_py3/test/traceback/crash.py in main()
+ 42 sys.executable = '<traceback test>'
+ 43
+---> 44 one()
+ global one = <function one>
+
+library/python/runtime_py3/test/traceback/crash.py in one()
+ 10
+ 11 def one():
+---> 12 modfunc(two) # aaa
+ global modfunc = <function modfunc>
+ global two = <function two>
+ 13
+ 14
+
+library/python/runtime_py3/test/traceback/mod/__init__.py in modfunc(f=<function two>)
+ 1 def modfunc(f):
+ 2 # lalala
+----> 3 f() # call back to caller
+ f = <function two>
+
+library/python/runtime_py3/test/traceback/crash.py in two()
+ 14
+ 15 def two():
+---> 16 three(42)
+ global three = <function three>
+ 17
+ 18
+
+library/python/runtime_py3/test/traceback/crash.py in three(x=42)
+ 18
+ 19 def three(x):
+---> 20 raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
+ global RuntimeError.format = undefined
+ x = 42
+ 21
+ 22
+
+RuntimeError: Kaboom! I'm dead: 42
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_verbose_/stdout.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_verbose_/stdout.txt
new file mode 100644
index 0000000000..2c9793eb14
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_custom-ultratb_verbose_/stdout.txt
@@ -0,0 +1,2 @@
+__name__ = library.python.runtime_py3.test.traceback.crash
+__file__ = library/python/runtime_py3/test/traceback/crash.py
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-default_/stderr.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-default_/stderr.txt
new file mode 100644
index 0000000000..5eb7da170a
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-default_/stderr.txt
@@ -0,0 +1,12 @@
+Traceback (most recent call last):
+ File "library/python/runtime_py3/test/traceback/crash.py", line 44, in main
+ one()
+ File "library/python/runtime_py3/test/traceback/crash.py", line 12, in one
+ modfunc(two) # aaa
+ File "library/python/runtime_py3/test/traceback/mod/__init__.py", line 3, in modfunc
+ f() # call back to caller
+ File "library/python/runtime_py3/test/traceback/crash.py", line 16, in two
+ three(42)
+ File "library/python/runtime_py3/test/traceback/crash.py", line 20, in three
+ raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
+RuntimeError: Kaboom! I'm dead: 42
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-default_/stdout.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-default_/stdout.txt
new file mode 100644
index 0000000000..2c9793eb14
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-default_/stdout.txt
@@ -0,0 +1,2 @@
+__name__ = library.python.runtime_py3.test.traceback.crash
+__file__ = library/python/runtime_py3/test/traceback/crash.py
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_color_/stderr.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_color_/stderr.txt
new file mode 100644
index 0000000000..9e5a474cbd
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_color_/stderr.txt
@@ -0,0 +1,13 @@
+Traceback (most recent call last):
+ File "library/python/runtime_py3/test/traceback/crash.py", line 44, in main
+ one()
+ File "library/python/runtime_py3/test/traceback/crash.py", line 12, in one
+ modfunc(two) # aaa
+ File "library/python/runtime_py3/test/traceback/mod/__init__.py", line 3, in modfunc
+ f() # call back to caller
+ File "library/python/runtime_py3/test/traceback/crash.py", line 16, in two
+ three(42)
+ File "library/python/runtime_py3/test/traceback/crash.py", line 20, in three
+ raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
+RuntimeError: Kaboom! I'm dead: 42
+
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_color_/stdout.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_color_/stdout.txt
new file mode 100644
index 0000000000..2c9793eb14
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_color_/stdout.txt
@@ -0,0 +1,2 @@
+__name__ = library.python.runtime_py3.test.traceback.crash
+__file__ = library/python/runtime_py3/test/traceback/crash.py
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_verbose_/stderr.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_verbose_/stderr.txt
new file mode 100644
index 0000000000..b0b299ebe6
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_verbose_/stderr.txt
@@ -0,0 +1,41 @@
+---------------------------------------------------------------------------
+RuntimeError Traceback (most recent call last)
+library/python/runtime_py3/test/traceback/crash.py in main()
+ 42 sys.executable = '<traceback test>'
+ 43
+---> 44 one()
+ global one = <function one>
+
+library/python/runtime_py3/test/traceback/crash.py in one()
+ 10
+ 11 def one():
+---> 12 modfunc(two) # aaa
+ global modfunc = <function modfunc>
+ global two = <function two>
+ 13
+ 14
+
+library/python/runtime_py3/test/traceback/mod/__init__.py in modfunc(f=<function two>)
+ 1 def modfunc(f):
+ 2 # lalala
+----> 3 f() # call back to caller
+ f = <function two>
+
+library/python/runtime_py3/test/traceback/crash.py in two()
+ 14
+ 15 def two():
+---> 16 three(42)
+ global three = <function three>
+ 17
+ 18
+
+library/python/runtime_py3/test/traceback/crash.py in three(x=42)
+ 18
+ 19 def three(x):
+---> 20 raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
+ global RuntimeError.format = undefined
+ x = 42
+ 21
+ 22
+
+RuntimeError: Kaboom! I'm dead: 42
diff --git a/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_verbose_/stdout.txt b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_verbose_/stdout.txt
new file mode 100644
index 0000000000..2c9793eb14
--- /dev/null
+++ b/library/python/runtime_py3/test/canondata/test_traceback.test_traceback_main-ultratb_verbose_/stdout.txt
@@ -0,0 +1,2 @@
+__name__ = library.python.runtime_py3.test.traceback.crash
+__file__ = library/python/runtime_py3/test/traceback/crash.py
diff --git a/library/python/runtime_py3/test/resources/__init__.py b/library/python/runtime_py3/test/resources/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/library/python/runtime_py3/test/resources/__init__.py
diff --git a/library/python/runtime_py3/test/resources/foo.txt b/library/python/runtime_py3/test/resources/foo.txt
new file mode 100644
index 0000000000..ba0e162e1c
--- /dev/null
+++ b/library/python/runtime_py3/test/resources/foo.txt
@@ -0,0 +1 @@
+bar \ No newline at end of file
diff --git a/library/python/runtime_py3/test/resources/submodule/__init__.py b/library/python/runtime_py3/test/resources/submodule/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/library/python/runtime_py3/test/resources/submodule/__init__.py
diff --git a/library/python/runtime_py3/test/resources/submodule/bar.txt b/library/python/runtime_py3/test/resources/submodule/bar.txt
new file mode 100644
index 0000000000..1910281566
--- /dev/null
+++ b/library/python/runtime_py3/test/resources/submodule/bar.txt
@@ -0,0 +1 @@
+foo \ No newline at end of file
diff --git a/library/python/runtime_py3/test/test_arcadia_source_finder.py b/library/python/runtime_py3/test/test_arcadia_source_finder.py
new file mode 100644
index 0000000000..ff80d0a0a2
--- /dev/null
+++ b/library/python/runtime_py3/test/test_arcadia_source_finder.py
@@ -0,0 +1,317 @@
+import unittest
+import yaml
+from unittest.mock import patch
+from parameterized import parameterized
+
+import __res as res
+
+
+NAMESPACE_PREFIX = b'py/namespace/'
+TEST_SOURCE_ROOT = '/home/arcadia'
+
+
+class ImporterMocks(object):
+ def __init__(self, mock_fs, mock_resources):
+ self._mock_fs = mock_fs
+ self._mock_resources = mock_resources
+ self._patchers = [
+ patch('__res.iter_keys', wraps=self._iter_keys),
+ patch('__res.__resource.find', wraps=self._resource_find),
+ patch('__res._path_isdir', wraps=self._path_isdir),
+ patch('__res._path_isfile', wraps=self._path_isfile),
+ patch('__res._os.listdir', wraps=self._os_listdir),
+ ]
+ for patcher in self._patchers:
+ patcher.start()
+
+ def stop(self):
+ for patcher in self._patchers:
+ patcher.stop()
+
+ def _iter_keys(self, prefix):
+ assert prefix == NAMESPACE_PREFIX
+ l = len(prefix)
+ for k in self._mock_resources.keys():
+ yield k, k[l:]
+
+ def _resource_find(self, key):
+ return self._mock_resources.get(key)
+
+ def _lookup_mock_fs(self, filename):
+ path = filename.lstrip('/').split('/')
+ curdir = self._mock_fs
+ for item in path:
+ if item in curdir:
+ curdir = curdir[item]
+ else:
+ return None
+ return curdir
+
+ def _path_isfile(self, filename):
+ f = self._lookup_mock_fs(filename)
+ return isinstance(f, str)
+
+ def _path_isdir(self, filename):
+ f = self._lookup_mock_fs(filename)
+ return isinstance(f, dict)
+
+ def _os_listdir(self, dirname):
+ f = self._lookup_mock_fs(dirname)
+ if isinstance(f, dict):
+ return f.keys()
+ else:
+ return []
+
+
+class ArcadiaSourceFinderTestCase(unittest.TestCase):
+ def setUp(self):
+ self.import_mock = ImporterMocks(yaml.safe_load(self._get_mock_fs()), self._get_mock_resources())
+ self.arcadia_source_finder = res.ArcadiaSourceFinder(TEST_SOURCE_ROOT)
+
+ def tearDown(self):
+ self.import_mock.stop()
+
+ def _get_mock_fs(self):
+ raise NotImplementedError()
+
+ def _get_mock_resources(self):
+ raise NotImplementedError()
+
+
+class TestLibraryWithoutNamespace(ArcadiaSourceFinderTestCase):
+ def _get_mock_fs(self):
+ return '''
+ home:
+ arcadia:
+ project:
+ lib:
+ mod1.py: ""
+ package1:
+ mod2.py: ""
+ '''
+
+ def _get_mock_resources(self):
+ return {
+ b'py/namespace/unique_prefix1/project/lib': b'project.lib.',
+ }
+
+ @parameterized.expand([
+ ('project.lib.mod1', b'project/lib/mod1.py'),
+ ('project.lib.package1.mod2', b'project/lib/package1/mod2.py'),
+ ('project.lib.unknown_module', None),
+ ('project.lib', None), # package
+ ])
+ def test_get_module_path(self, module, path):
+ assert path == self.arcadia_source_finder.get_module_path(module)
+
+ @parameterized.expand([
+ ('project.lib.mod1', False),
+ ('project.lib.package1.mod2', False),
+ ('project', True),
+ ('project.lib', True),
+ ('project.lib.package1', True),
+ ])
+ def test_is_packages(self, module, is_package):
+ assert is_package == self.arcadia_source_finder.is_package(module)
+
+ def test_is_package_for_unknown_module(self):
+ self.assertRaises(ImportError, lambda: self.arcadia_source_finder.is_package('project.lib.package2'))
+
+ @parameterized.expand([
+ ('', {
+ ('PFX.project', True),
+ }),
+ ('project.', {
+ ('PFX.lib', True),
+ }),
+ ('project.lib.', {
+ ('PFX.mod1', False),
+ ('PFX.package1', True),
+ }),
+ ('project.lib.package1.', {
+ ('PFX.mod2', False),
+ }),
+ ])
+ def test_iter_modules(self, package_prefix, expected):
+ got = self.arcadia_source_finder.iter_modules(package_prefix, 'PFX.')
+ assert expected == set(got)
+
+ # Check iter_modules() don't crash and return correct result after not existing module was requested
+ def test_iter_modules_after_unknown_module_import(self):
+ self.arcadia_source_finder.get_module_path('project.unknown_module')
+ assert {('lib', True)} == set(self.arcadia_source_finder.iter_modules('project.', ''))
+
+
+class TestLibraryExtendedFromAnotherLibrary(ArcadiaSourceFinderTestCase):
+ def _get_mock_fs(self):
+ return '''
+ home:
+ arcadia:
+ project:
+ lib:
+ mod1.py: ''
+ lib_extension:
+ mod2.py: ''
+ '''
+
+ def _get_mock_resources(self):
+ return {
+ b'py/namespace/unique_prefix1/project/lib': b'project.lib.',
+ b'py/namespace/unique_prefix2/project/lib_extension': b'project.lib.',
+ }
+
+ @parameterized.expand([
+ ('project.lib.mod1', b'project/lib/mod1.py'),
+ ('project.lib.mod2', b'project/lib_extension/mod2.py'),
+ ])
+ def test_get_module_path(self, module, path):
+ assert path == self.arcadia_source_finder.get_module_path(module)
+
+ @parameterized.expand([
+ ('project.lib.', {
+ ('PFX.mod1', False),
+ ('PFX.mod2', False),
+ }),
+ ])
+ def test_iter_modules(self, package_prefix, expected):
+ got = self.arcadia_source_finder.iter_modules(package_prefix, 'PFX.')
+ assert expected == set(got)
+
+
+class TestNamespaceAndTopLevelLibraries(ArcadiaSourceFinderTestCase):
+ def _get_mock_fs(self):
+ return '''
+ home:
+ arcadia:
+ project:
+ ns_lib:
+ mod1.py: ''
+ top_level_lib:
+ mod2.py: ''
+ '''
+
+ def _get_mock_resources(self):
+ return {
+ b'py/namespace/unique_prefix1/project/ns_lib': b'ns.',
+ b'py/namespace/unique_prefix2/project/top_level_lib': b'.',
+ }
+
+ @parameterized.expand([
+ ('ns.mod1', b'project/ns_lib/mod1.py'),
+ ('mod2', b'project/top_level_lib/mod2.py'),
+ ])
+ def test_get_module_path(self, module, path):
+ assert path == self.arcadia_source_finder.get_module_path(module)
+
+ @parameterized.expand([
+ ('ns', True),
+ ('ns.mod1', False),
+ ('mod2', False),
+ ])
+ def test_is_packages(self, module, is_package):
+ assert is_package == self.arcadia_source_finder.is_package(module)
+
+ @parameterized.expand([
+ 'project',
+ 'project.ns_lib',
+ 'project.top_level_lib',
+ ])
+ def test_is_package_for_unknown_modules(self, module):
+ self.assertRaises(ImportError, lambda: self.arcadia_source_finder.is_package(module))
+
+ @parameterized.expand([
+ ('', {
+ ('PFX.ns', True),
+ ('PFX.mod2', False),
+ }),
+ ('ns.', {
+ ('PFX.mod1', False),
+ }),
+ ])
+ def test_iter_modules(self, package_prefix, expected):
+ got = self.arcadia_source_finder.iter_modules(package_prefix, 'PFX.')
+ assert expected == set(got)
+
+
+class TestIgnoreDirectoriesWithYaMakeFile(ArcadiaSourceFinderTestCase):
+ ''' Packages and modules from tests should not be part of pylib namespace '''
+ def _get_mock_fs(self):
+ return '''
+ home:
+ arcadia:
+ contrib:
+ python:
+ pylib:
+ mod1.py: ""
+ tests:
+ conftest.py: ""
+ ya.make: ""
+ '''
+
+ def _get_mock_resources(self):
+ return {
+ b'py/namespace/unique_prefix1/contrib/python/pylib': b'pylib.',
+ }
+
+ def test_get_module_path_for_lib(self):
+ assert b'contrib/python/pylib/mod1.py' == self.arcadia_source_finder.get_module_path('pylib.mod1')
+
+ def test_get_module_for_tests(self):
+ assert self.arcadia_source_finder.get_module_path('pylib.tests.conftest') is None
+
+ def test_is_package_for_tests(self):
+ self.assertRaises(ImportError, lambda: self.arcadia_source_finder.is_package('pylib.tests'))
+
+
+class TestMergingNamespaceAndDirectoryPackages(ArcadiaSourceFinderTestCase):
+ ''' Merge parent package (top level in this test) dirs with namespace dirs (DEVTOOLS-8979) '''
+ def _get_mock_fs(self):
+ return '''
+ home:
+ arcadia:
+ contrib:
+ python:
+ pylint:
+ ya.make: ""
+ pylint:
+ __init__.py: ""
+ patcher:
+ patch.py: ""
+ ya.make: ""
+ '''
+
+ def _get_mock_resources(self):
+ return {
+ b'py/namespace/unique_prefix1/contrib/python/pylint': b'.',
+ b'py/namespace/unique_prefix1/contrib/python/pylint/patcher': b'pylint.',
+ }
+
+ @parameterized.expand([
+ ('pylint.__init__', b'contrib/python/pylint/pylint/__init__.py'),
+ ('pylint.patch', b'contrib/python/pylint/patcher/patch.py'),
+ ])
+ def test_get_module_path(self, module, path):
+ assert path == self.arcadia_source_finder.get_module_path(module)
+
+
+class TestEmptyResources(ArcadiaSourceFinderTestCase):
+ def _get_mock_fs(self):
+ return '''
+ home:
+ arcadia:
+ project:
+ lib:
+ mod1.py: ''
+ '''
+
+ def _get_mock_resources(self):
+ return {}
+
+ def test_get_module_path(self):
+ assert self.arcadia_source_finder.get_module_path('project.lib.mod1') is None
+
+ def test_is_package(self):
+ self.assertRaises(ImportError, lambda: self.arcadia_source_finder.is_package('project'))
+
+ def test_iter_modules(self):
+ assert [] == list(self.arcadia_source_finder.iter_modules('', 'PFX.'))
diff --git a/library/python/runtime_py3/test/test_metadata.py b/library/python/runtime_py3/test/test_metadata.py
new file mode 100644
index 0000000000..686c176468
--- /dev/null
+++ b/library/python/runtime_py3/test/test_metadata.py
@@ -0,0 +1,44 @@
+import importlib.metadata as im
+
+import pytest
+
+
+@pytest.mark.parametrize("name", ("foo-bar", "foo_bar", "Foo-Bar"))
+def test_distribution(name):
+ assert im.distribution(name) is not None
+
+
+def test_unknown_package():
+ with pytest.raises(im.PackageNotFoundError):
+ im.distribution("bar")
+
+
+def test_version():
+ assert im.version("foo-bar") == "1.2.3"
+
+
+def test_metadata():
+ assert im.metadata("foo-bar") is not None
+
+
+def test_files():
+ files = im.files("foo-bar")
+ assert len(files) == 1
+ assert files[0].name == "foo_bar.py"
+ assert files[0].size == 20
+
+
+def test_requires():
+ assert im.requires("foo-bar") == ["Werkzeug (>=0.15)", "Jinja2 (>=2.10.1)"]
+
+
+def test_entry_points():
+ entry_points = im.entry_points()
+ assert "console_scripts" in entry_points
+
+ flg_found = False
+ for entry_point in entry_points["console_scripts"]:
+ if entry_point.name == "foo_cli" and entry_point.value == "foo_bar:cli":
+ flg_found = True
+
+ assert flg_found
diff --git a/library/python/runtime_py3/test/test_resources.py b/library/python/runtime_py3/test/test_resources.py
new file mode 100644
index 0000000000..a269329f42
--- /dev/null
+++ b/library/python/runtime_py3/test/test_resources.py
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+
+import importlib.resources as ir
+
+import pytest
+
+
+@pytest.mark.parametrize("package, resource", (
+ ("resources", "foo.txt"),
+ ("resources.submodule", "bar.txt")
+))
+def test_is_resource_good_path(package, resource):
+ assert ir.is_resource(package, resource)
+
+
+@pytest.mark.parametrize("package, resource", (
+ ("resources", "111.txt"),
+ ("resources.submodule", "222.txt")
+))
+def test_is_resource_missing(package, resource):
+ assert not ir.is_resource(package, resource)
+
+
+def test_is_resource_subresource_directory():
+ # Directories are not resources.
+ assert not ir.is_resource("resources", "submodule")
+
+
+@pytest.mark.parametrize("package, resource, expected", (
+ ("resources", "foo.txt", b"bar"),
+ ("resources.submodule", "bar.txt", b"foo")
+))
+def test_read_binary_good_path(package, resource, expected):
+ assert ir.read_binary(package, resource) == expected
+
+
+def test_read_binary_missing():
+ with pytest.raises(FileNotFoundError):
+ ir.read_binary("resources", "111.txt")
+
+
+@pytest.mark.parametrize("package, resource, expected", (
+ ("resources", "foo.txt", "bar"),
+ ("resources.submodule", "bar.txt", "foo")
+))
+def test_read_text_good_path(package, resource, expected):
+ assert ir.read_text(package, resource) == expected
+
+
+def test_read_text_missing():
+ with pytest.raises(FileNotFoundError):
+ ir.read_text("resources", "111.txt")
+
+
+@pytest.mark.parametrize("package, expected", (
+ ("resources", ["submodule", "foo.txt"]),
+ ("resources.submodule", ["bar.txt"])
+))
+def test_contents_good_path(package, expected):
+ assert sorted(ir.contents(package)) == sorted(expected)
diff --git a/library/python/runtime_py3/test/test_traceback.py b/library/python/runtime_py3/test/test_traceback.py
new file mode 100644
index 0000000000..82087ce98a
--- /dev/null
+++ b/library/python/runtime_py3/test/test_traceback.py
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function, absolute_import, division
+
+import os
+import re
+
+import pytest
+
+import yatest.common as yc
+
+
+def clean_traceback(traceback):
+ traceback = re.sub(br'\033\[(\d|;)+?m', b'', traceback) # strip ANSI codes
+ traceback = re.sub(br' at 0x[0-9a-fA-F]+', b'', traceback) # remove object ids
+ return traceback
+
+
+@pytest.mark.parametrize('mode', [
+ 'default',
+ 'ultratb_color',
+ 'ultratb_verbose',
+])
+@pytest.mark.parametrize('entry_point', [
+ 'main',
+ 'custom',
+])
+def test_traceback(mode, entry_point):
+ tb_tool = yc.build_path('library/python/runtime_py3/test/traceback/traceback')
+ stdout_path = yc.test_output_path('stdout_raw.txt')
+ stderr_path = yc.test_output_path('stderr_raw.txt')
+ filtered_stdout_path = yc.test_output_path('stdout.txt')
+ filtered_stderr_path = yc.test_output_path('stderr.txt')
+
+ env = os.environ.copy()
+ env.pop('PYTHONPATH', None) # Do not let program peek into its sources on filesystem
+ if entry_point == 'custom':
+ env['Y_PYTHON_ENTRY_POINT'] = 'library.python.runtime_py3.test.traceback.crash:main'
+
+ proc = yc.execute(
+ command=[tb_tool, mode],
+ env=env,
+ stdout=stdout_path,
+ stderr=stderr_path,
+ check_exit_code=False,
+ )
+
+ with open(filtered_stdout_path, 'wb') as f:
+ f.write(clean_traceback(proc.std_out))
+
+ with open(filtered_stderr_path, 'wb') as f:
+ f.write(clean_traceback(proc.std_err))
+
+ return {
+ 'stdout': yc.canonical_file(
+ filtered_stdout_path,
+ local=True,
+ ),
+ 'stderr': yc.canonical_file(
+ filtered_stderr_path,
+ local=True,
+ ),
+ }
diff --git a/library/python/runtime_py3/test/traceback/__main__.py b/library/python/runtime_py3/test/traceback/__main__.py
new file mode 100644
index 0000000000..364db169f0
--- /dev/null
+++ b/library/python/runtime_py3/test/traceback/__main__.py
@@ -0,0 +1,4 @@
+from library.python.runtime_py3.test.traceback.crash import main
+
+if __name__ == "__main__":
+ main()
diff --git a/library/python/runtime_py3/test/traceback/crash.py b/library/python/runtime_py3/test/traceback/crash.py
new file mode 100644
index 0000000000..b5e36b3dd4
--- /dev/null
+++ b/library/python/runtime_py3/test/traceback/crash.py
@@ -0,0 +1,44 @@
+import argparse
+import cgitb
+import sys
+import time
+
+from IPython.core import ultratb
+
+from .mod import modfunc
+
+
+def one():
+ modfunc(two) # aaa
+
+
+def two():
+ three(42)
+
+
+def three(x):
+ raise RuntimeError('Kaboom! I\'m dead: {}'.format(x))
+
+
+def main():
+ hooks = {
+ 'default': lambda: sys.excepthook,
+ 'cgitb': lambda: cgitb.Hook(format='text'),
+ 'ultratb_color': lambda: ultratb.ColorTB(ostream=sys.stderr),
+ 'ultratb_verbose': lambda: ultratb.VerboseTB(ostream=sys.stderr),
+ }
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument('hook', choices=sorted(hooks), default='default')
+
+ args = parser.parse_args()
+
+ sys.excepthook = hooks[args.hook]()
+
+ print('__name__ =', __name__)
+ print('__file__ =', __file__)
+
+ time.time = lambda: 1531996624.0 # Freeze time
+ sys.executable = '<traceback test>'
+
+ one()
diff --git a/library/python/runtime_py3/test/traceback/mod/__init__.py b/library/python/runtime_py3/test/traceback/mod/__init__.py
new file mode 100644
index 0000000000..f00843d786
--- /dev/null
+++ b/library/python/runtime_py3/test/traceback/mod/__init__.py
@@ -0,0 +1,3 @@
+def modfunc(f):
+ # lalala
+ f() # call back to caller
diff --git a/library/python/runtime_py3/test/traceback/ya.make b/library/python/runtime_py3/test/traceback/ya.make
new file mode 100644
index 0000000000..b61fe9550b
--- /dev/null
+++ b/library/python/runtime_py3/test/traceback/ya.make
@@ -0,0 +1,19 @@
+PY3_PROGRAM()
+
+OWNER(
+ abodrov
+ borman
+)
+
+PEERDIR(
+ contrib/python/ipython
+)
+
+PY_SRCS(
+ MAIN
+ __main__.py=main
+ crash.py
+ mod/__init__.py
+)
+
+END()
diff --git a/library/python/runtime_py3/test/ya.make b/library/python/runtime_py3/test/ya.make
new file mode 100644
index 0000000000..4ec3db74f5
--- /dev/null
+++ b/library/python/runtime_py3/test/ya.make
@@ -0,0 +1,40 @@
+PY3TEST()
+
+OWNER(
+ abodrov
+ borman
+)
+
+DEPENDS(library/python/runtime_py3/test/traceback)
+
+PEERDIR(
+ contrib/python/parameterized
+ contrib/python/PyYAML
+)
+
+PY_SRCS(
+ TOP_LEVEL
+ resources/__init__.py
+ resources/submodule/__init__.py
+)
+
+TEST_SRCS(
+ test_metadata.py
+ test_resources.py
+ test_traceback.py
+ test_arcadia_source_finder.py
+)
+
+RESOURCE_FILES(
+ PREFIX library/python/runtime_py3/test/
+ .dist-info/METADATA
+ .dist-info/RECORD
+ .dist-info/entry_points.txt
+ .dist-info/top_level.txt
+ resources/foo.txt
+ resources/submodule/bar.txt
+)
+
+END()
+
+RECURSE_FOR_TESTS(traceback)