Skip to content

Commit 37ce17f

Browse files
committed
arelle: Add tests.cli
1 parent c291e5b commit 37ce17f

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

pkgs/development/python-modules/arelle/default.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
callPackage,
23
lib,
34
buildPythonPackage,
45
fetchFromGitHub,
@@ -45,6 +46,12 @@
4546

4647
pytestCheckHook,
4748
boto3,
49+
50+
# self-reference; TODO: use finalAttrs when available for buildPythonPackage
51+
arelle,
52+
53+
# make default package refer to headless tests, so that ofborg builds them
54+
arelle-headless,
4855
}:
4956

5057
buildPythonPackage rec {
@@ -147,6 +154,16 @@ buildPythonPackage rec {
147154
"tests/unit_tests/arelle/test_import.py"
148155
];
149156

157+
passthru.hasGUI = gui;
158+
159+
passthru.tests = {
160+
cli = callPackage ./test-cli.nix { inherit arelle; };
161+
}
162+
# ofborg will find the arelle tests, but not necessarily the headless ones; include those too.
163+
// lib.optionalAttrs gui {
164+
headless = lib.recurseIntoAttrs arelle-headless.tests;
165+
};
166+
150167
meta = {
151168
changelog = "https://github.com/Arelle/Arelle/releases/tag/${src.tag}";
152169
description = "Open source XBRL platform";
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Run with:
2+
# cd nixpkgs
3+
# nix-build -A python3Packages.arelle.passthru.tests.cli
4+
#
5+
# Note: These are uninteresting generated smoke tests to verify basic functionality
6+
{
7+
lib,
8+
runCommand,
9+
arelle,
10+
}:
11+
12+
runCommand "arelle-test-cli${lib.optionalString (!arelle.hasGUI) "-headless"}"
13+
{
14+
nativeBuildInputs = [ arelle ];
15+
}
16+
''
17+
# Set up temporary home directory
18+
export HOME=$(mktemp -d)
19+
20+
# Test basic CLI commands work with proper assertions
21+
arelleCmdLine --version --disablePersistentConfig 2>&1 | grep "Arelle(r) 2.37.59" > /dev/null
22+
arelleCmdLine --help --disablePersistentConfig 2>&1 | grep "Usage: arelleCmdLine \[options\]" > /dev/null
23+
arelleCmdLine --about --disablePersistentConfig 2>&1 | grep "An open source XBRL platform" > /dev/null
24+
25+
${lib.optionalString arelle.hasGUI ''
26+
# Test executables exist and are accessible
27+
if [ -f "${lib.getBin arelle}/bin/arelleGUI" ]; then
28+
test -x "${lib.getBin arelle}/bin/arelleGUI"
29+
fi
30+
''}
31+
32+
# Create a simple but valid XBRL instance for testing validation functionality
33+
cat > test-instance.xbrl << 'EOF'
34+
<?xml version="1.0" encoding="UTF-8"?>
35+
<xbrl xmlns="http://www.xbrl.org/2003/instance"
36+
xmlns:link="http://www.xbrl.org/2003/linkbase"
37+
xmlns:xlink="http://www.w3.org/1999/xlink">
38+
39+
<link:schemaRef xlink:href="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd" xlink:type="simple"/>
40+
41+
<context id="test_context">
42+
<entity>
43+
<identifier scheme="http://example.com/entities">TEST_ENTITY</identifier>
44+
</entity>
45+
<period>
46+
<instant>2023-12-31</instant>
47+
</period>
48+
</context>
49+
50+
</xbrl>
51+
EOF
52+
53+
# Also create a minimal test schema for more comprehensive testing
54+
cat > test-schema.xsd << 'EOF'
55+
<?xml version="1.0" encoding="UTF-8"?>
56+
<schema xmlns="http://www.w3.org/2001/XMLSchema"
57+
xmlns:xbrli="http://www.xbrl.org/2003/instance"
58+
xmlns:link="http://www.xbrl.org/2003/linkbase"
59+
xmlns:xlink="http://www.w3.org/1999/xlink"
60+
xmlns:test="http://example.com/test"
61+
targetNamespace="http://example.com/test"
62+
elementFormDefault="qualified">
63+
64+
<import namespace="http://www.xbrl.org/2003/instance"
65+
schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd"/>
66+
67+
<element name="TestElement" type="xbrli:stringItemType"
68+
substitutionGroup="xbrli:item" xbrli:periodType="instant"/>
69+
70+
</schema>
71+
EOF
72+
73+
# Test XBRL validation functionality
74+
arelleCmdLine \
75+
--file test-instance.xbrl \
76+
--validate \
77+
--disablePersistentConfig \
78+
--internetConnectivity=offline \
79+
--logLevel=info 2>&1 | grep "\[info\] validated in .* secs - .*test-instance.xbrl" > /dev/null
80+
81+
# Test with the built-in empty instance from arelle config
82+
arelleCmdLine \
83+
--file "${arelle}/lib/python3.13/site-packages/arelle/config/empty-instance.xml" \
84+
--validate \
85+
--disablePersistentConfig \
86+
--internetConnectivity=offline \
87+
--logLevel=info 2>&1 | grep "\[info\] validated in .* secs - .*empty-instance.xml" > /dev/null
88+
89+
# Test formula functionality (without running - just checking it loads)
90+
arelleCmdLine \
91+
--file test-instance.xbrl \
92+
--formula=none \
93+
--disablePersistentConfig \
94+
--internetConnectivity=offline 2>&1 | grep "\[info\] loaded in .* secs.*test-instance.xbrl" > /dev/null
95+
96+
# Test facts output functionality
97+
TEMP_DIR=$(mktemp -d)
98+
arelleCmdLine \
99+
--file test-instance.xbrl \
100+
--facts="$TEMP_DIR/test-facts.csv" \
101+
--disablePersistentConfig \
102+
--internetConnectivity=offline 2>&1 | grep "\[info\] loaded in .* secs.*test-instance.xbrl" > /dev/null
103+
104+
# Test schema validation
105+
arelleCmdLine \
106+
--file test-schema.xsd \
107+
--validate \
108+
--disablePersistentConfig \
109+
--internetConnectivity=offline \
110+
--logLevel=info 2>&1 | grep "\[info\] validated in .* secs - .*test-schema.xsd" > /dev/null
111+
112+
# Test disclosure system validation option
113+
arelleCmdLine \
114+
--disclosureSystem=help \
115+
--disablePersistentConfig 2>&1 | grep "Disclosure system choices:" > /dev/null
116+
117+
# Create success marker
118+
touch $out
119+
''

pkgs/top-level/python-packages.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,10 @@ self: super: with self; {
859859

860860
arelle = callPackage ../development/python-modules/arelle { gui = true; };
861861

862-
arelle-headless = callPackage ../development/python-modules/arelle { gui = false; };
862+
arelle-headless = callPackage ../development/python-modules/arelle {
863+
gui = false;
864+
arelle = arelle-headless;
865+
};
863866

864867
aresponses = callPackage ../development/python-modules/aresponses { };
865868

0 commit comments

Comments
 (0)