Skip to content

Commit

Permalink
fix(pain001): 🐛 fix #47
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed May 19, 2024
1 parent cb3892a commit 1145208
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 41 deletions.
49 changes: 17 additions & 32 deletions pain001/__main__.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
# Copyright (C) 2023 Sebastien Rousseau.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=invalid-name
"""
Enables use of Python Pain001 as a "main" function (i.e.
"python3 -m pain001
<xml_message_type> <xml_template_file_path> <xsd_schema_file_path>
<data_file_path>").
This allows using Pain001 with third-party libraries without modifying
their code.
"""


# Other imports remain the same
import click
import os
import sys
import click

from pain001.constants.constants import valid_xml_types
from pain001.context.context import Context
from pain001.core.core import process_files

from rich.console import Console
from rich.table import Table
from rich import box
Expand All @@ -47,7 +19,6 @@
title = "Pain001"

table = Table(box=box.ROUNDED, safe_box=True, show_header=False, title=title)

table.add_column(justify="center", no_wrap=False, vertical="middle")
table.add_row(description)
table.width = 80
Expand Down Expand Up @@ -85,6 +56,20 @@
type=click.Path(),
help="Path to data file (CSV or SQLite) (required)",
)
def cli(
xml_message_type,
xml_template_file_path,
xsd_schema_file_path,
data_file_path,
):
main(
xml_message_type,
xml_template_file_path,
xsd_schema_file_path,
data_file_path,
)


def main(
xml_message_type,
xml_template_file_path,
Expand Down Expand Up @@ -163,4 +148,4 @@ def main(

if __name__ == "__main__":
# pylint: disable=no-value-for-parameter
main()
cli()
18 changes: 9 additions & 9 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from click.testing import CliRunner
from pain001.__main__ import main
from pain001.__main__ import cli


class TestMain:
Expand All @@ -12,7 +12,7 @@ def setup_method(self):

def test_main_with_valid_files(self):
result = self.runner.invoke(
main,
cli,
[
"--xml_message_type",
self.xml_message_type,
Expand All @@ -32,7 +32,7 @@ def test_main_with_valid_files(self):

def test_main_with_missing_xml_message_type(self):
result = self.runner.invoke(
main,
cli,
[
"--xml_template_file_path",
self.xml_file,
Expand All @@ -47,7 +47,7 @@ def test_main_with_missing_xml_message_type(self):

def test_main_with_missing_xsd_template_file(self):
result = self.runner.invoke(
main,
cli,
[
"--xml_message_type",
self.xml_message_type,
Expand All @@ -62,7 +62,7 @@ def test_main_with_missing_xsd_template_file(self):

def test_main_with_missing_data_file(self):
result = self.runner.invoke(
main,
cli,
[
"--xml_message_type",
self.xml_message_type,
Expand All @@ -77,7 +77,7 @@ def test_main_with_missing_data_file(self):

def test_main_with_invalid_xml_message_type(self):
result = self.runner.invoke(
main,
cli,
[
"--xml_message_type",
"invalid",
Expand All @@ -94,7 +94,7 @@ def test_main_with_invalid_xml_message_type(self):

def test_main_with_invalid_xml_template_file(self):
result = self.runner.invoke(
main,
cli,
[
"--xml_message_type",
self.xml_message_type,
Expand All @@ -113,7 +113,7 @@ def test_main_with_invalid_xml_template_file(self):

def test_main_with_invalid_xsd_template_file(self):
result = self.runner.invoke(
main,
cli,
[
"--xml_message_type",
self.xml_message_type,
Expand All @@ -132,7 +132,7 @@ def test_main_with_invalid_xsd_template_file(self):

def test_main_with_invalid_data_file(self):
result = self.runner.invoke(
main,
cli,
[
"--xml_message_type",
self.xml_message_type,
Expand Down

0 comments on commit 1145208

Please sign in to comment.