Skip to content

Commit

Permalink
Test relative call positions
Browse files Browse the repository at this point in the history
Disclaimer:
Participation by NIST in the creation of the documentation of mentioned
software is not intended to imply a recommendation or endorsement by the
National Institute of Standards and Technology, nor is it intended to
imply that any specific software is necessarily the best available for
the purpose.

Signed-off-by: Alex Nelson <[email protected]>
  • Loading branch information
ajnelson-nist committed Dec 18, 2023
1 parent 82918f5 commit df13730
Show file tree
Hide file tree
Showing 41 changed files with 1,100 additions and 8 deletions.
1 change: 1 addition & 0 deletions cdo_local_uuid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def configure() -> None:
env_base_dir_name = os.getenv("CDO_DEMO_NONRANDOM_UUID_BASE")
if env_base_dir_name is None:
return
# _logger.debug("env_base_dir_name = %r.", env_base_dir_name)

base_dir_original_path = pathlib.Path(env_base_dir_name)
if not base_dir_original_path.exists():
Expand Down
4 changes: 2 additions & 2 deletions cdo_local_uuid/py.typed
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Portions of this file contributed by NIST are governed by the following
# statement:
# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ testing =
[options.package_data]
cdo_local_uuid = py.typed

[options.packages.find]
# https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#finding-simple-packages
exclude = tests

[flake8]
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
extend-ignore =
Expand Down
34 changes: 28 additions & 6 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/make -f

# Portions of this file contributed by NIST are governed by the following
# statement:
# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
Expand Down Expand Up @@ -48,10 +48,10 @@ all:
# These check calls are provided in preferred run-order.
check: \
check-mypy \
check-doctest
source venv/bin/activate \
&& pytest \
--log-level=DEBUG
check-doctest \
check-pytest \
check-relativity_to_venv \
check-varying_top_srcdir

check-doctest: \
.venv.done.log
Expand All @@ -65,11 +65,33 @@ check-mypy: \
.venv.done.log
source venv/bin/activate \
&& mypy \
--exclude varying_top_srcdir \
--exclude venv \
--strict \
$(top_srcdir)/cdo_local_uuid \
.

check-pytest: \
.venv.done.log
source venv/bin/activate \
&& pytest \
--ignore relativity_to_venv \
--ignore varying_top_srcdir \
--log-level=DEBUG

check-relativity_to_venv: \
.venv.done.log
$(MAKE) \
PYTHON3=$(PYTHON3) \
--directory relativity_to_venv \
check

check-varying_top_srcdir: \
.venv.done.log
$(MAKE) \
--directory varying_top_srcdir \
check

clean:
@rm -f \
.venv.done.log
Expand Down
11 changes: 11 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
These tests confirm the impact, and mostly non-impact, of the following factors in usage of `cdo-local-uuid`:

* Whether a project's top source directory has an effect on the UUID seeding (e.g. via indepenent Git clones).
- See `varying_top_srcdir/`.
* Whether the called program is installed in a virtual environment, or a standalone script.
- See `relativity_to_venv/editability_*/cdo_example_command/__init__.py` for the former.
- See `varying_top_srcdir/project_*/example.py` for the latter.
* Whether the virtual environment being in the same directory, or not, has an effect on the UUID seeding.
- See `relativity_to_venv/editability_*/dir_1/Makefile` for call examples.

`pytest` scripts confirm when various factors are expected to influence and not influence the UUID seeding.
1 change: 1 addition & 0 deletions tests/relativity_to_venv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.txt
58 changes: 58 additions & 0 deletions tests/relativity_to_venv/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/make -f

# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to Title 17 Section 105 of the
# United States Code, this software is not subject to copyright
# protection within the United States. NIST assumes no responsibility
# whatsoever for its use by other parties, and makes no guarantees,
# expressed or implied, about its quality, reliability, or any other
# characteristic.
#
# We would appreciate acknowledgement if the software is used.

SHELL := /bin/bash

top_srcdir := $(shell cd ../.. ; pwd)

PYTHON3 ?= python3

all: \
all-editability_no \
all-editability_yes

all-editability_no:
$(MAKE) \
--directory editability_no

all-editability_yes:
$(MAKE) \
--directory editability_yes

check: \
all

check: \
all
source $(top_srcdir)/tests/venv/bin/activate \
&& pytest \
--log-level=DEBUG \
--verbose \
test_outputs.py

clean: \
clean-editability_no \
clean-editability_yes

clean-editability_no:
@$(MAKE) \
--directory editability_no \
clean

clean-editability_yes:
@$(MAKE) \
--directory editability_yes \
clean
3 changes: 3 additions & 0 deletions tests/relativity_to_venv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Tests: Virtual environment editability

This directory confirms the editability of a project installed into a virtual environment does not influence programs in the top directory, nor below the top directory. The Python test in this directory confirms generated UUIDs match only when they're expected to, and mismatch in expected cases.
19 changes: 19 additions & 0 deletions tests/relativity_to_venv/editability_no/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/make -f

# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to Title 17 Section 105 of the
# United States Code, this software is not subject to copyright
# protection within the United States. NIST assumes no responsibility
# whatsoever for its use by other parties, and makes no guarantees,
# expressed or implied, about its quality, reliability, or any other
# characteristic.
#
# We would appreciate acknowledgement if the software is used.

