Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion gemfileparser2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
import os
import re

TRACE = False


def logger_debug(*args):
pass


if TRACE:
import logging
import sys

logger = logging.getLogger(__name__)
logging.basicConfig(stream=sys.stdout)
logger.setLevel(logging.DEBUG)

def logger_debug(*args):
return logger.debug(' '.join(isinstance(a, str) and a or repr(a) for a in args))

logger_debug = print


class Dependency(object):
"""
Expand Down Expand Up @@ -157,10 +177,17 @@ def parse_gemfile(self):
# Gemfile contains a call to gemspec
gemfiledir = os.path.dirname(self.filepath)
gemspec_list = glob.glob(os.path.join(gemfiledir, "*.gemspec"))

if not gemspec_list:
logger_debug(f"No gemspec files found: {gemspec_list}")
continue

if len(gemspec_list) > 1:
print("Multiple gemspec files found")
logger_debug("Multiple gemspec files found")
continue

gemspec_file = gemspec_list[0]
# FIXME: the path is not used
self.parse_gemspec(path=os.path.join(gemfiledir, gemspec_file))

elif line.startswith("gem "):
Expand Down
2 changes: 0 additions & 2 deletions tests/README.rst

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/data/gemspecs/arel2.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = arel2
s.version = "2.0.7.beta.20110429111451"

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
s.date = %q{2011-04-29}
s.description = %q{Arel is a SQL AST manager for Ruby.}
s.email = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]
s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown"]
s.files = [".autotest", ".gemtest", "History.txt", "MIT-LICENSE.txt"]
s.homepage = %q{http://github.com/rails/arel}
s.rdoc_options = ["--main", "README.markdown"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{arel}
s.rubygems_version = %q{1.6.1}
s.summary = %q{Arel is a SQL AST manager for Ruby}
s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_as.rb"]

end
8 changes: 8 additions & 0 deletions tests/data/gemspecs/arel2.gemspec-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"development": [],
"runtime": [],
"dependency": [],
"test": [],
"production": [],
"metrics": []
}
File renamed without changes.
41 changes: 25 additions & 16 deletions tests/test_gemfileparser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@
# Copyright (c) Balasankar C <[email protected]> and others
# SPDX-License-Identifier: GPL-3.0-or-later OR MIT

import json
import os

from gemfileparser2 import GemfileParser

TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')


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
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

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

expected_file = test_file + "-expected.json"
expected_file = f"{test_file}-expected.json"
if regen:
with open(expected_file, "w") as o:
json.dump(dependencies, o, indent=2)
Expand All @@ -31,40 +36,44 @@ def check_gemparser_results(test_file, regen=False):


def test_source_only_gemfile():
check_gemparser_results("tests/Gemfile")
check_gemparser_results("gemfiles/Gemfile")


def test_gemfile_1():
check_gemparser_results("tests/Gemfile_1")
check_gemparser_results("gemfiles/Gemfile_1")


def test_gemfile_2():
check_gemparser_results("tests/Gemfile_2")
check_gemparser_results("gemfiles/Gemfile_2")


def test_gemfile_3():
check_gemparser_results("tests/Gemfile_3")
check_gemparser_results("gemfiles/Gemfile_3")


def test_gemfile_4():
check_gemparser_results("tests/Gemfile_4")
check_gemparser_results("gemfiles/Gemfile_4")


def test_gemfile_platforms():
check_gemparser_results("tests/Gemfile_5")
check_gemparser_results("gemfiles/Gemfile_5")


def test_gemspec_1():
check_gemparser_results("tests/sample.gemspec")
check_gemparser_results("gemspecs/sample.gemspec")


def test_gemspec_2():
check_gemparser_results("tests/address_standardization.gemspec")
check_gemparser_results("gemspecs/address_standardization.gemspec")


def test_gemspec_3():
check_gemparser_results("tests/arel.gemspec")
check_gemparser_results("gemspecs/arel.gemspec")


def test_gemspec_no_deps():
check_gemparser_results("gemspecs/arel2.gemspec", regen=False)


def test_gemspec_4():
check_gemparser_results("tests/logstash-mixin-ecs_compatibility_support.gemspec")
check_gemparser_results("gemspecs/logstash-mixin-ecs_compatibility_support.gemspec")