# Path: diffoscope/main.py
# def main(args=None):
#     if args is None:
#         args = sys.argv[1:]
#     signal.signal(signal.SIGTERM, sigterm_handler)
#     parsed_args = None
#     try:
#         with profile('main', 'parse_args'):
#             parser = create_parser()
#             parsed_args = parser.parse_args(args)
#         sys.exit(run_diffoscope(parsed_args))
#     except KeyboardInterrupt:
#         logger.info('Keyboard Interrupt')
#         sys.exit(2)
#     except BrokenPipeError:
#         sys.exit(2)
#     except Exception:
#         traceback.print_exc()
#         if parsed_args and parsed_args.debugger:
#             import pdb
#             pdb.post_mortem()
#         sys.exit(2)
#     finally:
#         with profile('main', 'cleanup'):
#             clean_all_temp_files()
# 
#         # Print profiling output at the very end
#         if parsed_args is not None:
#             ProfileManager().finish(parsed_args)
# 
# Path: diffoscope/progress.py
# class ProgressManager(object):
#     _singleton = {}
# 
#     def __init__(self):
#         self.__dict__ = self._singleton
# 
#         if not self._singleton:
#             self.reset()
# 
#     def reset(self):
#         self.total = 0
#         self.current = 0
#         self.observers = []
# 
#     def setup(self, parsed_args):
#         # Show progress bar if user explicitly asked for it, otherwise show if
#         # STDOUT is a tty.
#         if parsed_args.progress or \
#                 (parsed_args.progress is None and sys.stdout.isatty()):
#             try:
#                 self.register(ProgressBar())
#             except ImportError:
#                 # User asked for bar, so show them the error
#                 if parsed_args.progress:
#                     raise
# 
#         if parsed_args.status_fd:
#             self.register(StatusFD(os.fdopen(parsed_args.status_fd, 'w')))
# 
#     ##
# 
#     def register(self, observer):
#         logger.debug("Registering %s as a progress observer", observer)
# 
#         self.observers.append(observer)
# 
#     def step(self, delta=1, msg=""):
#         delta = min(self.total - self.current, delta) # clamp
# 
#         self.current += delta
#         for x in self.observers:
#             x.notify(self.current, self.total, msg)
# 
#     def new_total(self, delta, msg):
#         self.total += delta
#         for x in self.observers:
#             x.notify(self.current, self.total, msg)
# 
#     def finish(self):
#         for x in self.observers:
#             x.finish()
# 
# class StatusFD(object):
#     def __init__(self, fileobj):
#         self.fileobj = fileobj
# 
#     def notify(self, current, total, msg):
#         print(json.dumps({
#             'msg': msg,
#             'total': total,
#             'current': current,
#         }), file=self.fileobj)
# 
#     def finish(self):
#         pass


import os
import sys
import json
import pytest
from diffoscope.main import main
from diffoscope.progress import ProgressManager, StatusFD
from comparators.utils.tools import skip_unless_module_exists
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2017 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.




TEST_TAR1_PATH = os.path.join(os.path.dirname(__file__), 'data', 'test1.tar')
TEST_TAR2_PATH = os.path.join(os.path.dirname(__file__), 'data', 'test2.tar')


def run(capsys, *args):
    with pytest.raises(SystemExit) as exc:

# Path: diffoscope/main.py
# def main(args=None):
#     if args is None:
#         args = sys.argv[1:]
#     signal.signal(signal.SIGTERM, sigterm_handler)
#     parsed_args = None
#     try:
#         with profile('main', 'parse_args'):
#             parser = create_parser()
#             parsed_args = parser.parse_args(args)
#         sys.exit(run_diffoscope(parsed_args))
#     except KeyboardInterrupt:
#         logger.info('Keyboard Interrupt')
#         sys.exit(2)
#     except BrokenPipeError:
#         sys.exit(2)
#     except Exception:
#         traceback.print_exc()
#         if parsed_args and parsed_args.debugger:
#             import pdb
#             pdb.post_mortem()
#         sys.exit(2)
#     finally:
#         with profile('main', 'cleanup'):
#             clean_all_temp_files()
# 
#         # Print profiling output at the very end
#         if parsed_args is not None:
#             ProfileManager().finish(parsed_args)
# 
# Path: diffoscope/progress.py
# class ProgressManager(object):
#     _singleton = {}
# 
#     def __init__(self):
#         self.__dict__ = self._singleton
# 
#         if not self._singleton:
#             self.reset()
# 
#     def reset(self):
#         self.total = 0
#         self.current = 0
#         self.observers = []
# 
#     def setup(self, parsed_args):
#         # Show progress bar if user explicitly asked for it, otherwise show if
#         # STDOUT is a tty.
#         if parsed_args.progress or \
#                 (parsed_args.progress is None and sys.stdout.isatty()):
#             try:
#                 self.register(ProgressBar())
#             except ImportError:
#                 # User asked for bar, so show them the error
#                 if parsed_args.progress:
#                     raise
# 
#         if parsed_args.status_fd:
#             self.register(StatusFD(os.fdopen(parsed_args.status_fd, 'w')))
# 
#     ##
# 
#     def register(self, observer):
#         logger.debug("Registering %s as a progress observer", observer)
# 
#         self.observers.append(observer)
# 
#     def step(self, delta=1, msg=""):
#         delta = min(self.total - self.current, delta) # clamp
# 
#         self.current += delta
#         for x in self.observers:
#             x.notify(self.current, self.total, msg)
# 
#     def new_total(self, delta, msg):
#         self.total += delta
#         for x in self.observers:
#             x.notify(self.current, self.total, msg)
# 
#     def finish(self):
#         for x in self.observers:
#             x.finish()
# 
# class StatusFD(object):
#     def __init__(self, fileobj):
#         self.fileobj = fileobj
# 
#     def notify(self, current, total, msg):
#         print(json.dumps({
#             'msg': msg,
#             'total': total,
#             'current': current,
#         }), file=self.fileobj)
# 
#     def finish(self):
#         pass


# Path: tests/test_progress.py
import os
import sys
import json
import pytest
from diffoscope.main import main
from diffoscope.progress import ProgressManager, StatusFD
from comparators.utils.tools import skip_unless_module_exists

# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2017 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.




TEST_TAR1_PATH = os.path.join(os.path.dirname(__file__), 'data', 'test1.tar')
TEST_TAR2_PATH = os.path.join(os.path.dirname(__file__), 'data', 'test2.tar')


def run(capsys, *args):
    with pytest.raises(SystemExit) as exc:

        main(args)