installation_editable := no

include ../editability_x.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3

# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to Title 17 Section 105 of the
# United States Code, this software is not subject to copyright
# protection within the United States. NIST assumes no responsibility
# whatsoever for its use by other parties, and makes no guarantees,
# expressed or implied, about its quality, reliability, or any other
# characteristic.
#
# We would appreciate acknowledgement if the software is used.

import logging

import cdo_local_uuid


def main() -> None:
logging.basicConfig(level=logging.DEBUG)
cdo_local_uuid.configure()
print(cdo_local_uuid.local_uuid())


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to Title 17 Section 105 of the
# United States Code, this software is not subject to copyright
# protection within the United States. NIST assumes no responsibility
# whatsoever for its use by other parties, and makes no guarantees,
# expressed or implied, about its quality, reliability, or any other
# characteristic.
#
# We would appreciate acknowledgement if the software is used.

# This file is defined to support PEP 561:
# https://www.python.org/dev/peps/pep-0561/
17 changes: 17 additions & 0 deletions tests/relativity_to_venv/editability_no/dir_1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/make -f

# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to Title 17 Section 105 of the
# United States Code, this software is not subject to copyright
# protection within the United States. NIST assumes no responsibility
# whatsoever for its use by other parties, and makes no guarantees,
# expressed or implied, about its quality, reliability, or any other
# characteristic.
#
# We would appreciate acknowledgement if the software is used.

include ../../editability_x_dir_1.mk
28 changes: 28 additions & 0 deletions tests/relativity_to_venv/editability_no/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[metadata]
name = cdo-example-command
version = 0.0.1
author = Example Developer
author_email = [email protected]
description = Test project
classifiers =
Development Status :: 1 - Planning
Operating System :: OS Independent
Private :: Do Not Upload
Programming Language :: Python :: 3
# Usage of the classifier 'Private :: Do Not Upload' is to confirm that
# the package configuration for cdo-local-uuid is ignoring this test
# project. If it's picked up, PyPI will reject the package, per:
# https://pypi.org/classifiers/

[options]
include_package_data = true
packages = find:
install_requires =
cdo_local_uuid

[options.entry_points]
console_scripts =
cdo_example_command = cdo_example_command:main

[options.package_data]
cdo_example_command = py.typed
20 changes: 20 additions & 0 deletions tests/relativity_to_venv/editability_no/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to Title 17 Section 105 of the
# United States Code, this software is not subject to copyright
# protection within the United States. NIST assumes no responsibility
# whatsoever for its use by other parties, and makes no guarantees,
# expressed or implied, about its quality, reliability, or any other
# characteristic.
#
# We would appreciate acknowledgement if the software is used.

import setuptools

if __name__ == "__main__":
setuptools.setup()
100 changes: 100 additions & 0 deletions tests/relativity_to_venv/editability_x.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/make -f

# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to Title 17 Section 105 of the
# United States Code, this software is not subject to copyright
# protection within the United States. NIST assumes no responsibility
# whatsoever for its use by other parties, and makes no guarantees,
# expressed or implied, about its quality, reliability, or any other
# characteristic.
#
# We would appreciate acknowledgement if the software is used.

# Purpose:
#
# This Makefile is intended to be loaded with the 'include' Make
# directive in one of the editability_*/Makefile files. The variable
# installation_editable is expected to be 'yes' or 'no'.
# https://www.gnu.org/software/make/manual/html_node/Include.html
#
# This file is not intended to be used with Make by itself.
#
# This Makefile confirms that the same command line generates the same
# UUID sequence, and clarifies that redirection of stdout to a differing
# file path is not considered as part of the sequence seed. It also
# recurses into dir_1/ to test different relative positions (pwd, or
# pwd's parent) for CDO_DEMO_NONRANDOM_UUID_BASE.

SHELL := /bin/bash

# NOTE: This top_srcdir is the "real" top source directory, the root
# directory of the cdo-local-uuid repository, for access to the
# cdo_local_uuid project as a local directory.
top_srcdir := $(shell cd ../../.. ; pwd)

PYTHON3 ?= python3

ifeq ($(installation_editable),)
$(error installation_editable undefined ; please define before the Make 'include' directive)
endif
ifeq ($(installation_editable),yes)
editable_flag=--editable
else
editable_flag=
endif

all: \
all-dir_1 \
output_0.txt \
output_1.txt

%.txt: \
.venv.done.log \
cdo_example_command/__init__.py
export CDO_DEMO_NONRANDOM_UUID_BASE="$$(pwd)" \
&& source venv/bin/activate \
&& cdo_example_command \
> _$@
mv _$@ $@

.venv.done.log: \
$(top_srcdir)/setup.cfg \
$(top_srcdir)/setup.py \
setup.cfg \
setup.py
rm -rf venv
$(PYTHON3) -m venv \
venv
source venv/bin/activate \
&& pip install \
--upgrade \
pip \
setuptools \
wheel
source venv/bin/activate \
&& pip install \
$(top_srcdir)
source venv/bin/activate \
&& pip install \
$(editable_flag) \
.
touch $@

all-dir_1: \
.venv.done.log
$(MAKE) \
--directory dir_1

check: \
all

clean:
@rm -f \
.venv.done.log \
*.txt
@rm -rf \
venv
Loading

0 comments on commit df13730

Please sign in to comment.