def test_unconnected(): sketcher = Sketcher() sketcher.define('a1 a2 b1 c2') sketch = sketcher.sketch sketch.color_beads() assert bead(sketch, 'a1').freshness == SUPERSEDED assert bead(sketch, 'a2').freshness == UP_TO_DATE assert bead(sketch, 'b1').freshness == UP_TO_DATE assert bead(sketch, 'c2').freshness == UP_TO_DATE
def indirect_links_sketch(self, robot): sketcher = Sketcher() sketcher.define('a1 b1 b2 c1 c2 d3 e1 f1') sketcher.compile(""" a1 -> b1 e1 -> f1 b2 -> c1 c2 -> d3 """) sketcher.sketch.to_file(robot.cwd / 'computation.web')
def sketch(self, robot): sketcher = Sketcher() sketcher.define('a1 b1 c1 d1 e1 f1') sketcher.compile(""" a1 -> b1 -> c1 -> d1 b1 ------------> e1 -> f1 """) sketcher.sketch.to_file(robot.cwd / 'computation.web')
def test_phantom_input(): sketcher = Sketcher() sketcher.define('d1 e1') sketcher.phantom('d1') sketcher.compile(""" d1 --> e1 """) sketch = sketcher.sketch sketch.color_beads() assert {'e'} == {bead.name for bead in sketcher.beads} assert len(list(sketcher.beads)) == 1 assert len(sketch.beads) == 2 assert bead(sketch, 'd1').freshness == PHANTOM assert bead(sketch, 'e1').freshness == OUT_OF_DATE
def test_out_of_date_input(): sketcher = Sketcher() sketcher.define('a1 a2 b1') sketcher.compile(""" a1 -> b1 """) sketch = sketcher.sketch sketch.color_beads() assert bead(sketch, 'a1').freshness == SUPERSEDED assert bead(sketch, 'b1').freshness == OUT_OF_DATE
def test_impossible_loop(): # sketcher are always forming a DAG, so this can not happen sketcher = Sketcher() sketcher.define('a1 b1') sketcher.compile(""" a1 -> b1 b1 -> a1 """) sketch = sketcher.sketch with pytest.raises(ValueError): sketch.color_beads()
def test_coloring_is_transitive(): sketcher = Sketcher() sketcher.define('a1 c1 d1 e1') sketcher.define('a2 b2 c2 ') sketcher.phantom('c1') sketcher.compile(""" a1 c1 -> d1 -> e1 a2 -> b2 -> c2 """) sketch = sketcher.sketch sketch.color_beads() assert bead(sketch, 'a1').freshness == SUPERSEDED assert bead(sketch, 'c1').freshness == PHANTOM assert bead(sketch, 'd1').freshness == OUT_OF_DATE assert bead(sketch, 'e1').freshness == OUT_OF_DATE assert bead(sketch, 'a2').freshness == UP_TO_DATE assert bead(sketch, 'b2').freshness == UP_TO_DATE assert bead(sketch, 'c2').freshness == UP_TO_DATE
def test_new_version_marks_older_superseded(): sketcher = Sketcher() sketcher.define('a1 b1 c1') sketcher.compile(""" a1 -> b1 a1 -:survivor:-> c1 """) sketch = sketcher.sketch orig_beads = sketch.beads sketch = Sketch(beads=orig_beads, edges=tuple(e for e in sketch.edges if e.label == 'survivor')) sketch = sketch.drop_deleted_inputs() assert orig_beads != sketch.beads assert len(sketch.edges) == 1 assert len(bead(sketch, 'a1').inputs) == 0 assert len(bead(sketch, 'b1').inputs) == 0 assert len(bead(sketch, 'c1').inputs) == 1 assert bead(sketch, 'c1').inputs[0].name == 'survivor'
def test_new_version_marks_older_superseded(): sketcher = Sketcher() sketcher.define('a1') sketch = sketcher.sketch sketch.color_beads() assert bead(sketch, 'a1').freshness == UP_TO_DATE sketcher = Sketcher() sketcher.define('a1 a2') sketch = sketcher.sketch sketch.color_beads() assert bead(sketch, 'a1').freshness == SUPERSEDED assert bead(sketch, 'a2').freshness == UP_TO_DATE sketcher = Sketcher() sketcher.define('a1 a2 a3') sketch = sketcher.sketch sketch.color_beads() assert bead(sketch, 'a1').freshness == SUPERSEDED assert bead(sketch, 'a2').freshness == SUPERSEDED assert bead(sketch, 'a3').freshness == UP_TO_DATE
def test_up_to_date_input(): sketcher = Sketcher() sketcher.define('a1 b1') sketcher.compile(""" a1 -> b1 """) sketch = sketcher.sketch sketch.color_beads() assert bead(sketch, 'a1').freshness == UP_TO_DATE assert bead(sketch, 'b1').freshness == UP_TO_DATE sketcher = Sketcher() sketcher.define('a1 a2 b1') sketcher.compile(""" a2 -> b1 """) sketch = sketcher.sketch sketch.color_beads() assert bead(sketch, 'a1').freshness == SUPERSEDED assert bead(sketch, 'a2').freshness == UP_TO_DATE assert bead(sketch, 'b1').freshness == UP_TO_DATE
def renamed_e_web_file(self, robot): sketcher = Sketcher() sketcher.define('a1 b1 c1 d1 e1 f1') sketcher.compile(""" a1 -> b1 -> c1 -> d1 b1 ------------> e1 -> f1 """) # Mess up the above a bit: make copies of `e1` to `renamed_e` and `another_e_copy`, # then deleting `e1`. # Since we are just making copies/renaming them, `f1` can use any of them as input. # Which one to select of the copies just affects future updates. sketcher.phantom('e1') sketcher.clone('e1', 'renamed_e') sketcher.clone('e1', 'another_e_copy') # a1 -> b1 -> c1 -> d1 # [e1] -> f1 # [e1] is phantom - it is not existing by the name e # b1 ------------> renamed_e[e1] # b1 ------------> another_e_copy[e1] output_filename = robot.cwd / 'computation.web' sketcher.sketch.to_file(output_filename) return output_filename