Datasets:
File size: 8,890 Bytes
9306e26 0c5f0da 9306e26 0c5f0da 9306e26 2999ac5 69f59e2 9306e26 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | import importlib.util
import json
from pathlib import Path
import tempfile
from types import SimpleNamespace
import unittest
from unittest.mock import patch
spec=importlib.util.spec_from_file_location('sync',Path(__file__).with_name('sync-costume-progress.py'))
module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module)
class ProgressTests(unittest.TestCase):
def test_roster_export_requires_all_entries_and_publishes_only_parameterized_graph(self):
from portrait_autorefine import signature
for passing in (6,7):
with tempfile.TemporaryDirectory() as d:
root=Path(d);folder=root/'workflows/portraits/costume';folder.mkdir(parents=True)
(folder.parent/'index.json').write_text(json.dumps([dict(workflow_folder='workflows/portraits/costume')]))
args=SimpleNamespace(repo=root,identity=Path('operator-key'),host='operator-host',port=22,remote_repo='/repo',publish=False)
def git(command,**kwargs):
return 'main' if command[1]=='branch' else 'https://github.com/bensblueprints/consistent-pet.git' if command[1]=='remote' else ''
data=dict(status='locked_on_development_roster',format='consistent-pet-roster-recipe-v1',
evaluation=dict(roster_entries=7,passing_entries=passing,same_recipe_for_all=True,unseen_dog_validation=False),
graph={'1':dict(class_type='LoadImage',inputs=dict(image='__DOG_ORIGINAL__'))})
data['sha256']=signature(data)
files={'workflows/portraits/costume/workflow.json':json.dumps(data)}
with patch.object(module.subprocess,'check_output',side_effect=git),patch.object(module.subprocess,'run',return_value=SimpleNamespace(stdout=json.dumps(files))):
if passing==7:module.run(args);self.assertTrue((folder/'workflow.json').exists())
else:
with self.assertRaises(ValueError):module.run(args)
self.assertFalse((folder/'workflow.json').exists())
def test_85_percent_export_requires_fifteen_of_seventeen_and_complete_round(self):
from portrait_autorefine import signature
for version,passing,checked in [(v,p,c) for v in (3,4) for p,c in [(14,17),(15,17),(15,16)]]:
with tempfile.TemporaryDirectory() as d:
root=Path(d);folder=root/'workflows/portraits/costume';folder.mkdir(parents=True)
(folder.parent/'index.json').write_text(json.dumps([dict(workflow_folder='workflows/portraits/costume')]))
args=SimpleNamespace(repo=root,identity=Path('operator-key'),host='operator-host',port=22,remote_repo='/repo',publish=False)
def git(command,**kwargs):
return 'main' if command[1]=='branch' else 'https://github.com/bensblueprints/consistent-pet.git' if command[1]=='remote' else ''
data=dict(status='locked_on_qualified_roster',format=f'consistent-pet-roster-recipe-v{version}',thresholds=dict(identity=8 if version==4 else 9,fur=8 if version==4 else 9,body=7,template=8 if version==4 else 9),
evaluation=dict(roster_entries=17,passing_entries=passing,checked_entries=checked,required_pass_percent=85,required_passing_entries=15,input_minimum=7,same_recipe_for_all=True,unseen_dog_validation=False),
graph={'1':dict(class_type='LoadImage',inputs=dict(image='__DOG_ORIGINAL__'))})
data['sha256']=signature(data)
files={'workflows/portraits/costume/workflow.json':json.dumps(data)}
with patch.object(module.subprocess,'check_output',side_effect=git),patch.object(module.subprocess,'run',return_value=SimpleNamespace(stdout=json.dumps(files))):
if passing==15 and checked==17:module.run(args);self.assertTrue((folder/'workflow.json').exists())
else:
with self.assertRaises(ValueError):module.run(args)
def test_complete_round_average_export_acceptance(self):
from portrait_autorefine import signature
for total,checked in [(543,17),(544,17),(571,17),(571,16)]:
with tempfile.TemporaryDirectory() as d:
root=Path(d);folder=root/'workflows/portraits/costume';folder.mkdir(parents=True)
(folder.parent/'index.json').write_text(json.dumps([dict(workflow_folder='workflows/portraits/costume')]))
args=SimpleNamespace(repo=root,identity=Path('operator-key'),host='operator-host',port=22,remote_repo='/repo',publish=False)
def git(command,**kwargs):
return 'main' if command[1]=='branch' else 'https://github.com/bensblueprints/consistent-pet.git' if command[1]=='remote' else ''
data=dict(status='locked_on_average',format='consistent-pet-average-recipe-v1',thresholds={'round_average':8},
evaluation=dict(roster_entries=17,checked_entries=checked,score_sum=total,score_count=68,average_score=total/68,required_average=8,input_minimum=7,same_recipe_for_all=True),
graph={'1':dict(class_type='LoadImage',inputs=dict(image='__DOG_ORIGINAL__'))})
data['sha256']=signature(data)
files={'workflows/portraits/costume/workflow.json':json.dumps(data)}
with patch.object(module.subprocess,'check_output',side_effect=git),patch.object(module.subprocess,'run',return_value=SimpleNamespace(stdout=json.dumps(files))):
if total>=544 and checked==17:module.run(args);self.assertTrue((folder/'workflow.json').exists())
else:
with self.assertRaises(ValueError):module.run(args)
def test_five_dog_screening_export_acceptance(self):
from portrait_autorefine import signature
for total,checked in [(159,5),(160,5),(175,5),(175,4)]:
with tempfile.TemporaryDirectory() as d:
root=Path(d);folder=root/'workflows/portraits/costume';folder.mkdir(parents=True)
(folder.parent/'index.json').write_text(json.dumps([dict(workflow_folder='workflows/portraits/costume')]))
args=SimpleNamespace(repo=root,identity=Path('operator-key'),host='operator-host',port=22,remote_repo='/repo',publish=False)
def git(command,**kwargs):
return 'main' if command[1]=='branch' else 'https://github.com/bensblueprints/consistent-pet.git' if command[1]=='remote' else ''
data=dict(status='locked_on_average',format='consistent-pet-average-recipe-v2',thresholds={'round_average':8},
evaluation=dict(roster_entries=5,screening_sample=True,qualified_pool_entries=17,checked_entries=checked,score_sum=total,score_count=20,average_score=total/20,required_average=8,input_minimum=7,same_recipe_for_all=True),
graph={'1':dict(class_type='LoadImage',inputs=dict(image='__DOG_ORIGINAL__'))})
data['sha256']=signature(data)
files={'workflows/portraits/costume/workflow.json':json.dumps(data)}
with patch.object(module.subprocess,'check_output',side_effect=git),patch.object(module.subprocess,'run',return_value=SimpleNamespace(stdout=json.dumps(files))):
if total>=160 and checked==5:module.run(args);self.assertTrue((folder/'workflow.json').exists())
else:
with self.assertRaises(ValueError):module.run(args)
def test_publisher_rejects_unexpected_paths_private_evidence_and_bound_workflows(self):
with tempfile.TemporaryDirectory() as d:
root=Path(d);folder=root/'workflows/portraits/costume';folder.mkdir(parents=True)
(folder.parent/'index.json').write_text(json.dumps([dict(workflow_folder='workflows/portraits/costume')]))
args=SimpleNamespace(repo=root,identity=Path('operator-key'),host='operator-host',port=22,remote_repo='/repo',publish=False)
def git(command,**kwargs):
return 'main' if command[1]=='branch' else 'https://github.com/bensblueprints/consistent-pet.git' if command[1]=='remote' else ''
for files in ({'../secret':'bad'}, {'workflows/portraits/costume/REPORT.md':'inputs-v3-private.png'},
{'workflows/portraits/costume/workflow.json':'{"status":"provisional"}'}):
with patch.object(module.subprocess,'check_output',side_effect=git),patch.object(module.subprocess,'run',return_value=SimpleNamespace(stdout=json.dumps(files))):
with self.assertRaises(ValueError):module.run(args)
self.assertEqual(list(folder.iterdir()),[])
if __name__=='__main__':unittest.main()
|