<commit_before>'use strict';

var path = require('path'),
    fs = require('fs'),
    _ = require('underscore'),
    gm = require('gm'),
    expect = require('chai').expect;

module.exports = function testCompositor(name, module) {
    describe('Compositor/' + name, function () {
        var imagePaths = [
                'test/fixtures/images/src/house.png',
                'test/fixtures/images/src/lena.jpg',
                'test/fixtures/images/src/lock.png'
            ],
            spritePath = 'test/fixtures/images/test_out.png';

        it('should read the files correctly', function (done) {
            module.readImages(imagePaths, function (err, images) {
                var houseImage = images[0],
                    lenaImage = images[1],
                    lockImage = images[2];

                expect(err).to.equal(null);

                expect(lenaImage.width).to.equal(300);
                expect(lenaImage.height).to.equal(168);

                expect(lockImage.width).to.equal(26);
                expect(lockImage.height).to.equal(31);

                expect(houseImage.width).to.equal(15);
                expect(houseImage.height).to.equal(15);

                done();
            });
        });

        it('should write the sprites correctly', function (done) {
            var options = {},
                expectedPath = 'test/fixtures/images/expected/' + name + '/nsg.png';

            module.readImages(imagePaths, function (err, images) {
                var layout = {
                    width: 300,
                    height: 214,
                    images: [
                        _({ x: 0, y: 0 }).extend(images[0]),
                        _({ x: 0, y: 15 }).extend(images[1]),
                        _({ x: 0, y: 183 }).extend(images[2])
                    ]
                };

                expect(err).not.to.be.ok;

                module.render(layout, spritePath, options, function (err) {
                    expect(err).not.to.be.ok;
                    expect(options).to.deep.equal({});
                    expect(fs.readFileSync(expectedPath).toString()).to.equal(fs.readFileSync(spritePath).toString());
                    fs.unlinkSync(spritePath);
                    done();
                });
            });
        });

        it('should write the sprites correctly when specifying a different compression level', function(done) {
            var options = { compressionLevel: 9 },
                expectedPath = 'test/fixtures/images/expected/' + name + '/nsg_compression_level_9.png';

            module.readImages(imagePaths, function (err, images) {
                var layout = {
                    width: 300,
                    height: 214,
                    images: [
                        _({ x: 0, y: 0 }).extend(images[0]),
                        _({ x: 0, y: 15 }).extend(images[1]),
                        _({ x: 0, y: 183 }).extend(images[2])
                    ]
                };

                expect(err).not.to.be.ok;

                module.render(layout, spritePath, options, function (err) {
                    expect(err).not.to.be.ok;
                    expect(options).to.deep.equal({ compressionLevel: 9 });
                    expect(fs.readFileSync(expectedPath).toString()).to.equal(fs.readFileSync(spritePath).toString());
                    fs.unlinkSync(spritePath);
                    done();
                });
            });
        });

    });
};<commit_msg>fix hanging test on travis<commit_after>'use strict';

var path = require('path'),
    fs = require('fs'),
    _ = require('underscore'),
    gm = require('gm'),
    expect = require('chai').expect;

function compareFiles (generated, expected, callback) {
    var generatedContent,
        expectedContent;

    try {
        generatedContent = fs.readFileSync(generated).toString();
        expectedContent = fs.readFileSync(expected).toString();
    } catch (e) {
        return callback(e);
    }

    if (generatedContent !== expectedContent) {
        return callback(new Error('Files dont match'));
    }

    callback(null);
}

module.exports = function testCompositor(name, module) {
    describe('Compositor/' + name, function () {
        var imagePaths = [
                'test/fixtures/images/src/house.png',
                'test/fixtures/images/src/lena.jpg',
                'test/fixtures/images/src/lock.png'
            ],
            spritePath = 'test/fixtures/images/test_out.png';

        it('should read the files correctly', function (done) {
            module.readImages(imagePaths, function (err, images) {
                var houseImage = images[0],
                    lenaImage = images[1],
                    lockImage = images[2];

                expect(err).to.equal(null);

                expect(lenaImage.width).to.equal(300);
                expect(lenaImage.height).to.equal(168);

                expect(lockImage.width).to.equal(26);
                expect(lockImage.height).to.equal(31);

                expect(houseImage.width).to.equal(15);
                expect(houseImage.height).to.equal(15);

                done();
            });
        });

        it('should write the sprites correctly', function (done) {
            var options = {},
                expectedPath = 'test/fixtures/images/expected/' + name + '/nsg.png';

            module.readImages(imagePaths, function (err, images) {
                var layout = {
                    width: 300,
                    height: 214,
                    images: [
                        _({ x: 0, y: 0 }).extend(images[0]),
                        _({ x: 0, y: 15 }).extend(images[1]),
                        _({ x: 0, y: 183 }).extend(images[2])
                    ]
                };

                expect(err).not.to.be.ok;

                module.render(layout, spritePath, options, function (err) {
                    expect(err).not.to.be.ok;
                    expect(options).to.deep.equal({});
                    compareFiles(spritePath, expectedPath, function (err) {
                        expect(err).not.to.be.ok;
                        fs.unlinkSync(spritePath);
                        done();
                    });
                });
            });
        });

        it('should write the sprites correctly when specifying a different compression level', function(done) {
            var options = { compressionLevel: 9 },
                expectedPath = 'test/fixtures/images/expected/' + name + '/nsg_compression_level_9.png';

            module.readImages(imagePaths, function (err, images) {
                var layout = {
                    width: 300,
                    height: 214,
                    images: [
                        _({ x: 0, y: 0 }).extend(images[0]),
                        _({ x: 0, y: 15 }).extend(images[1]),
                        _({ x: 0, y: 183 }).extend(images[2])
                    ]
                };

                expect(err).not.to.be.ok;

                module.render(layout, spritePath, options, function (err) {
                    expect(err).not.to.be.ok;
                    expect(options).to.deep.equal({ compressionLevel: 9 });
                    compareFiles(spritePath, expectedPath, function (err) {
                        expect(err).not.to.be.ok;
                        fs.unlinkSync(spritePath);
                        done();
                    });
                });
            });
        });

    });
};
{'fraction_non_alphanumeric': 0.1334041987775711, 'fraction_numerical': 0.01488174328992825, 'mean_word_length': 1.3744479495268138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2479408', 'n_tokens_mistral': 2135, 'n_tokens_neox': 1901, 'n_words': 360}