edq-utils 0.4.2__tar.gz → 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {edq_utils-0.4.2 → edq_utils-0.4.4}/PKG-INFO +2 -1
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/__init__.py +1 -1
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/cli.py +27 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/httpserver.py +4 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/unittest.py +16 -0
- edq_utils-0.4.4/edq/util/git.py +113 -0
- edq_utils-0.4.4/edq/util/git_test.py +29 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/time.py +15 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/PKG-INFO +2 -1
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/SOURCES.txt +2 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/requires.txt +1 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/requirements.txt +1 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/gen_docs.sh +1 -1
- {edq_utils-0.4.2 → edq_utils-0.4.4}/.github/workflows/main.yml +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/.gitignore +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/.mypy.ini +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/.pylintrc +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/LICENSE +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/README.md +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/__main__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/__main__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/config/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/config/__main__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/config/list.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/doc/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/doc/__main__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/doc/update-pdoc-cli.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/__main__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/exchange-server.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/send-exchange.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/verify-exchanges.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/testing/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/testing/__main__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/testing/cli-test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/version.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/clilib/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/clilib/list.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/clilib/model.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/clilib/pdoc.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/argparser.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/argparser_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/config.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/config_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/errors.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/log.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/version.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/cli.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/exchange.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/exchangeserver.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/request.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/request_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/util.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/procedure/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/procedure/verify_exchanges.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/py.typed +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/asserts.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/cli_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/httpserver_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/run.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/serverrunner.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/empty/edq-config.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/simple-1/edq-config.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/simple-2/edq-config.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/value-number/edq-config.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_base.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_config_value_number.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_ignore_config.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_no_config.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_show_origin.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_skip_header.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/help_base.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/platform_skip.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/version_base.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_anchor.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_binary.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_get_params.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_multiple.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_name.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_post_multiple.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_post_params.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_headers.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_jsonresponse_dict.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_jsonresponse_list.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_params.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_post.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_post_params.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_post_urlparams.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_urlparams.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/specialcase_listparams_explicit.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/specialcase_listparams_url.httpex.json +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/files/a.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/files/tiny.png +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/__init__.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/code.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/code_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/constants.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/dirent.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/dirent_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/encoding.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/gzip.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/gzip_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/hash.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/hash_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/json.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/json_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/parse.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/pyimport.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/pyimport_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/reflection.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/base.ipynb +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/base.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/base_with_raise.ipynb +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/base_with_raise.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/simple.ipynb +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/simple.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/time_test.py +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/dependency_links.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/top_level.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/pyproject.toml +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/requirements-dev.txt +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/build_site.sh +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_all.sh +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_lint.sh +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_python_version.sh +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_strict_types.sh +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_types.sh +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/run_tests.sh +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/template/html/css/style.css +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/template/html/favicon.ico +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/template/html/images/favicon.png +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/template/html/index.html +0 -0
- {edq_utils-0.4.2 → edq_utils-0.4.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: edq-utils
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Common utilities used by EduLinq Python projects.
|
|
5
5
|
Author-email: Eriq Augustine <eriq@edulinq.org>
|
|
6
6
|
License: MIT License
|
|
@@ -34,6 +34,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
34
34
|
Requires-Python: >=3.9
|
|
35
35
|
Description-Content-Type: text/markdown
|
|
36
36
|
License-File: LICENSE
|
|
37
|
+
Requires-Dist: GitPython>=3.1.31
|
|
37
38
|
Requires-Dist: beautifulsoup4>=4.10.0
|
|
38
39
|
Requires-Dist: json5>=0.9.14
|
|
39
40
|
Requires-Dist: platformdirs
|
|
@@ -14,6 +14,7 @@ then this method will be called with the test info right after the test info is
|
|
|
14
14
|
|
|
15
15
|
If a test class implements a class method with the signature `get_test_basename(cls, path: str) -> str`,
|
|
16
16
|
then this method will be called to create the base name for the test case at the given path.
|
|
17
|
+
Otherwise, the file's basename will be used.
|
|
17
18
|
|
|
18
19
|
The expected output or any argument can reference the test's current temp or data dirs with `__TEMP_DIR__()` or `__DATA_DIR__()`, respectively.
|
|
19
20
|
An optional slash-separated path can be used as an argument to reference a path within those base directories.
|
|
@@ -282,6 +283,32 @@ def replace_path_pattern(text: str, key: str, target_dir: str, normalize_path: b
|
|
|
282
283
|
|
|
283
284
|
return text
|
|
284
285
|
|
|
286
|
+
def compute_ancestor_basename(path: str, cli_tests_dir: str) -> str:
|
|
287
|
+
"""
|
|
288
|
+
Get the test's name based off of its filename and location.
|
|
289
|
+
A useful fuction to use in get_test_basename().
|
|
290
|
+
"""
|
|
291
|
+
|
|
292
|
+
path = os.path.abspath(path)
|
|
293
|
+
|
|
294
|
+
name = os.path.splitext(os.path.basename(path))[0]
|
|
295
|
+
|
|
296
|
+
# Clean drive identifiers (for Windows).
|
|
297
|
+
cli_tests_dir_path = os.path.splitdrive(os.path.abspath(cli_tests_dir))[1]
|
|
298
|
+
path = os.path.splitdrive(path)[1]
|
|
299
|
+
|
|
300
|
+
ancestors = os.path.dirname(path).replace(cli_tests_dir_path, '')
|
|
301
|
+
prefix = ancestors.replace(os.sep, '_')
|
|
302
|
+
|
|
303
|
+
if (prefix.startswith('_')):
|
|
304
|
+
prefix = prefix.replace('_', '', 1)
|
|
305
|
+
|
|
306
|
+
if (len(prefix) > 0):
|
|
307
|
+
name = f"{prefix}_{name}"
|
|
308
|
+
|
|
309
|
+
return name
|
|
310
|
+
|
|
311
|
+
|
|
285
312
|
def _get_test_method(test_name: str, path: str, data_dir: str) -> typing.Callable:
|
|
286
313
|
""" Get a test method that represents the test case at the given path. """
|
|
287
314
|
|
|
@@ -49,6 +49,8 @@ class HTTPServerTest(edq.testing.unittest.BaseTest):
|
|
|
49
49
|
|
|
50
50
|
@classmethod
|
|
51
51
|
def setUpClass(cls) -> None:
|
|
52
|
+
super().setUpClass()
|
|
53
|
+
|
|
52
54
|
if (not cls._child_class_setup_called):
|
|
53
55
|
cls.child_class_setup()
|
|
54
56
|
cls._child_class_setup_called = True
|
|
@@ -65,6 +67,8 @@ class HTTPServerTest(edq.testing.unittest.BaseTest):
|
|
|
65
67
|
|
|
66
68
|
@classmethod
|
|
67
69
|
def tearDownClass(cls) -> None:
|
|
70
|
+
super().tearDownClass()
|
|
71
|
+
|
|
68
72
|
if (cls.server_key not in cls._servers):
|
|
69
73
|
return
|
|
70
74
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import datetime
|
|
1
2
|
import typing
|
|
2
3
|
import unittest
|
|
3
4
|
|
|
4
5
|
import edq.util.dirent
|
|
5
6
|
import edq.util.json
|
|
6
7
|
import edq.util.reflection
|
|
8
|
+
import edq.util.time
|
|
7
9
|
|
|
8
10
|
FORMAT_STR: str = "\n--- Expected ---\n%s\n--- Actual ---\n%s\n---\n"
|
|
9
11
|
|
|
@@ -15,6 +17,20 @@ class BaseTest(unittest.TestCase):
|
|
|
15
17
|
maxDiff = None
|
|
16
18
|
""" Don't limit the size of diffs. """
|
|
17
19
|
|
|
20
|
+
testing_timezone: typing.Union[datetime.timezone, None] = edq.util.time.UTC
|
|
21
|
+
|
|
22
|
+
@classmethod
|
|
23
|
+
def setUpClass(cls) -> None:
|
|
24
|
+
super().setUpClass()
|
|
25
|
+
|
|
26
|
+
edq.util.time.set_testing_local_timezone(cls.testing_timezone)
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def tearDownClass(cls) -> None:
|
|
30
|
+
super().tearDownClass()
|
|
31
|
+
|
|
32
|
+
edq.util.time.set_testing_local_timezone(None)
|
|
33
|
+
|
|
18
34
|
def assertJSONEqual(self, a: typing.Any, b: typing.Any, message: typing.Union[str, None] = None) -> None: # pylint: disable=invalid-name
|
|
19
35
|
"""
|
|
20
36
|
Like unittest.TestCase.assertEqual(),
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Handle interfacing with git repos.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import typing
|
|
8
|
+
|
|
9
|
+
import git
|
|
10
|
+
|
|
11
|
+
UNKNOWN_VERSION: str = 'UNKNOWN'
|
|
12
|
+
VERSION_LEN: int = 8
|
|
13
|
+
DIRTY_SIFFIX: str = '-d'
|
|
14
|
+
|
|
15
|
+
def get_version(path: str = '.', throw: bool = False) -> str:
|
|
16
|
+
"""
|
|
17
|
+
Get a version string from the git repo.
|
|
18
|
+
This is just a commit hash with some dressup.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
if (os.path.isfile(path)):
|
|
22
|
+
path = os.path.dirname(path)
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
repo = git.Repo(path, search_parent_directories = True)
|
|
26
|
+
version = repo.head.commit.tree.hexsha[:VERSION_LEN]
|
|
27
|
+
except Exception as ex:
|
|
28
|
+
if (throw):
|
|
29
|
+
raise ValueError(f"Path '{path}' is not a valid Git repo.") from ex
|
|
30
|
+
|
|
31
|
+
return UNKNOWN_VERSION
|
|
32
|
+
|
|
33
|
+
if (repo.is_dirty()):
|
|
34
|
+
version += DIRTY_SIFFIX
|
|
35
|
+
|
|
36
|
+
return version
|
|
37
|
+
|
|
38
|
+
def ensure_repo(
|
|
39
|
+
url: str,
|
|
40
|
+
path: str,
|
|
41
|
+
username: typing.Union[str, None] = None,
|
|
42
|
+
token: typing.Union[str, None] = None,
|
|
43
|
+
update: bool = False,
|
|
44
|
+
ref: typing.Union[str, None] = None,
|
|
45
|
+
) -> None:
|
|
46
|
+
"""
|
|
47
|
+
Ensure that a git repo exists locally.
|
|
48
|
+
Clone the repo if it does not exist.
|
|
49
|
+
Optionally update (pull) the repo.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
if (os.path.isfile(path)):
|
|
53
|
+
raise ValueError(f"Target git path exists and is a file: '{path}'.")
|
|
54
|
+
|
|
55
|
+
if (not os.path.exists(path)):
|
|
56
|
+
clone(url, path, username = username, token = token)
|
|
57
|
+
|
|
58
|
+
repo = get_repo(path)
|
|
59
|
+
|
|
60
|
+
if (update):
|
|
61
|
+
update_repo(repo)
|
|
62
|
+
|
|
63
|
+
if (ref is not None):
|
|
64
|
+
checkout_repo(repo, ref)
|
|
65
|
+
|
|
66
|
+
def get_repo(path: str) -> git.Repo:
|
|
67
|
+
""" Get a reference to a git repo. """
|
|
68
|
+
|
|
69
|
+
return git.Repo(path)
|
|
70
|
+
|
|
71
|
+
def clone(
|
|
72
|
+
url: str,
|
|
73
|
+
path: str,
|
|
74
|
+
username: typing.Union[str, None] = None,
|
|
75
|
+
token: typing.Union[str, None] = None,
|
|
76
|
+
) -> git.Repo:
|
|
77
|
+
""" Clone a git repo to the target location and return a reference to it. """
|
|
78
|
+
|
|
79
|
+
# If we have a username or password, we need to rewrite the URL.
|
|
80
|
+
# This is not very robust, but should work.
|
|
81
|
+
# After clone, the credentials are saved in the local git config.
|
|
82
|
+
if (username is not None):
|
|
83
|
+
if (token is None):
|
|
84
|
+
raise ValueError("If username is specified, a token must also be specified.")
|
|
85
|
+
|
|
86
|
+
auth_text = f"{username}:{token}"
|
|
87
|
+
url = re.sub(r'(http(s?)://)', rf"\1{auth_text}@", url)
|
|
88
|
+
|
|
89
|
+
return git.Repo.clone_from(url, path)
|
|
90
|
+
|
|
91
|
+
def checkout_repo(repo: git.Repo, ref: str) -> None:
|
|
92
|
+
""" Checkout the given reference on the given repo. """
|
|
93
|
+
|
|
94
|
+
repo.git.checkout(ref)
|
|
95
|
+
|
|
96
|
+
def update_repo(repo: git.Repo) -> bool:
|
|
97
|
+
"""
|
|
98
|
+
Update (pull) the given repo.
|
|
99
|
+
Return true if an update occurred.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
fetch_results = repo.remotes.origin.pull()
|
|
103
|
+
|
|
104
|
+
for fetch_result in fetch_results:
|
|
105
|
+
if (fetch_result.ref.name != f"origin/{repo.active_branch.name}"):
|
|
106
|
+
continue
|
|
107
|
+
|
|
108
|
+
if (fetch_result.flags == git.remote.FetchInfo.HEAD_UPTODATE):
|
|
109
|
+
return False
|
|
110
|
+
|
|
111
|
+
return True
|
|
112
|
+
|
|
113
|
+
return False
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import edq.testing.unittest
|
|
4
|
+
import edq.util.dirent
|
|
5
|
+
import edq.util.git
|
|
6
|
+
|
|
7
|
+
THIS_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
|
8
|
+
|
|
9
|
+
class TestGit(edq.testing.unittest.BaseTest):
|
|
10
|
+
""" Test git functionality. """
|
|
11
|
+
|
|
12
|
+
def test_version_in_repo(self):
|
|
13
|
+
""" Test getting a git version inside of a repo. """
|
|
14
|
+
|
|
15
|
+
version = edq.util.git.get_version(THIS_DIR)
|
|
16
|
+
self.assertNotEqual(edq.util.git.UNKNOWN_VERSION, version, 'Got an unknown version (assumes test is run in a repo).')
|
|
17
|
+
|
|
18
|
+
def test_version_cwd(self):
|
|
19
|
+
""" Test getting a git version using the current working directory. """
|
|
20
|
+
|
|
21
|
+
version = edq.util.git.get_version()
|
|
22
|
+
self.assertNotEqual(edq.util.git.UNKNOWN_VERSION, version, 'Got an unknown version (assumes test is run in a repo)')
|
|
23
|
+
|
|
24
|
+
def test_version_not_in_repo(self):
|
|
25
|
+
""" Test getting a git version when not inside of a repo. """
|
|
26
|
+
|
|
27
|
+
path = edq.util.dirent.get_temp_path(prefix = 'edq-test-git-')
|
|
28
|
+
version = edq.util.git.get_version(path)
|
|
29
|
+
self.assertEqual(edq.util.git.UNKNOWN_VERSION, version)
|
|
@@ -24,6 +24,18 @@ UNIXTIME_THRESHOLD_MSECS: int = int(1e13)
|
|
|
24
24
|
UNIXTIME_THRESHOLD_USECS: int = int(1e16)
|
|
25
25
|
""" Epoch time guessing threshold for nanoseconds. """
|
|
26
26
|
|
|
27
|
+
_testing_timezone: typing.Union[datetime.timezone, None] = None # pylint: disable=invalid-name
|
|
28
|
+
""" A timezone to use for testing. """
|
|
29
|
+
|
|
30
|
+
def set_testing_local_timezone(timezone: typing.Union[datetime.timezone, None] = UTC):
|
|
31
|
+
"""
|
|
32
|
+
Force the local timezone to be a specific value (UTC by default).
|
|
33
|
+
This will only affect this package (e.g., the stdlib will not be affected).
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
global _testing_timezone # pylint: disable=global-statement
|
|
37
|
+
_testing_timezone = timezone
|
|
38
|
+
|
|
27
39
|
class Duration(int):
|
|
28
40
|
"""
|
|
29
41
|
A Duration represents some length in time in milliseconds.
|
|
@@ -204,6 +216,9 @@ class Timestamp(int):
|
|
|
204
216
|
def get_local_timezone() -> datetime.timezone:
|
|
205
217
|
""" Get the local (system) timezone or raise an exception. """
|
|
206
218
|
|
|
219
|
+
if (_testing_timezone is not None):
|
|
220
|
+
return _testing_timezone
|
|
221
|
+
|
|
207
222
|
local_timezone = datetime.datetime.now().astimezone().tzinfo
|
|
208
223
|
if ((local_timezone is None) or (not isinstance(local_timezone, datetime.timezone))):
|
|
209
224
|
raise ValueError("Could not discover local timezone.")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: edq-utils
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Common utilities used by EduLinq Python projects.
|
|
5
5
|
Author-email: Eriq Augustine <eriq@edulinq.org>
|
|
6
6
|
License: MIT License
|
|
@@ -34,6 +34,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
34
34
|
Requires-Python: >=3.9
|
|
35
35
|
Description-Content-Type: text/markdown
|
|
36
36
|
License-File: LICENSE
|
|
37
|
+
Requires-Dist: GitPython>=3.1.31
|
|
37
38
|
Requires-Dist: beautifulsoup4>=4.10.0
|
|
38
39
|
Requires-Dist: json5>=0.9.14
|
|
39
40
|
Requires-Dist: platformdirs
|
|
@@ -37,7 +37,7 @@ function main() {
|
|
|
37
37
|
fi
|
|
38
38
|
|
|
39
39
|
# Update the docs with CLI information.
|
|
40
|
-
python3 -m edq.cli.doc.update-pdoc-cli "${PACKAGE_DIR}" "${BASE_PACKAGE}" "${outputDir}"
|
|
40
|
+
NO_COLOR=1 python3 -m edq.cli.doc.update-pdoc-cli "${PACKAGE_DIR}" "${BASE_PACKAGE}" "${outputDir}"
|
|
41
41
|
if [[ $? -ne 0 ]] ; then
|
|
42
42
|
echo "Failed to update docs with CLI information."
|
|
43
43
|
return 3
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/empty/edq-config.json
RENAMED
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/simple-1/edq-config.json
RENAMED
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/simple-2/edq-config.json
RENAMED
|
File without changes
|
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_base.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_anchor.httpex.json
RENAMED
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file.httpex.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_name.httpex.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_headers.httpex.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_params.httpex.json
RENAMED
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_post.httpex.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_urlparams.httpex.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|