-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for setting environment variables.
Specified as a list of NAME=VALUE lines in the pgfutils.environment configuration option.
- Loading branch information
Showing
16 changed files
with
240 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pgfutils import setup_figure, save | ||
setup_figure() | ||
|
||
import os | ||
|
||
name1 = os.environ.get("name1", "not set") | ||
name2 = os.environ.get("name2", "not set") | ||
|
||
if name1 != "value1": | ||
raise ValueError("Incorrect value ({}) for environment variable name1".format(name1)) | ||
if name2 != "value2": | ||
raise ValueError("Incorrect value ({}) for environment variable name2".format(name2)) | ||
|
||
save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import os | ||
os.environ["name1"] = "original value" | ||
|
||
from pgfutils import setup_figure, save | ||
setup_figure() | ||
|
||
import os | ||
|
||
name1 = os.environ.get("name1", "not set") | ||
name2 = os.environ.get("name2", "not set") | ||
|
||
if name1 != "value1": | ||
raise ValueError("Incorrect value ({}) for environment variable name1".format(name1)) | ||
if name2 != "value2": | ||
raise ValueError("Incorrect value ({}) for environment variable name2".format(name2)) | ||
|
||
save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[pgfutils] | ||
environment= | ||
name1=value1 | ||
name2 = value2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from pgfutils import setup_figure, save | ||
setup_figure() | ||
save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[pgfutils] | ||
environment= | ||
line1=ok | ||
line2 should fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pgfutils import setup_figure, save | ||
setup_figure() | ||
|
||
import os | ||
|
||
name1 = os.environ.get("name1", "not set") | ||
name2 = os.environ.get("name2", "not set") | ||
|
||
if name1 != "value3": | ||
raise ValueError("Incorrect value ({}) for environment variable name1".format(name1)) | ||
if name2 != "value2": | ||
raise ValueError("Incorrect value ({}) for environment variable name2".format(name2)) | ||
|
||
save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pgfutils] | ||
environment= | ||
name1=value1 | ||
name2 = value2 | ||
name1=value3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from pgfutils import setup_figure, add_dependencies, save | ||
setup_figure(width=1, height=1) | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
import os.path | ||
|
||
noise = np.load('noise.npy') | ||
plt.imshow(noise) | ||
plt.colorbar() | ||
|
||
data = np.loadtxt('scatter.csv', delimiter=',', dtype=np.int) | ||
|
||
x = data[:, :3] | ||
y = data[:, 3:] | ||
|
||
plt.scatter(x, y) | ||
|
||
add_dependencies("extra.file") | ||
save() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pgfutils] | ||
environment = | ||
PGFUTILS_TRACK_FILES = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-41, 8, 40, 63, 11, -20 | ||
198, -4, -173, -19, -107, -96 | ||
-127, -137, -19, -49, -65, 79 | ||
302, 116, -23, -22, 23, -65 | ||
-97, 138, -85, -13, 10, -75 | ||
-167, 82, 34, 41, 31, -10 | ||
73, -71, 92, 59, 55, 21 | ||
-18, 268, 11, 101, -57, -1 | ||
101, -41, -58, -34, -63, -19 | ||
2, -80, -146, 31, 18, 65 | ||
54, -3, 23, 45, -5, -36 | ||
63, 76, 199, -3, -21, 58 | ||
-185, -7, -32, -58, -20, -30 | ||
100, 91, 53, 29, -105, 16 | ||
-30, 37, 281, 15, 34, -41 | ||
-146, -204, -37, 12, 9, -77 | ||
22, 78, -34, -2, 68, -100 | ||
-97, 14, -9, -42, 90, -36 | ||
-5, 213, -73, -14, -15, -11 | ||
51, 2, -102, 26, 23, -30 | ||
-13, -30, -242, -30, -27, -45 | ||
-5, -18, 19, -78, 129, 7 | ||
-84, -76, -92, -34, 10, -7 | ||
72, 20, -35, -49, -8, -52 | ||
27, -5, 102, 0, 3, -66 | ||
128, 93, -121, -28, -15, 21 | ||
-77, 11, -150, -15, -18, 72 | ||
-53, -7, -137, 17, 41, 37 | ||
98, -46, 224, -20, -43, 0 | ||
-158, -15, -98, -21, 12, 26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os.path | ||
from .utils import build_figure, clean_dir | ||
import pytest | ||
|
||
srcdir = os.path.join(os.path.normpath(os.path.dirname(__file__)), "sources", "environment") | ||
|
||
|
||
def test_environment_set(): | ||
"""Check environment variables can be set...""" | ||
res = build_figure(os.path.join(srcdir, "check_set"), "basic.py") | ||
assert res.returncode == 0, "Environment variables not set correctly." | ||
clean_dir(srcdir) | ||
|
||
|
||
def test_environment_override(): | ||
"""Check environment variables can override existing ones...""" | ||
res = build_figure(os.path.join(srcdir, "check_set"), "override.py") | ||
assert res.returncode == 0, "Environment variables not set correctly." | ||
clean_dir(srcdir) | ||
|
||
|
||
def test_environment_repeated(): | ||
"""Check the last value of repeated environment variables is used...""" | ||
res = build_figure(os.path.join(srcdir, "repeated"), "basic.py") | ||
assert res.returncode == 0, "Environment variables not set correctly." | ||
clean_dir(srcdir) | ||
|
||
|
||
def test_environment_invalid(): | ||
"""Check invalid environment variable in configuration is rejected...""" | ||
res = build_figure(os.path.join(srcdir, "invalid"), "basic.py") | ||
assert res.returncode != 0, "Configuration not rejected." | ||
assert "Environment variables should be in the form" in res.stderr, "Incorrect message." | ||
clean_dir(srcdir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters