@@ -26,7 +26,9 @@ def test_write_artifact_json(self):
2626        try :
2727            decision .ARTIFACTS_DIR  =  Path (tmpdir ) /  "artifacts" 
2828            decision .write_artifact ("artifact.json" , data )
29-             with  open (os .path .join (decision .ARTIFACTS_DIR , "artifact.json" )) as  f :
29+             with  open (
30+                 os .path .join (decision .ARTIFACTS_DIR , "public" , "artifact.json" )
31+             ) as  f :
3032                self .assertEqual (json .load (f ), data )
3133        finally :
3234            if  os .path .exists (tmpdir ):
@@ -39,7 +41,97 @@ def test_write_artifact_yml(self):
3941        try :
4042            decision .ARTIFACTS_DIR  =  Path (tmpdir ) /  "artifacts" 
4143            decision .write_artifact ("artifact.yml" , data )
42-             self .assertEqual (load_yaml (decision .ARTIFACTS_DIR , "artifact.yml" ), data )
44+             self .assertEqual (
45+                 load_yaml (decision .ARTIFACTS_DIR  /  "public" , "artifact.yml" ), data 
46+             )
47+         finally :
48+             if  os .path .exists (tmpdir ):
49+                 shutil .rmtree (tmpdir )
50+             decision .ARTIFACTS_DIR  =  Path ("artifacts" )
51+ 
52+     def  test_write_artifact_custom_prefix (self ):
53+         data  =  [{"some" : "data" }]
54+         tmpdir  =  tempfile .mkdtemp ()
55+         try :
56+             decision .ARTIFACTS_DIR  =  Path (tmpdir ) /  "artifacts" 
57+             decision .write_artifact ("artifact.json" , data , "custom-prefix" )
58+             with  open (
59+                 os .path .join (decision .ARTIFACTS_DIR , "custom-prefix" , "artifact.json" )
60+             ) as  f :
61+                 self .assertEqual (json .load (f ), data )
62+         finally :
63+             if  os .path .exists (tmpdir ):
64+                 shutil .rmtree (tmpdir )
65+             decision .ARTIFACTS_DIR  =  Path ("artifacts" )
66+ 
67+     def  test_read_artifact_json (self ):
68+         data  =  {"test" : "data" }
69+         tmpdir  =  tempfile .mkdtemp ()
70+         try :
71+             decision .ARTIFACTS_DIR  =  Path (tmpdir ) /  "artifacts" 
72+             decision .write_artifact ("test.json" , data )
73+             result  =  decision .read_artifact ("test.json" )
74+             self .assertEqual (result , data )
75+         finally :
76+             if  os .path .exists (tmpdir ):
77+                 shutil .rmtree (tmpdir )
78+             decision .ARTIFACTS_DIR  =  Path ("artifacts" )
79+ 
80+     def  test_read_artifact_yml (self ):
81+         data  =  {"test" : "data" }
82+         tmpdir  =  tempfile .mkdtemp ()
83+         try :
84+             decision .ARTIFACTS_DIR  =  Path (tmpdir ) /  "artifacts" 
85+             decision .write_artifact ("test.yml" , data )
86+             result  =  decision .read_artifact ("test.yml" )
87+             self .assertEqual (result , data )
88+         finally :
89+             if  os .path .exists (tmpdir ):
90+                 shutil .rmtree (tmpdir )
91+             decision .ARTIFACTS_DIR  =  Path ("artifacts" )
92+ 
93+     def  test_read_artifact_custom_prefix (self ):
94+         data  =  {"test" : "data" }
95+         tmpdir  =  tempfile .mkdtemp ()
96+         try :
97+             decision .ARTIFACTS_DIR  =  Path (tmpdir ) /  "artifacts" 
98+             decision .write_artifact ("test.json" , data , "custom" )
99+             result  =  decision .read_artifact ("test.json" , "custom" )
100+             self .assertEqual (result , data )
101+         finally :
102+             if  os .path .exists (tmpdir ):
103+                 shutil .rmtree (tmpdir )
104+             decision .ARTIFACTS_DIR  =  Path ("artifacts" )
105+ 
106+     def  test_rename_artifact (self ):
107+         data  =  {"test" : "data" }
108+         tmpdir  =  tempfile .mkdtemp ()
109+         try :
110+             decision .ARTIFACTS_DIR  =  Path (tmpdir ) /  "artifacts" 
111+             decision .write_artifact ("original.json" , data )
112+             decision .rename_artifact ("original.json" , "renamed.json" )
113+             result  =  decision .read_artifact ("renamed.json" )
114+             self .assertEqual (result , data )
115+             # Verify original is gone 
116+             with  self .assertRaises (FileNotFoundError ):
117+                 decision .read_artifact ("original.json" )
118+         finally :
119+             if  os .path .exists (tmpdir ):
120+                 shutil .rmtree (tmpdir )
121+             decision .ARTIFACTS_DIR  =  Path ("artifacts" )
122+ 
123+     def  test_rename_artifact_custom_prefix (self ):
124+         data  =  {"test" : "data" }
125+         tmpdir  =  tempfile .mkdtemp ()
126+         try :
127+             decision .ARTIFACTS_DIR  =  Path (tmpdir ) /  "artifacts" 
128+             decision .write_artifact ("original.json" , data , "custom" )
129+             decision .rename_artifact ("original.json" , "renamed.json" , "custom" )
130+             result  =  decision .read_artifact ("renamed.json" , "custom" )
131+             self .assertEqual (result , data )
132+             # Verify original is gone 
133+             with  self .assertRaises (FileNotFoundError ):
134+                 decision .read_artifact ("original.json" , "custom" )
43135        finally :
44136            if  os .path .exists (tmpdir ):
45137                shutil .rmtree (tmpdir )
0 commit comments