from pyqgraf import qgraf, model
import pytest

prologue = r"""
<prologue>
<<!--
 file generated by <program>

<command_loop><command_line_loop> <command_data><end><end>

 You must add x= and y= with suitable vertex positions.
 Some lines may need manual bending to render properly.
-->>
<exit>
"""

style = r"""
<prologue>
<<feynml>>
<diagram>
  <back>
 <<diagram 
          id="Diagram<diagram_index>"
          incoming="<legs_in>"
          outgoing="<legs_out>"
          sign="<sign>"
          symmmetry_factor="<symmetry_factor>"
 >>

<vertex_loop> 
  <<vertex id="Vert<vertex_index>">>
  <</vertex>>
<end>

<in_loop>
  <<leg id="In<in_index>">>  
        <<name>><field><</name>>
        <<sense>>incoming<</sense>>
        <<target>>Vert<vertex_index><</target>>
        <<momentum>>
          <<name>><momentum><</name>>
        <</momentum>>
  <</leg>>
<end>

<out_loop> 
  <<leg id="Out<out_index>">>  
        <<name>><field><</name>>
        <<sense>>outgoing<</sense>>
        <<target>>Vert<vertex_index><</target>>
        <<momentum>>
          <<name>><momentum><</name>>
        <</momentum>>
  <</leg>>
<end>

<propagator_loop> 
  <<propagator id="Prop<propagator_index>">>  
        <<name>><field><</name>>
        <<source>>Vert<dual-vertex_index><</source>>
        <<target>>Vert<vertex_index><</target>>
        <<momentum>>
          <<name>><momentum><</name>>
        <</momentum>>
  <</propagator>>
<end>

 <</diagram>>
<epilogue>
<</feynml>>

<<!-- end -->>
<exit>
"""

result_1_1="""<feynml>
 
 <diagram
          id="Diagram1"
          incoming="1"
          outgoing="1"
          sign="+"
          symmmetry_factor="1"
 >


  <vertex id="Vert1">
  </vertex>

  <vertex id="Vert2">
  </vertex>



  <leg id="In1">
        <name>e_minus</name>
        <sense>incoming</sense>
        <target>Vert1</target>
        <momentum>
          <name>p1</name>
        </momentum>
  </leg>



  <leg id="Out1">
        <name>e_minus</name>
        <sense>outgoing</sense>
        <target>Vert2</target>
        <momentum>
          <name>p2</name>
        </momentum>
  </leg>



  <propagator id="Prop1">
        <name>e_minus</name>
        <source>Vert1</source>
        <target>Vert2</target>
        <momentum>
          <name>-l1+p1</name>
        </momentum>
  </propagator>

  <propagator id="Prop2">
        <name>gamma</name>
        <source>Vert2</source>
        <target>Vert1</target>
        <momentum>
          <name>-l1</name>
        </momentum>
  </propagator>


 </diagram>
</feynml>

<!-- end -->
"""

result_2_2=""""""


def test_run():
    qgraf.install()
    xml_string = qgraf.run(
        "nu_e[p1], nu_e_bar[p2]",
        "nu_e[p3], nu_e_bar[p4]",
        loops=1,
        loop_momentum="l",
        model=model.gws_UnitaryGauge_reduced,
        style=style,
    )


@pytest.mark.parametrize("version", ["3.6.9", "3.5.3", "3.4.2"])
def test_run_1_1(version):
    qgraf.install(version)
    xml_string = qgraf.run(
        "e_minus[p1]",
        "e_minus[p2]",
        loops=1,
        loop_momentum="l",
        model=model.qed,
        style=style,
    )
    assert xml_string == result_1_1

@pytest.mark.parametrize("version", ["3.6.9", "3.5.3", "3.4.2"])
def test_run_2_2(version):
    qgraf.install(version)
    xml_string = qgraf.run(
        "nu_e[p1], nu_e_bar[p2]",
        "nu_e[p3], nu_e_bar[p4]",
        loops=1,
        loop_momentum="l",
        model=model.gws_UnitaryGauge,
        style=style,
    )
