from treeherder.log_parser.artifactbuildercollection import ArtifactBuilderCollection
from treeherder.log_parser.artifactbuilders import BuildbotLogViewArtifactBuilder
from ..sampledata import SampleData


def test_builders_as_list():
    """test that passing in a list of builders works"""
    builder = BuildbotLogViewArtifactBuilder()
    lpc = ArtifactBuilderCollection(
        "foo-url",
        builders=[builder]
    )
    assert lpc.builders == [builder]


def test_builders_as_single_still_list():
    """test that passing in a single builder becomes a list"""
    builder = BuildbotLogViewArtifactBuilder()
    lpc = ArtifactBuilderCollection(
        "foo-url",
        builders=builder
    )
    assert lpc.builders == [builder]


def test_default_builders():
    """test no builders"""
    lpc = ArtifactBuilderCollection(
        "foo-url",
    )
    assert isinstance(lpc.builders, list)
    assert len(lpc.builders) == 2


def test_all_builders_complete():
    """test no builders"""
    log = "mozilla-central_fedora-b2g_test-crashtest-1-bm54-tests1-linux-build50"
    url = "file://{0}".format(
        SampleData().get_log_path("{0}.txt.gz".format(log)))
    lpc = ArtifactBuilderCollection(
        url,
    )
    for builder in lpc.builders:
        for parser in builder.parsers:
            parser.parse_complete = True

    lpc.parse()
    exp = {
        "Structured Log": {
            "header": {},
            "logurl": "file:///home/vagrant/treeherder-service/tests/sample_data/logs/mozilla-central_fedora-b2g_test-crashtest-1-bm54-tests1-linux-build50.txt.gz",
            "step_data": {
                "all_errors": [],
                "steps": []
            }
        },
        "Unknown Builder Job Artifact": {
            "errors": [],
            "logurl": "file:///home/vagrant/treeherder-service/tests/sample_data/logs/mozilla-central_fedora-b2g_test-crashtest-1-bm54-tests1-linux-build50.txt.gz",
            "tinderbox_printlines": []
        }
    }

    assert lpc.artifacts == exp

@@ -1424,173 +1424,8 @@
 %7B%7D,%0A
-            %22logurl%22: %22file:///home/vagrant/treeherder-service/tests/sample_data/logs/mozilla-central_fedora-b2g_test-crashtest-1-bm54-tests1-linux-build50.txt.gz%22,%0A
     
@@ -1619,214 +1619,420 @@
    %22
-logurl%22: %22file:///home/vagrant/treeherder-service/tests/sample_data/logs/mozilla-central_fedora-b2g_test-crashtest-1-bm54-tests1-linux-build50.txt.gz%22,%0A            %22tinderbox_printlines%22: %5B%5D%0A        %7D%0A    %7D
+tinderbox_printlines%22: %5B%5D%0A        %7D%0A    %7D%0A    act = lpc.artifacts%0A%0A    # we can't compare the %22logurl%22 field, because it's a fully qualified url,%0A    # so it will be different depending on the config it's run in.%0A    assert %22logurl%22 in act%5B%22Structured Log%22%5D%0A    assert %22logurl%22 in act%5B%22Unknown Builder Job Artifact%22%5D%0A    del(act%5B%22Unknown Builder Job Artifact%22%5D%5B%22logurl%22%5D)%0A    del(act%5B%22Structured Log%22%5D%5B%22logurl%22%5D)
 %0A%0A  

fix collection test errors