Skip to content

Refactor test for comparing output, do not show plots while testing, no default behavior modified #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ repos:
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude: \.json$
- id: trailing-whitespace
- id: check-case-conflict
- id: check-merge-conflict
2 changes: 0 additions & 2 deletions src/diffpy/nmf_mapping/main.py
Original file line number Diff line number Diff line change
@@ -132,8 +132,6 @@ def tup(s):
n_iter=args1.n_iter,
)

print(f"Number of components: {len(df_components.columns)}")

fig1 = nmf.component_plot(df_components, args1.xrd, args1.x_units, args1.show)
fig2 = nmf.component_ratio_plot(df_component_weight_timeseries, args1.show)
fig3 = nmf.reconstruction_error_plot(df_reconstruction_error, args1.show)
2 changes: 1 addition & 1 deletion tests/output/output_1/component_index_vs_RE_value.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"0":{"1":297.2320764418,"2":99.3169152025,"3":0.1930209752,"4":0.1930209752,"5":0.1930209752,"6":0.1930209752,"7":0.1930209752,"8":0.1930209752,"9":0.1930209752,"10":0.1930209752}}
{"0":{"1":297.2320764418,"2":99.3384847868,"3":24.2757958967,"4":8.3941967981,"5":2.4565516346,"6":0.0706811697,"7":0.0703110956,"8":0.0208623408,"9":0.0405341728,"10":0.0089427879}}
2 changes: 1 addition & 1 deletion tests/output/output_1/component_index_vs_pratio_col.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"0":{"0":0.1012347369,"1":0.0761357385,"2":0.8226295245},"1":{"0":0.1010235873,"1":0.0779591956,"2":0.8210172171},"2":{"0":0.0994416662,"1":0.0916204305,"2":0.8089379033},"3":{"0":0.0887636744,"1":0.1838339774,"2":0.7274023482},"4":{"0":0.0474476951,"1":0.5411997046,"2":0.4113526004},"5":{"0":0.0087175609,"1":0.8962651575,"2":0.0950172816},"6":{"0":0.0010510094,"1":0.9857832857,"2":0.0131657049},"7":{"0":0.0037712798,"1":0.9949611562,"2":0.0012675641},"8":{"0":0.0098830598,"1":0.9901169402,"2":0.0},"9":{"0":0.0189903523,"1":0.9810096477,"2":0.0},"10":{"0":0.0316610363,"1":0.9683389637,"2":0.0},"11":{"0":0.0486184937,"1":0.9513815063,"2":0.0},"12":{"0":0.070690848,"1":0.929309152,"2":0.0},"13":{"0":0.0987468127,"1":0.9012531873,"2":0.0},"14":{"0":0.1336502636,"1":0.8663497364,"2":0.0},"15":{"0":0.1761934011,"1":0.8238065989,"2":0.0},"16":{"0":0.2269939584,"1":0.7730060416,"2":0.0},"17":{"0":0.2863470819,"1":0.7136529181,"2":0.0},"18":{"0":0.3540301731,"1":0.6459659981,"2":0.0000038288},"19":{"0":0.4290746918,"1":0.5708935987,"2":0.0000317095},"20":{"0":0.5095924913,"1":0.4903292057,"2":0.000078303},"21":{"0":0.5927003213,"1":0.4071615954,"2":0.0001380833},"22":{"0":0.6746779849,"1":0.3251164016,"2":0.0002056135},"23":{"0":0.7514333455,"1":0.2482910397,"2":0.0002756149},"24":{"0":0.8192174853,"1":0.1804393879,"2":0.0003431268},"25":{"0":0.875377344,"1":0.1242187716,"2":0.0004038844},"26":{"0":0.9188519755,"1":0.0806931319,"2":0.0004548926},"27":{"0":0.9502096756,"1":0.0492958216,"2":0.0004945028},"28":{"0":0.9712444548,"1":0.0282325552,"2":0.00052299},"29":{"0":0.9843478389,"1":0.0151103201,"2":0.000541841},"30":{"0":0.9919161267,"1":0.0075306698,"2":0.0005532035},"31":{"0":0.9959607838,"1":0.0034798433,"2":0.0005593729},"32":{"0":0.9979554044,"1":0.0014823242,"2":0.0005622714},"33":{"0":0.9988599149,"1":0.0005766909,"2":0.0005633941},"34":{"0":0.9992355861,"1":0.0002007286,"2":0.0005636853},"35":{"0":0.9993777604,"1":0.0000584775,"2":0.0005637622},"36":{"0":0.9994265484,"1":0.0000096631,"2":0.0005637886},"37":{"0":0.9994402459,"1":0.0,"2":0.0005597541},"38":{"0":0.9994430456,"1":0.0,"2":0.0005569544},"39":{"0":0.9994437327,"1":0.0,"2":0.0005562673},"40":{"0":0.9994438838,"1":0.0,"2":0.0005561162},"41":{"0":0.9994439131,"1":0.0,"2":0.0005560869},"42":{"0":0.9994439181,"1":0.0,"2":0.0005560819},"43":{"0":0.9994439188,"1":0.0,"2":0.0005560812},"44":{"0":0.9994439189,"1":0.0,"2":0.0005560811},"45":{"0":0.9994439189,"1":0.0,"2":0.0005560811},"46":{"0":0.9994439189,"1":0.0,"2":0.0005560811},"47":{"0":0.9994439189,"1":0.0,"2":0.0005560811},"48":{"0":0.9994439189,"1":0.0,"2":0.0005560811},"49":{"0":0.9994439189,"1":0.0,"2":0.0005560811}}
{"0":{"0":0.0000522102,"1":0.0047576936,"2":0.0,"3":0.013978016,"4":2.807840198e-16,"5":0.9812120802},"1":{"0":0.0026932817,"1":0.0047234755,"2":0.0,"3":0.0138987049,"4":2.79163112e-16,"5":0.9786845379},"2":{"0":0.0218719611,"1":0.0044749936,"2":0.0,"3":0.0133227711,"4":2.673925598e-16,"5":0.9603302742},"3":{"0":0.1283311828,"1":0.0030934526,"2":0.0000010742,"3":0.0101257214,"4":2.020577884e-16,"5":0.858448569},"4":{"0":0.3463450022,"1":0.0002594009,"2":0.0000055822,"3":0.003578409,"4":6.826681601e-17,"5":0.6498116056},"5":{"0":0.4438798167,"1":0.0,"2":0.0,"3":0.0006027121,"4":6.986007417e-18,"5":0.5555174712},"6":{"0":0.458414082,"1":0.0,"2":0.0000804014,"3":0.00007128,"4":0.0,"5":0.5414342366},"7":{"0":0.4557590578,"1":0.0000257648,"2":0.0009928895,"3":0.000007841,"4":2.89218139e-20,"5":0.5432144469},"8":{"0":0.4515252094,"1":0.0022239176,"2":0.0010539824,"3":0.0,"4":7.546948622e-20,"5":0.5451968905},"9":{"0":0.4453515862,"1":0.0055633583,"2":0.0010292212,"3":0.0,"4":9.992771288e-20,"5":0.5480558343},"10":{"0":0.437027719,"1":0.0102497676,"2":0.0009127226,"3":0.0,"4":8.759595553e-20,"5":0.5518097907},"11":{"0":0.4260814555,"1":0.0164357859,"2":0.0007489773,"3":0.0,"4":6.602590379e-20,"5":0.5567337813},"12":{"0":0.411909771,"1":0.0241768588,"2":0.0006101976,"3":0.0000000095,"4":3.589818954e-19,"5":0.5633031632},"13":{"0":0.3941183987,"1":0.0335986428,"2":0.0005382951,"3":0.0000012607,"4":9.371526193e-19,"5":0.5717434027},"14":{"0":0.3726533719,"1":0.0449452339,"2":0.0004572243,"3":0.0000027709,"4":1.659300364e-18,"5":0.581941399},"15":{"0":0.3474540388,"1":0.0582511869,"2":0.0003660714,"3":0.000004544,"4":2.524495998e-18,"5":0.593924159},"16":{"0":0.3186581266,"1":0.0734255207,"2":0.0002703565,"3":0.0000065704,"4":3.549753217e-18,"5":0.6076394258},"17":{"0":0.286697556,"1":0.0902546107,"2":0.0001676698,"3":0.0000088196,"4":4.703044079e-18,"5":0.6228713438},"18":{"0":0.2522925376,"1":0.1083579853,"2":0.0000606662,"3":0.000011241,"4":5.959855632e-18,"5":0.6392775699},"19":{"0":0.2162968729,"1":0.1270965432,"2":0.0000042182,"3":0.0000137761,"4":7.515081733e-18,"5":0.6565885896},"20":{"0":0.1799716664,"1":0.1458021793,"2":0.0000034946,"3":0.0000163362,"4":9.328051553e-18,"5":0.6742063235},"21":{"0":0.1449229934,"1":0.1638502799,"2":0.0000028475,"3":0.0000188064,"4":1.107753121e-17,"5":0.6912050728},"22":{"0":0.1125540137,"1":0.1805184217,"2":0.0000022683,"3":0.0000210877,"4":1.269333204e-17,"5":0.7069042086},"23":{"0":0.0840505879,"1":0.1951959897,"2":0.0000017688,"3":0.0000230965,"4":1.411621706e-17,"5":0.7207285571},"24":{"0":0.0602086759,"1":0.2074731309,"2":0.0000013578,"3":0.0000247769,"4":1.530642959e-17,"5":0.7322920585},"25":{"0":0.0413321706,"1":0.217193372,"2":0.0000010369,"3":0.0000261072,"4":1.62487833e-17,"5":0.7414473132},"26":{"0":0.0272326384,"1":0.2244537553,"2":0.0000007999,"3":0.0000271009,"4":1.695267283e-17,"5":0.7482857055},"27":{"0":0.0173280581,"1":0.229553993,"2":0.0000006351,"3":0.000027799,"4":1.744714517e-17,"5":0.7530895149},"28":{"0":0.0108044458,"1":0.2329132411,"2":0.0000005273,"3":0.0000282588,"4":1.777283103e-17,"5":0.756253527},"29":{"0":0.0067884158,"1":0.2349812414,"2":0.0000004614,"3":0.0000285418,"4":1.797332962e-17,"5":0.7582013395},"30":{"0":0.0044853541,"1":0.2361671714,"2":0.0000004237,"3":0.0000287041,"4":1.808830963e-17,"5":0.7593183467},"31":{"0":0.0032595366,"1":0.2367983891,"2":0.0000004037,"3":0.0000287905,"4":1.81495086e-17,"5":0.7599128801},"32":{"0":0.0026563912,"1":0.2371089704,"2":0.0000003939,"3":0.000028833,"4":1.817962069e-17,"5":0.7602054115},"33":{"0":0.0023832337,"1":0.237249629,"2":0.0000003895,"3":0.0000288523,"4":1.819325812e-17,"5":0.7603378956},"34":{"0":0.0022698927,"1":0.2373079923,"2":0.0000003876,"3":0.0000288603,"4":1.819891669e-17,"5":0.7603928671},"35":{"0":0.0022270164,"1":0.2373300709,"2":0.0000003869,"3":0.0000288633,"4":1.82010573e-17,"5":0.7604136625},"36":{"0":0.0022123041,"1":0.2373376468,"2":0.0000003867,"3":0.0000288643,"4":1.820179181e-17,"5":0.7604207981},"37":{"0":0.0022077493,"1":0.2373399922,"2":0.0000003866,"3":0.0000288646,"4":1.820201921e-17,"5":0.7604230072},"38":{"0":0.002206484,"1":0.2373406437,"2":0.0000003866,"3":0.0000288647,"4":1.820208238e-17,"5":0.7604236209},"39":{"0":0.0022061704,"1":0.2373408052,"2":0.0000003866,"3":0.0000288648,"4":1.820209804e-17,"5":0.760423773},"40":{"0":0.0022061014,"1":0.2373408407,"2":0.0000003866,"3":0.0000288648,"4":1.820210148e-17,"5":0.7604238065},"41":{"0":0.0022060881,"1":0.2373408476,"2":0.0000003866,"3":0.0000288648,"4":1.820210215e-17,"5":0.760423813},"42":{"0":0.0022060858,"1":0.2373408488,"2":0.0000003866,"3":0.0000288648,"4":1.820210226e-17,"5":0.7604238141},"43":{"0":0.0022060855,"1":0.237340849,"2":0.0000003866,"3":0.0000288648,"4":1.820210228e-17,"5":0.7604238142},"44":{"0":0.0022060854,"1":0.237340849,"2":0.0000003866,"3":0.0000288648,"4":1.820210228e-17,"5":0.7604238142},"45":{"0":0.0022060854,"1":0.237340849,"2":0.0000003866,"3":0.0000288648,"4":1.820210228e-17,"5":0.7604238143},"46":{"0":0.0022060854,"1":0.237340849,"2":0.0000003866,"3":0.0000288648,"4":1.820210228e-17,"5":0.7604238143},"47":{"0":0.0022060854,"1":0.237340849,"2":0.0000003866,"3":0.0000288648,"4":1.820210228e-17,"5":0.7604238143},"48":{"0":0.0022060854,"1":0.237340849,"2":0.0000003866,"3":0.0000288648,"4":1.820210228e-17,"5":0.7604238143},"49":{"0":0.0022060854,"1":0.237340849,"2":0.0000003866,"3":0.0000288648,"4":1.820210228e-17,"5":0.7604238143}}
2 changes: 1 addition & 1 deletion tests/output/output_1/x_index_vs_y_col_components.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/output/output_2/component_index_vs_RE_value.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"0":{"1":477.1151575591,"2":181.8950165697,"3":0.5234417462,"4":0.5234417462,"5":0.5234417462,"6":0.5234417462,"7":0.5234417462,"8":0.5234417462,"9":0.5234417462,"10":0.5234417462}}
{"0":{"1":477.1151575591,"2":181.9381472904,"3":3.8968296168,"4":15.4446994529,"5":0.050537146,"6":0.1378804104,"7":0.0095666506,"8":0.0625164884,"9":0.0060391372,"10":0.0309647978}}
2 changes: 1 addition & 1 deletion tests/output/output_2/component_index_vs_pratio_col.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"0":{"0":0.0833641066,"1":0.1035847705,"2":0.8130511229},"1":{"0":0.0832033675,"1":0.1052933866,"2":0.8115032459},"2":{"0":0.0819985332,"1":0.1181004714,"2":0.7999009954},"3":{"0":0.0738387331,"1":0.2048370908,"2":0.7213241761},"4":{"0":0.0418091531,"1":0.5457849786,"2":0.4124058683},"5":{"0":0.0117229038,"1":0.8922342899,"2":0.0960428063},"6":{"0":0.0062914579,"1":0.9807387617,"2":0.0129697804},"7":{"0":0.0094478659,"1":0.9895521985,"2":0.0009999356},"8":{"0":0.0157472415,"1":0.9842527585,"2":0.0},"9":{"0":0.0251902614,"1":0.9748097386,"2":0.0},"10":{"0":0.0383110733,"1":0.9616889267,"2":0.0},"11":{"0":0.0558477803,"1":0.9441522197,"2":0.0},"12":{"0":0.0786353777,"1":0.9213646223,"2":0.0},"13":{"0":0.1075375533,"1":0.8924624467,"2":0.0},"14":{"0":0.143395796,"1":0.856604204,"2":0.0},"15":{"0":0.1869565209,"1":0.8130434791,"2":0.0},"16":{"0":0.2387629405,"1":0.7612370595,"2":0.0},"17":{"0":0.2990046793,"1":0.7009953207,"2":0.0},"18":{"0":0.3673284362,"1":0.6326715638,"2":0.0},"19":{"0":0.4426238536,"1":0.5573542646,"2":0.0000218819},"20":{"0":0.5228655038,"1":0.4770566778,"2":0.0000778185},"21":{"0":0.605104567,"1":0.3947394751,"2":0.0001559579},"22":{"0":0.6856502359,"1":0.3141006976,"2":0.0002490665},"23":{"0":0.7605522499,"1":0.2390988057,"2":0.0003489443},"24":{"0":0.8262912468,"1":0.1732615993,"2":0.0004471539},"25":{"0":0.8804688444,"1":0.1189949496,"2":0.000536206},"26":{"0":0.9222310543,"1":0.0771581706,"2":0.0006107751},"27":{"0":0.9522574732,"1":0.0470736654,"2":0.0006688614},"28":{"0":0.9723545037,"1":0.0269353436,"2":0.0007101528},"29":{"0":0.9848558164,"1":0.0144071384,"2":0.0007370452},"30":{"0":0.9920703172,"1":0.0071767354,"2":0.0007529474},"31":{"0":0.9959243689,"1":0.0033143251,"2":0.000761306},"32":{"0":0.9978246931,"1":0.001410202,"2":0.0007651049},"33":{"0":0.9986864778,"1":0.0005470068,"2":0.0007665154},"34":{"0":0.9990443735,"1":0.0001886853,"2":0.0007669412},"35":{"0":0.9991797847,"1":0.000053113,"2":0.0007671023},"36":{"0":0.9992262515,"1":0.0000065909,"2":0.0007671576},"37":{"0":0.9992366349,"1":0.0,"2":0.0007633651},"38":{"0":0.999238301,"1":0.0,"2":0.000761699},"39":{"0":0.9992387109,"1":0.0,"2":0.0007612891},"40":{"0":0.999238801,"1":0.0,"2":0.000761199},"41":{"0":0.9992388184,"1":0.0,"2":0.0007611816},"42":{"0":0.9992388214,"1":0.0,"2":0.0007611786},"43":{"0":0.9992388218,"1":0.0,"2":0.0007611782},"44":{"0":0.9992388219,"1":0.0,"2":0.0007611781},"45":{"0":0.9992388219,"1":0.0,"2":0.0007611781},"46":{"0":0.9992388219,"1":0.0,"2":0.0007611781},"47":{"0":0.9992388219,"1":0.0,"2":0.0007611781},"48":{"0":0.9992388219,"1":0.0,"2":0.0007611781},"49":{"0":0.9992388219,"1":0.0,"2":0.0007611781}}
{"0":{"0":0.0062011968,"1":0.0,"2":0.0,"3":2.518220297e-16,"4":0.0,"5":0.0,"6":0.0000697061,"7":0.0004626493,"8":0.0119308583,"9":0.9813355895},"1":{"0":0.0076512573,"1":0.0,"2":0.0,"3":2.507813915e-16,"4":0.0,"5":0.0,"6":0.0000739082,"7":0.0004265537,"8":0.0119429019,"9":0.9799053789},"2":{"0":0.0182628758,"1":0.0,"2":0.0,"3":2.431092533e-16,"4":0.0,"5":0.0,"6":0.0001042818,"7":0.0001719625,"8":0.0120039459,"9":0.9694569339},"3":{"0":0.0778442752,"1":0.0,"2":0.0109341895,"3":1.956788276e-16,"4":0.0,"5":0.0,"6":0.0003064126,"7":0.0000080719,"8":0.0097150345,"9":0.9011920164},"4":{"0":0.2239708277,"1":0.0,"2":0.041566808,"3":7.811775638e-17,"4":0.0,"5":0.0,"6":0.0008151248,"7":0.0,"8":0.0033184571,"9":0.7303287824},"5":{"0":0.3035822004,"1":0.0,"2":0.0585520458,"3":1.331108626e-17,"4":0.0,"5":0.000000906,"6":0.0011739464,"7":0.0,"8":0.0001890347,"9":0.6365018666},"6":{"0":0.3178284196,"1":0.0,"2":0.0620363322,"3":1.076262981e-18,"4":0.0,"5":0.0,"6":0.0013107652,"7":0.0,"8":0.0,"9":0.618824483},"7":{"0":0.3159885333,"1":0.0,"2":0.0573463178,"3":0.0,"4":0.0,"5":0.0000571564,"6":0.0015484328,"7":0.0,"8":0.0,"9":0.6250595597},"8":{"0":0.3135144762,"1":0.0,"2":0.0573161228,"3":0.0,"4":0.0,"5":0.0000613973,"6":0.0017553685,"7":0.0,"8":0.0010321357,"9":0.6263204995},"9":{"0":0.310909318,"1":0.0,"2":0.0602393929,"3":4.718281558e-21,"4":0.0,"5":0.0000344768,"6":0.0019921147,"7":0.0,"8":0.002878618,"9":0.6239460797},"10":{"0":0.3071242395,"1":0.0,"2":0.0637910674,"3":9.094520677e-20,"4":0.0,"5":0.000002517,"6":0.0023237302,"7":0.0,"8":0.0053504053,"9":0.6214080406},"11":{"0":0.3004093638,"1":0.0,"2":0.0645165649,"3":5.901476741e-19,"4":0.0,"5":0.0000031519,"6":0.0028382964,"7":0.0,"8":0.008162363,"9":0.62407026},"12":{"0":0.2917766389,"1":0.0,"2":0.0654445577,"3":1.232746965e-18,"4":0.0,"5":0.000004014,"6":0.0034997097,"7":0.0,"8":0.0117759087,"9":0.627499171},"13":{"0":0.2809771012,"1":0.0,"2":0.0666016948,"3":2.036937797e-18,"4":0.0,"5":0.0000051311,"6":0.0043270807,"7":0.0,"8":0.0162953611,"9":0.6317936311},"14":{"0":0.2678062542,"1":0.0,"2":0.0680090511,"3":3.017953544e-18,"4":0.0,"5":0.0000065331,"6":0.0053360702,"7":0.0,"8":0.0218060816,"9":0.6370360097},"15":{"0":0.2521365691,"1":0.0,"2":0.0696790736,"3":4.18535893e-18,"4":0.0,"5":0.0000082459,"6":0.0065364331,"7":0.0,"8":0.0283610988,"9":0.6432785796},"16":{"0":0.2339568071,"1":0.0,"2":0.0716116574,"3":5.540069805e-18,"4":0.0,"5":0.0000102839,"6":0.0079290133,"7":0.0,"8":0.0359647475,"9":0.6505274908},"17":{"0":0.2134154866,"1":0.0,"2":0.0737893642,"3":7.071119366e-18,"4":0.0,"5":0.0000126475,"6":0.0095024125,"7":0.0,"8":0.0445544455,"9":0.6587256437},"18":{"0":0.1908616306,"1":0.0,"2":0.0761724688,"3":8.75265897e-18,"4":0.0,"5":0.0000153246,"6":0.0112298607,"7":0.0,"8":0.0539834762,"9":0.6677372392},"19":{"0":0.1668698935,"1":0.0,"2":0.0786935998,"3":1.054224946e-17,"4":0.0,"5":0.0000183151,"6":0.0130672564,"7":0.0,"8":0.0640097221,"9":0.6773412132},"20":{"0":0.1422263114,"1":0.0,"2":0.0812414326,"3":1.238300885e-17,"4":0.0,"5":0.0000218161,"6":0.0149540232,"7":0.0,"8":0.0742966059,"9":0.6872598107},"21":{"0":0.1156230481,"1":0.0004376275,"2":0.0833474873,"3":1.389898546e-17,"4":0.0,"5":0.0000332299,"6":0.016739263,"7":0.000397017,"8":0.0830232803,"9":0.7003990468},"22":{"0":0.0855136744,"1":0.0005376259,"2":0.0877956416,"3":1.424991439e-17,"4":0.0,"5":0.000041088,"6":0.0182847239,"7":0.0020377177,"8":0.0878292268,"9":0.7179603016},"23":{"0":0.0589113334,"1":0.0006262559,"2":0.0917234596,"3":1.455984244e-17,"4":0.0,"5":0.0000480551,"6":0.0196500167,"7":0.0034875206,"8":0.092073597,"9":0.7334797617},"24":{"0":0.0365954827,"1":0.0007004835,"2":0.0950188836,"3":1.48193513e-17,"4":0.0,"5":0.0000538995,"6":0.0207951406,"7":0.0047041383,"8":0.095632181,"9":0.7464997908},"25":{"0":0.0188859026,"1":0.0007591642,"2":0.0976354299,"3":1.502482635e-17,"4":0.0,"5":0.0000585288,"6":0.0217037645,"7":0.0056700108,"8":0.0984548608,"9":0.7568323384},"26":{"0":0.0056342483,"1":0.0008028662,"2":0.099594516,"3":1.517824685e-17,"4":0.0,"5":0.0000619843,"6":0.0223835847,"7":0.0063930118,"8":0.1005661658,"9":0.764563623},"27":{"0":0.0018387366,"1":0.0007843489,"2":0.0992891328,"3":1.643796741e-17,"4":0.0,"5":0.0000604759,"6":0.0230625369,"7":0.0055445199,"8":0.1061446554,"9":0.7632755935},"28":{"0":0.0017333629,"1":0.0007508053,"2":0.0983392784,"3":1.778870633e-17,"4":0.0,"5":0.0000577671,"6":0.0236052743,"7":0.0043787121,"8":0.1116803681,"9":0.7594544318},"29":{"0":0.0016673739,"1":0.0007300674,"2":0.0977453637,"3":1.863134822e-17,"4":0.0,"5":0.0000560917,"6":0.0239437997,"7":0.0036515087,"8":0.1151330114,"9":0.7570727835},"30":{"0":0.0016288467,"1":0.0007181445,"2":0.0974016833,"3":1.911839009e-17,"4":0.0,"5":0.0000551281,"6":0.0241394614,"7":0.0032312327,"8":0.1171284068,"9":0.7556970964},"31":{"0":0.0016084433,"1":0.0007117849,"2":0.097217754,"3":1.937882708e-17,"4":0.0,"5":0.0000546141,"6":0.024244073,"7":0.0030064895,"8":0.1181953199,"9":0.7549615213},"32":{"0":0.0015983661,"1":0.0007086503,"2":0.0971269901,"3":1.950727315e-17,"4":0.0,"5":0.0000543611,"6":0.0242956653,"7":0.002895651,"8":0.1187214875,"9":0.7545988286},"33":{"0":0.0015939743,"1":0.0007072325,"2":0.0970857888,"3":1.956554422e-17,"4":0.0,"5":0.0000542463,"6":0.0243190622,"7":0.0028453555,"8":0.1189601712,"9":0.7544341693},"34":{"0":0.0015920775,"1":0.0007066431,"2":0.0970687101,"3":1.958971828e-17,"4":0.0,"5":0.0000541986,"6":0.0243287721,"7":0.002824495,"8":0.1190592,"9":0.7543659035},"35":{"0":0.0015913244,"1":0.0007064199,"2":0.0970622544,"3":1.959885854e-17,"4":0.0,"5":0.0000541807,"6":0.0243324451,"7":0.0028166102,"8":0.1190966448,"9":0.7543401204},"36":{"0":0.001591066,"1":0.0007063433,"2":0.0970600391,"3":1.960199509e-17,"4":0.0,"5":0.0000541745,"6":0.0243337055,"7":0.0028139045,"8":0.1191094943,"9":0.7543312728},"37":{"0":0.001590986,"1":0.0007063196,"2":0.0970593532,"3":1.960296616e-17,"4":0.0,"5":0.0000541726,"6":0.0243340957,"7":0.0028130668,"8":0.1191134725,"9":0.7543285336},"38":{"0":0.0015909637,"1":0.0007063131,"2":0.0970591627,"3":1.960323592e-17,"4":0.0,"5":0.0000541721,"6":0.0243342041,"7":0.0028128341,"8":0.1191145777,"9":0.7543277726},"39":{"0":0.0015909582,"1":0.0007063114,"2":0.0970591155,"3":1.960330279e-17,"4":0.0,"5":0.0000541719,"6":0.0243342309,"7":0.0028127764,"8":0.1191148516,"9":0.754327584},"40":{"0":0.001590957,"1":0.0007063111,"2":0.0970591051,"3":1.960331749e-17,"4":0.0,"5":0.0000541719,"6":0.0243342368,"7":0.0028127637,"8":0.1191149118,"9":0.7543275425},"41":{"0":0.0015909568,"1":0.000706311,"2":0.0970591031,"3":1.960332034e-17,"4":0.0,"5":0.0000541719,"6":0.024334238,"7":0.0028127613,"8":0.1191149235,"9":0.7543275345},"42":{"0":0.0015909568,"1":0.000706311,"2":0.0970591027,"3":1.960332082e-17,"4":0.0,"5":0.0000541719,"6":0.0243342382,"7":0.0028127609,"8":0.1191149255,"9":0.7543275331},"43":{"0":0.0015909567,"1":0.000706311,"2":0.0970591027,"3":1.960332089e-17,"4":0.0,"5":0.0000541719,"6":0.0243342382,"7":0.0028127608,"8":0.1191149258,"9":0.7543275329},"44":{"0":0.0015909567,"1":0.000706311,"2":0.0970591027,"3":1.96033209e-17,"4":0.0,"5":0.0000541719,"6":0.0243342382,"7":0.0028127608,"8":0.1191149258,"9":0.7543275329},"45":{"0":0.0015909567,"1":0.000706311,"2":0.0970591027,"3":1.96033209e-17,"4":0.0,"5":0.0000541719,"6":0.0243342382,"7":0.0028127608,"8":0.1191149258,"9":0.7543275329},"46":{"0":0.0015909567,"1":0.000706311,"2":0.0970591027,"3":1.96033209e-17,"4":0.0,"5":0.0000541719,"6":0.0243342382,"7":0.0028127608,"8":0.1191149258,"9":0.7543275329},"47":{"0":0.0015909567,"1":0.000706311,"2":0.0970591027,"3":1.96033209e-17,"4":0.0,"5":0.0000541719,"6":0.0243342382,"7":0.0028127608,"8":0.1191149258,"9":0.7543275329},"48":{"0":0.0015909567,"1":0.000706311,"2":0.0970591027,"3":1.96033209e-17,"4":0.0,"5":0.0000541719,"6":0.0243342382,"7":0.0028127608,"8":0.1191149258,"9":0.7543275329},"49":{"0":0.0015909567,"1":0.000706311,"2":0.0970591027,"3":1.96033209e-17,"4":0.0,"5":0.0000541719,"6":0.0243342382,"7":0.0028127608,"8":0.1191149258,"9":0.7543275329}}
2 changes: 1 addition & 1 deletion tests/output/output_2/x_index_vs_y_col_components.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/output/output_3/component_index_vs_RE_value.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"0":{"1":329.0880682792,"2":115.1656743197,"3":0.259035152,"4":0.259035152,"5":0.259035152,"6":0.259035152,"7":0.259035152,"8":0.259035152,"9":0.259035152,"10":0.259035152}}
{"0":{"1":329.0880682792,"2":115.1948975423,"3":5.8374364027,"4":4.6549850714,"5":0.5182742614,"6":0.9198601895,"7":0.4896964258,"8":0.0451959899,"9":24.3012756712,"10":26.3665515702}}
2 changes: 1 addition & 1 deletion tests/output/output_3/component_index_vs_pratio_col.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"0":{"0":0.1036498399,"1":0.0699584532,"2":0.8263917069},"1":{"0":0.1034423069,"1":0.0717546399,"2":0.8248030531},"2":{"0":0.1018869025,"1":0.0852165828,"2":0.8128965147},"3":{"0":0.0913610782,"1":0.176317033,"2":0.7323218889},"4":{"0":0.0501644906,"1":0.5331610386,"2":0.4166744707},"5":{"0":0.01069995,"1":0.8933788102,"2":0.0959212398},"6":{"0":0.0025693759,"1":0.9846959849,"2":0.0127346391},"7":{"0":0.0051581681,"1":0.9938121418,"2":0.0010296901},"8":{"0":0.0113097072,"1":0.9886902928,"2":0.0},"9":{"0":0.0206264963,"1":0.9793735037,"2":0.0},"10":{"0":0.0335905894,"1":0.9664094106,"2":0.0},"11":{"0":0.0509286895,"1":0.9490713105,"2":0.0},"12":{"0":0.0734740415,"1":0.9265259585,"2":0.0},"13":{"0":0.1020944006,"1":0.8979055994,"2":0.0},"14":{"0":0.1376425472,"1":0.8623574528,"2":0.0},"15":{"0":0.1808855869,"1":0.8191144131,"2":0.0},"16":{"0":0.2323986642,"1":0.7676013358,"2":0.0},"17":{"0":0.2924150226,"1":0.7075849774,"2":0.0},"18":{"0":0.3606342299,"1":0.6393657701,"2":0.0},"19":{"0":0.4360110504,"1":0.5639889496,"2":0.0},"20":{"0":0.5165803523,"1":0.4834196477,"2":0.0},"21":{"0":0.599409524,"1":0.400590476,"2":0.0},"22":{"0":0.6807786951,"1":0.3192147481,"2":0.0000065568},"23":{"0":0.7566586389,"1":0.2433158272,"2":0.0000255338},"24":{"0":0.8234239933,"1":0.176523238,"2":0.0000527687},"25":{"0":0.8785652148,"1":0.1213509256,"2":0.0000838597},"26":{"0":0.9211423993,"1":0.0787432111,"2":0.0001143895},"27":{"0":0.9517928158,"1":0.0480656873,"2":0.000141497},"28":{"0":0.9723239904,"1":0.0275124962,"2":0.0001635134},"29":{"0":0.9851005165,"1":0.0147190347,"2":0.0001804487},"30":{"0":0.9924747464,"1":0.007333179,"2":0.0001920746},"31":{"0":0.9964133888,"1":0.0033869911,"2":0.0001996201},"32":{"0":0.9983546833,"1":0.0014413304,"2":0.0002039864},"33":{"0":0.9992345434,"1":0.0005591905,"2":0.0002062661},"34":{"0":0.9995997592,"1":0.0001929316,"2":0.0002073092},"35":{"0":0.9997379722,"1":0.0000543171,"2":0.0002077107},"36":{"0":0.9997854054,"1":0.0000067477,"2":0.0002078469},"37":{"0":0.9997957027,"1":0.0,"2":0.0002042973},"38":{"0":0.9997973432,"1":0.0,"2":0.0002026568},"39":{"0":0.9997977479,"1":0.0,"2":0.0002022521},"40":{"0":0.9997978368,"1":0.0,"2":0.0002021632},"41":{"0":0.999797854,"1":0.0,"2":0.000202146},"42":{"0":0.9997978569,"1":0.0,"2":0.0002021431},"43":{"0":0.9997978574,"1":0.0,"2":0.0002021426},"44":{"0":0.9997978574,"1":0.0,"2":0.0002021426},"45":{"0":0.9997978574,"1":0.0,"2":0.0002021426},"46":{"0":0.9997978574,"1":0.0,"2":0.0002021426},"47":{"0":0.9997978574,"1":0.0,"2":0.0002021426},"48":{"0":0.9997978574,"1":0.0,"2":0.0002021426},"49":{"0":0.9997978574,"1":0.0,"2":0.0002021426}}
{"0":{"0":0.0168483558,"1":0.117327529,"2":0.0,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.8658241152},"1":{"0":0.0179629734,"1":0.1170146489,"2":0.0,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.8650223778},"2":{"0":0.0262724752,"1":0.1146821194,"2":0.0,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.8590454054},"3":{"0":0.0805258769,"1":0.0994528482,"2":0.0,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.820021275},"4":{"0":0.2555019877,"1":0.0441429394,"2":0.0064862269,"3":0.0073345631,"4":1.146011953e-16,"5":3.546697364e-17,"6":8.140367365e-18,"7":3.231527263e-17,"8":4.990301329e-18,"9":0.6865342829},"5":{"0":0.4061366003,"1":0.0000654218,"2":0.0132761594,"3":0.0003124753,"4":2.346387479e-18,"5":2.896192144e-17,"6":1.213711146e-18,"7":2.770338831e-17,"8":3.260488575e-19,"9":0.5802093432},"6":{"0":0.449054886,"1":0.0,"2":0.0147890624,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.5361560515},"7":{"0":0.4516724924,"1":0.0,"2":0.015230926,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.5330965816},"8":{"0":0.4465301811,"1":0.0,"2":0.0156226071,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.5378472119},"9":{"0":0.4380744452,"1":0.0,"2":0.0161455081,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.5457800467},"10":{"0":0.4264071166,"1":0.0,"2":0.0168538394,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.556739044},"11":{"0":0.4148289826,"1":0.0043123039,"2":0.017697499,"3":0.0004905993,"4":3.474720006e-17,"5":5.777310661e-18,"6":3.34966024e-17,"7":4.447510266e-18,"8":3.152805328e-17,"9":0.5626706152},"12":{"0":0.4011490489,"1":0.0111071105,"2":0.0187456136,"3":0.0014332389,"4":3.953478394e-17,"5":1.111267914e-17,"6":3.906374586e-17,"7":9.685651253e-18,"8":3.549408614e-17,"9":0.5675649881},"13":{"0":0.3841734669,"1":0.0196221281,"2":0.0200615948,"3":0.0023327278,"4":2.522326894e-17,"5":5.313558256e-17,"6":2.131873785e-17,"7":3.610242092e-17,"8":6.274111642e-18,"9":0.5738100825},"14":{"0":0.3636549619,"1":0.0300043761,"2":0.0216688716,"3":0.0031277202,"4":3.288153694e-17,"5":3.413422277e-18,"6":3.209816748e-17,"7":2.085207332e-18,"8":2.901151457e-17,"9":0.5815440702},"15":{"0":0.3395655167,"1":0.0424597029,"2":0.0236050523,"3":0.0031976087,"4":5.746894537e-17,"5":2.678184911e-17,"6":5.355612749e-17,"7":2.380789845e-17,"8":5.143729232e-17,"9":0.5911721194},"16":{"0":0.3118806072,"1":0.0567959587,"2":0.0258342655,"3":0.0032068532,"4":2.737908101e-17,"5":5.697172716e-17,"6":2.525153279e-17,"7":5.477632262e-17,"8":2.381830614e-17,"9":0.6022823153},"17":{"0":0.2809213168,"1":0.0728278083,"2":0.0283271347,"3":0.0032171912,"4":1.063655904e-16,"5":1.39931364e-17,"6":4.466989042e-17,"7":1.387778602e-17,"8":4.396144972e-17,"9":0.6147065489},"18":{"0":0.2473168644,"1":0.0902294193,"2":0.0310329947,"3":0.0032284124,"4":5.708350806e-17,"5":2.552189034e-17,"6":5.66807739e-17,"7":2.508600621e-17,"8":5.530763378e-17,"9":0.6281923092},"19":{"0":0.2120123944,"1":0.1085113614,"2":0.0338757416,"3":0.0032402013,"4":1.261304571e-16,"5":2.910178085e-17,"6":6.081715666e-17,"7":2.73617201e-17,"8":5.492411636e-17,"9":0.6423603013},"20":{"0":0.1762369906,"1":0.1270371702,"2":0.0367564085,"3":0.0032521475,"4":5.011707666e-17,"5":1.602241291e-17,"6":4.901316229e-17,"7":1.059994125e-17,"8":4.194337415e-17,"9":0.6567172833},"21":{"0":0.1414069941,"1":0.1450734126,"2":0.0395609504,"3":0.003263778,"4":9.04426869e-17,"5":5.594916817e-17,"6":2.167730137e-17,"7":5.407301009e-17,"8":1.977703592e-17,"9":0.670694865},"22":{"0":0.1089649458,"1":0.1618748962,"2":0.0421735466,"3":0.0032687469,"4":2.025346899e-17,"5":4.78285362e-17,"6":1.124366533e-17,"7":4.275183056e-17,"8":7.725132856e-18,"9":0.6837178645},"23":{"0":0.0801810212,"1":0.1767986608,"2":0.0444946526,"3":0.0032186804,"4":6.820673466e-18,"5":3.876675101e-17,"6":1.768636834e-18,"7":3.225350444e-17,"8":6.455904412e-17,"9":0.695306985},"24":{"0":0.0559427859,"1":0.189365596,"2":0.046449199,"3":0.0031765207,"4":2.276258085e-17,"5":5.826882038e-17,"6":1.660093435e-17,"7":5.136226195e-17,"8":8.729763766e-18,"9":0.7050658984},"25":{"0":0.0366470633,"1":0.1993699587,"2":0.0480051862,"3":0.0031429579,"4":8.67235385e-17,"5":5.050123714e-17,"6":1.420989364e-17,"7":4.764800072e-17,"8":1.024884564e-17,"9":0.7128348339},"26":{"0":0.0221731668,"1":0.2068743219,"2":0.0491723463,"3":0.0031177821,"4":4.746986759e-17,"5":1.074970294e-17,"6":4.41946748e-17,"7":4.781835484e-18,"8":4.090038725e-17,"9":0.7186623829},"27":{"0":0.011978764,"1":0.2121748779,"2":0.0499971849,"3":0.0030513758,"4":2.065360703e-17,"5":5.629411166e-17,"6":1.889775622e-17,"7":4.781741198e-17,"8":1.12436204e-17,"9":0.7227977974},"28":{"0":0.0052756543,"1":0.2157441734,"2":0.0505550643,"3":0.0027351542,"4":4.207732493e-17,"5":5.097127229e-18,"6":4.08430727e-17,"7":1.590182423e-18,"8":3.610812023e-17,"9":0.7256899539},"29":{"0":0.0011851247,"1":0.2180607643,"2":0.0509210858,"3":0.0020931008,"4":6.038140987e-17,"5":2.318324433e-17,"6":5.60307935e-17,"7":1.579304212e-17,"8":5.020077185e-17,"9":0.7277399245},"30":{"0":0.0,"1":0.2201296428,"2":0.0512010121,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7286693452},"31":{"0":0.0,"1":0.221107872,"2":0.0512717061,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7276204219},"32":{"0":0.0,"1":0.2215894166,"2":0.0513064746,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7271041088},"33":{"0":0.0,"1":0.2218075655,"2":0.0513222254,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7268702091},"34":{"0":0.0,"1":0.2218980933,"2":0.0513287617,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.726773145},"35":{"0":0.0,"1":0.2219323412,"2":0.0513312345,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267364242},"36":{"0":0.0,"1":0.2219440931,"2":0.051332083,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267238239},"37":{"0":0.0,"1":0.2219477314,"2":0.0513323457,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267199229},"38":{"0":0.0,"1":0.2219487421,"2":0.0513324187,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267188392},"39":{"0":0.0,"1":0.2219489926,"2":0.0513324368,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267185706},"40":{"0":0.0,"1":0.2219490477,"2":0.0513324408,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267185116},"41":{"0":0.0,"1":0.2219490583,"2":0.0513324415,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267185001},"42":{"0":0.0,"1":0.2219490602,"2":0.0513324417,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267184982},"43":{"0":0.0,"1":0.2219490604,"2":0.0513324417,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267184979},"44":{"0":0.0,"1":0.2219490605,"2":0.0513324417,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267184979},"45":{"0":0.0,"1":0.2219490605,"2":0.0513324417,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267184978},"46":{"0":0.0,"1":0.2219490605,"2":0.0513324417,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267184978},"47":{"0":0.0,"1":0.2219490605,"2":0.0513324417,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267184978},"48":{"0":0.0,"1":0.2219490605,"2":0.0513324417,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267184978},"49":{"0":0.0,"1":0.2219490605,"2":0.0513324417,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":0.7267184978}}
2 changes: 1 addition & 1 deletion tests/output/output_3/x_index_vs_y_col_components.json

Large diffs are not rendered by default.

109 changes: 54 additions & 55 deletions tests/test_NMF_analysis_code.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
import os
import tempfile
import shutil
from os.path import exists, join
from pathlib import Path
from shutil import rmtree

import pytest

from diffpy.nmf_mapping.main import main

dir = Path(__file__).parent.resolve()

data_dir = os.path.join(dir, "data/synthetic_r_vs_gr")

test_map = [
([data_dir, "--xrange", "5,10"], "output_1", "Number of components: 3\n"),
([data_dir], "output_2", "Number of components: 3\n"),
([data_dir, "--xrange", "5,10", "12,15"], "output_3", "Number of components: 3\n"),
]


@pytest.fixture(scope="session")
def temp_dir():
"""A test fixture that creates and destroys tes outputs in a temporary
directory.
This will yield the path to the directory.
"""
cwd = os.getcwd()
name = "outputs"
temp_dir = Path(tempfile.gettempdir())
repo = os.path.join(temp_dir, name)
if os.path.exists(repo):
rmtree(repo)
os.chdir(temp_dir)
os.mkdir(name)
os.chdir(cwd)
yield repo
os.chdir(cwd)
rmtree(repo)


@pytest.mark.parametrize("tm", test_map)
def test_nmf_mapping_code(tm, temp_dir, capsys):
data_dir = tm[0]
working_dir = Path(temp_dir)
os.chdir(working_dir)
main(args=data_dir)
out, err = capsys.readouterr()
assert out == tm[2]
results_dir = os.path.join(working_dir, "nmf_result")
os.chdir(results_dir)
expected_base = os.path.join(os.path.dirname(__file__), "output")
test_specific_dir = os.path.join(expected_base, tm[1])
for root, dirs, files in os.walk("."):
for file in files:
if file in os.listdir(test_specific_dir):
fn1 = os.path.join(results_dir, file)
with open(fn1, "r") as f:
actual = f.read()
fn2 = os.path.join(test_specific_dir, file)
with open(fn2, "r") as f:
expected = f.read()
assert expected == actual
data_dir = join(dir, "data/synthetic_r_vs_gr")


@pytest.mark.parametrize(
"args, output_dir",
[
(["tests/data/synthetic_r_vs_gr", "--xrange", "5,10", "--show", "false"], "output_1"),
(["tests/data/synthetic_r_vs_gr", "--show", "false"], "output_2"),
(["tests/data/synthetic_r_vs_gr", "--xrange", "5,10", "12,15", "--show", "false"], "output_3"),
],
)
def test_nmf_mapping_code(args, output_dir, tmpdir):

# Save the result in ("nmf_result") at the top project level (default behavior)
main(args=args)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr

This main(args=args) creates 3 .json files under nmf_result at the top directly level, which is the default behavior. I then copy these outputs to tmpdir and then compare those three json files under tmpdir against the expected .json files under tests/output/output1, tests/output/output2, and tests/output/output3.

The three 3 json files are:

    json_files_to_check = [
        "component_index_vs_pratio_col.json",
        "component_index_vs_RE_value.json",
        "x_index_vs_y_col_components.json",
    ]


# Define the copied results directory in tmpdir
tmp_results_dir = join(tmpdir, "nmf_result")
expected_output_dir = join("tests/output", output_dir)

# Copy the output to tmpdir
shutil.copytree("nmf_result", tmp_results_dir)

# Remove the nmf_result folder from the top project level
shutil.rmtree("nmf_result")

# Define the specific JSON files to check
json_files_to_check = [
"component_index_vs_pratio_col.json",
"component_index_vs_RE_value.json",
"x_index_vs_y_col_components.json",
]

# Compare each specified .json file
for json_file in json_files_to_check:
# Define paths for actual and expected .json files
actual_file_path = join(tmp_results_dir, json_file)
expected_file_path = join(expected_output_dir, json_file)

# Ensure the file exists in both locations
assert exists(actual_file_path)
assert exists(expected_file_path)

# Read and compare file contents
with open(actual_file_path, "r") as actual_file:
actual = actual_file.read()

with open(expected_file_path, "r") as expected_file:
expected = expected_file.read()

# Assert that the contents match
assert actual == expected