Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

WIP: Maven simple E2E test added #184

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ jobs:
run: |
pip install mypy
pipenv run check-types
- name: End-to-End tests
run: |
pipenv run test-e2e
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ allow_prereleases = true
[scripts]
lint = "flake8 . --count --max-complexity=10 --max-line-length=127 --statistics"
check-types = "mypy ./license-sh"
test = "python -m unittest"
test = "python -m unittest discover -s ./tests"
test-e2e = "python -m unittest discover -s ./tests_e2e"
Empty file added tests_e2e/__init__.py
Empty file.
Empty file added tests_e2e/test_data/__init__.py
Empty file.
59 changes: 59 additions & 0 deletions tests_e2e/test_data/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sh.license</groupId>
<version>0.9.23</version>
<artifactId>license</artifactId>
<name>license-sh maven test</name>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.22.0-GA</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.20</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.20</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
45 changes: 45 additions & 0 deletions tests_e2e/test_maven.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest

from license_sh.commands.run_license_sh import run_license_sh
from anytree.importer import JsonImporter
from unittest.mock import patch
from tests_e2e import test_data
from importlib import resources

ARGUMENTS = {
'--config': None,
'--debug': False,
'--dependencies': False,
'--help': False,
'--interactive': False,
'--output': 'console',
'--project': None,
'--tree': False,
'--version': False,
'<path>': None,
'config': False
}


class MavenCase(unittest.TestCase):
@patch('builtins.print')
def test_valid_json(self, print_mock):
with resources.path(test_data, "") as test_data_path:
with self.assertRaises(SystemExit):
run_license_sh({**ARGUMENTS, **{
'--output': 'json',
'<path>': test_data_path,
'--project': 'maven'
}})
calls = print_mock.call_args_list

std_out = ""
for call in calls:
file_arg = call.kwargs.get('file', None)
if not file_arg:
std_out += ''.join(call.args)
self.assertTrue(bool(JsonImporter().import_(std_out)))


if __name__ == '__main__':
unittest.main()