Ejemplo n.º 1
0
def check_gemparser_results(test_file, regen=False):
    """
    Run GemfileParser.parse on `test_file` and check against a JSON file that
    contains expected results with the same name as the `test_file` with a
    "-expected.json" suffix appended.
    """
    import json

    gemparser = GemfileParser(test_file)
    dependencies = {
        group: [dep.to_dict() for dep in deps]
        for group, deps in gemparser.parse().items()
    }

    expected_file = test_file + '-expected.json'
    if regen:
        with open(expected_file, 'w') as o:
            json.dump(dependencies, o, indent=2)

    with open(expected_file) as o:
        expected = json.load(o)

    assert expected == dependencies
 def parse_file(self, fname, file_content):
     parser = GemfileParser(fname)
     return parser.parse()
def test_source_only_gemfile():
    gemparser = GemfileParser("tests/Gemfile")
    expected = {"development": [], "test": [], "runtime": [], "metrics": [], "production": []}
    dependencies = gemparser.parse()
    assert_equal(dependencies, expected)
def test_gemspec():
    gemparser = GemfileParser("tests/Gemfile_2")
    dependencies = gemparser.parse()
    assert_in("rails", [x.name for x in dependencies["runtime"]])
    assert_in("responders", [x.name for x in dependencies["development"]])
def test_source():
    gemparser = GemfileParser("tests/Gemfile_2")
    dependencies = gemparser.parse()
    assert_equal(dependencies["runtime"][0].source, "http://www.example.com")
def test_group_block():
    gemparser = GemfileParser("tests/Gemfile_2")
    dependencies = gemparser.parse()
    assert_equal(dependencies["development"][0].requirement, "3.0.0")
    assert_equal(dependencies["runtime"][0].requirement, "4.2.4")
def test_group():
    gemparser = GemfileParser("tests/Gemfile_3")
    dependencies = gemparser.parse()
    assert_equal(dependencies["development"][0].requirement, "4.2.4")
Ejemplo n.º 8
0
def test_name():
    gemparser = GemfileParser('tests/Gemfile_2')
    dependencies = gemparser.parse()
    assert_equal(dependencies['runtime'][0].name, 'rails')
def test_name():
    gemparser = GemfileParser("tests/Gemfile_2")
    dependencies = gemparser.parse()
    assert_equal(dependencies["runtime"][0].name, "rails")
Ejemplo n.º 10
0
def test_gemspec():
    gemparser = GemfileParser('tests/Gemfile_2')
    dependencies = gemparser.parse()
    assert_in('rails', [x.name for x in dependencies['runtime']])
    assert_in('responders', [x.name for x in dependencies['development']])
Ejemplo n.º 11
0
def test_source():
    gemparser = GemfileParser('tests/Gemfile_2')
    dependencies = gemparser.parse()
    assert_equal(dependencies['runtime'][0].source, 'http://www.example.com')
Ejemplo n.º 12
0
def test_group_block():
    gemparser = GemfileParser('tests/Gemfile_2')
    dependencies = gemparser.parse()
    assert_equal(dependencies['development'][0].requirement, '3.0.0')
    assert_equal(dependencies['runtime'][0].requirement, '4.2.4')
Ejemplo n.º 13
0
def test_group():
    gemparser = GemfileParser('tests/Gemfile_3')
    dependencies = gemparser.parse()
    assert_equal(dependencies['development'][0].requirement, '4.2.4')
Ejemplo n.º 14
0
def test_requirement():
    gemparser = GemfileParser('tests/Gemfile_2')
    dependencies = gemparser.parse()
    assert_equal(dependencies['runtime'][0].requirement, '4.2.4')
Ejemplo n.º 15
0
    def parse_spec(self, location):
        """
        Return dictionary contains podspec or gemspec file data.
        """
        with io.open(location, encoding='utf-8', closefd=True) as data:
            lines = data.readlines()

        spec_data = {}

        for line in lines:
            line = pre_process(line)
            match = self.parse_name.match(line)
            if match:
                name = match.group('name')
                spec_data['name'] = get_stripped_data(name)
            match = self.parse_version.match(line)
            if match:
                version = match.group('version')
                spec_data['version'] = get_stripped_data(version)
            match = self.parse_license.match(line)
            if match:
                license_value = match.group('license')
                spec_data['license'] = get_stripped_data(license_value)
            match = self.parse_summary.match(line)
            if match:
                summary = match.group('summary')
                spec_data['summary'] = get_stripped_data(summary)
            match = self.parse_homepage.match(line)
            if match:
                homepage = match.group('homepage')
                spec_data['homepage_url'] = get_stripped_data(homepage)
            match = self.parse_source.match(line)
            if match:
                source = re.sub(r'/*.*source.*?>', '', line)
                stripped_source = re.sub(r',.*', '', source)
                spec_data['source'] = get_stripped_data(stripped_source)
            match = self.parse_description.match(line)
            if match:
                if location.endswith('.gemspec'):
                    # FIXME: description can be in single or multi-lines
                    # There are many different ways to write description.
                    description = match.group('description')
                    spec_data['description'] = get_stripped_data(description)
                else:
                    spec_data['description'] = get_description(location)
            if '.email' in line:
                _key, _sep, value = line.rpartition('=')
                stripped_emails = get_stripped_data(value)
                stripped_emails = stripped_emails.strip()
                stripped_emails = stripped_emails.split(',')
                spec_data['email'] = stripped_emails
            elif '.author' in line:
                authors = re.sub(r'/*.*author.*?=', '', line)
                stripped_authors = get_stripped_data(authors)
                stripped_authors = re.sub(r'(\s*=>\s*)', '=>',
                                          stripped_authors)
                stripped_authors = stripped_authors.strip()
                stripped_authors = stripped_authors.split(',')
                spec_data['author'] = stripped_authors

        parser = GemfileParser(location)
        deps = parser.parse()
        dependencies = {}
        for key in deps:
            depends = deps.get(key, []) or []
            for dep in depends:
                dependencies[dep.name] = dep.requirement
        spec_data['dependencies'] = dependencies

        return spec_data
 def parse_file(self, fname, file_content):
     parser = GemfileParser(fname)
     return parser.parse()
def test_requirement():
    gemparser = GemfileParser("tests/Gemfile_2")
    dependencies = gemparser.parse()
    assert_equal(dependencies["runtime"][0].requirement, "4.2.4")