# Path: moult/utils.py
# def load_stdlib():
# def is_stdlib(module):
# def is_import_str(text):
# def import_path_from_file(filename, as_list=False):
# def file_containing_import(import_path, import_root):
# def resolve_import(import_path, from_module):
# def find_package(name, installed, package=False):
# def is_script(filename):
# def is_python_script(filename):
# def iter_dist_files(dist):
# def installed_packages(local=False):
# 
# Path: moult/classes.py
# class PyModule(object):
#     def __init__(self, name, version, location='', missing=False):
#         self.name = name
#         self.import_names = [name]
#         self.version = version
#         self.is_scan = version in ('SCRIPT', 'MODULE', 'DIRECTORY')
#         self.frameworks = []
#         self.location = location
#         self._dependencies = []  # The string list of dependencies
#         self.dependencies = []
#         self.dependants = []
#         self._dependants = []  # This is a shadow dependant list for the turtles
#         self.installed_scripts = []
#         self.installed_files = []
#         self.user = False
#         self.local = False
#         self.hidden = False
#         self.missing = missing
# 
#     def set_import_names(self, names):
#         self.import_names = [x.replace('/', '.') for x in names]
# 
#     def add_framework(self, framework):
#         if framework not in self.frameworks:
#             self.frameworks.append(framework)
# 
#     def add_dependency(self, dep):
#         if dep not in self.dependencies:
#             if dep.is_scan:
#                 self.dependencies.insert(0, dep)
#             else:
#                 self.dependencies.append(dep)
# 
#     def remove_dependency(self, dep):
#         if dep in self.dependencies:
#             self.dependencies.remove(dep)
# 
#     def add_dependant(self, dep):
#         if dep not in self.dependants:
#             if dep.is_scan:
#                 self.dependants.insert(0, dep)
#                 self._dependants.insert(0, dep)
#             else:
#                 self.dependants.append(dep)
#                 self._dependants.append(dep)
# 
#     def remove_dependant(self, dep):
#         if dep in self._dependants:
#             self._dependants.remove(dep)
# 
#     def restore_dependants(self):
#         self._dependants = self.dependants[:]
# 
#     def __hash__(self):
#         return hash((self.name, self.version))
# 
#     def __unicode__(self):
#         if self.is_scan:
#             fmt = '{name} [{version}]'
#         else:
#             fmt = '{name} ({version})'
#         return fmt.format(name=self.name, version=self.version)
# 
#     def __str__(self):
#         if PY3:
#             return self.__unicode__()
#         return self.__unicode__().encode('utf8')
# 
#     def __bytes__(self):
#         return self.__unicode__().encode('utf8')
# 
#     def __repr__(self):
#         r = '<PyModule {}>'.format(self.__unicode__())
#         if PY3:
#             return r
#         return r.encode('utf8')


import sys
import pytest
from moult import utils
from moult.classes import PyModule
    'distutils', 'doctest', 'dummy_threading', 'email', 'encodings',
    'errno', 'filecmp', 'fileinput', 'fnmatch', 'formatter', 'fractions',
    'ftplib', 'functools', 'gc', 'getopt', 'getpass', 'gettext', 'glob',
    'gzip', 'hashlib', 'heapq', 'hmac', 'html', 'http', 'imaplib', 'imghdr',
    'imp', 'importlib', 'inspect', 'io', 'itertools', 'json', 'keyword',
    'lib2to3', 'linecache', 'locale', 'logging', 'macpath', 'mailbox',
    'mailcap', 'marshal', 'math', 'mimetypes', 'mmap', 'modulefinder',
    'multiprocessing', 'netrc', 'nntplib', 'numbers', 'operator', 'os',
    'parser', 'pdb', 'pickle', 'pickletools', 'pkgutil', 'platform',
    'plistlib', 'poplib', 'pprint', 'profile', 'pstats', 'py_compile',
    'pyclbr', 'pydoc', 'queue', 'quopri', 'random', 're', 'reprlib',
    'rlcompleter', 'runpy', 'sched', 'select', 'shelve', 'shlex', 'shutil',
    'signal', 'site', 'smtpd', 'smtplib', 'sndhdr', 'socket',
    'socketserver', 'sqlite3', 'ssl', 'stat', 'string', 'struct',
    'subprocess', 'sunau', 'symbol', 'symtable', 'sys', 'sysconfig',
    'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'test', 'textwrap',
    'threading', 'time', 'timeit', 'tkinter', 'token', 'tokenize', 'trace',
    'traceback', 'turtle', 'types', 'unicodedata', 'unittest', 'urllib',
    'uu', 'uuid', 'warnings', 'wave', 'weakref', 'webbrowser', 'wsgiref',
    'xdrlib', 'xml', 'xmlrpc', 'zipfile', 'zipimport', 'zlib',
)


def test_installed_packages(data):
    installed = data.copy_installed()
    assert len(installed)

    for pkg in installed:
        assert isinstance(pkg, PyModule), 'Item in installed packages is not a PyModule instance'
        assert len(pkg.import_names), 'Installed package has no import path names'

# Path: moult/utils.py
# def load_stdlib():
# def is_stdlib(module):
# def is_import_str(text):
# def import_path_from_file(filename, as_list=False):
# def file_containing_import(import_path, import_root):
# def resolve_import(import_path, from_module):
# def find_package(name, installed, package=False):
# def is_script(filename):
# def is_python_script(filename):
# def iter_dist_files(dist):
# def installed_packages(local=False):
# 
# Path: moult/classes.py
# class PyModule(object):
#     def __init__(self, name, version, location='', missing=False):
#         self.name = name
#         self.import_names = [name]
#         self.version = version
#         self.is_scan = version in ('SCRIPT', 'MODULE', 'DIRECTORY')
#         self.frameworks = []
#         self.location = location
#         self._dependencies = []  # The string list of dependencies
#         self.dependencies = []
#         self.dependants = []
#         self._dependants = []  # This is a shadow dependant list for the turtles
#         self.installed_scripts = []
#         self.installed_files = []
#         self.user = False
#         self.local = False
#         self.hidden = False
#         self.missing = missing
# 
#     def set_import_names(self, names):
#         self.import_names = [x.replace('/', '.') for x in names]
# 
#     def add_framework(self, framework):
#         if framework not in self.frameworks:
#             self.frameworks.append(framework)
# 
#     def add_dependency(self, dep):
#         if dep not in self.dependencies:
#             if dep.is_scan:
#                 self.dependencies.insert(0, dep)
#             else:
#                 self.dependencies.append(dep)
# 
#     def remove_dependency(self, dep):
#         if dep in self.dependencies:
#             self.dependencies.remove(dep)
# 
#     def add_dependant(self, dep):
#         if dep not in self.dependants:
#             if dep.is_scan:
#                 self.dependants.insert(0, dep)
#                 self._dependants.insert(0, dep)
#             else:
#                 self.dependants.append(dep)
#                 self._dependants.append(dep)
# 
#     def remove_dependant(self, dep):
#         if dep in self._dependants:
#             self._dependants.remove(dep)
# 
#     def restore_dependants(self):
#         self._dependants = self.dependants[:]
# 
#     def __hash__(self):
#         return hash((self.name, self.version))
# 
#     def __unicode__(self):
#         if self.is_scan:
#             fmt = '{name} [{version}]'
#         else:
#             fmt = '{name} ({version})'
#         return fmt.format(name=self.name, version=self.version)
# 
#     def __str__(self):
#         if PY3:
#             return self.__unicode__()
#         return self.__unicode__().encode('utf8')
# 
#     def __bytes__(self):
#         return self.__unicode__().encode('utf8')
# 
#     def __repr__(self):
#         r = '<PyModule {}>'.format(self.__unicode__())
#         if PY3:
#             return r
#         return r.encode('utf8')


# Path: tests/test_utils.py
import sys
import pytest
from moult import utils
from moult.classes import PyModule

    'distutils', 'doctest', 'dummy_threading', 'email', 'encodings',
    'errno', 'filecmp', 'fileinput', 'fnmatch', 'formatter', 'fractions',
    'ftplib', 'functools', 'gc', 'getopt', 'getpass', 'gettext', 'glob',
    'gzip', 'hashlib', 'heapq', 'hmac', 'html', 'http', 'imaplib', 'imghdr',
    'imp', 'importlib', 'inspect', 'io', 'itertools', 'json', 'keyword',
    'lib2to3', 'linecache', 'locale', 'logging', 'macpath', 'mailbox',
    'mailcap', 'marshal', 'math', 'mimetypes', 'mmap', 'modulefinder',
    'multiprocessing', 'netrc', 'nntplib', 'numbers', 'operator', 'os',
    'parser', 'pdb', 'pickle', 'pickletools', 'pkgutil', 'platform',
    'plistlib', 'poplib', 'pprint', 'profile', 'pstats', 'py_compile',
    'pyclbr', 'pydoc', 'queue', 'quopri', 'random', 're', 'reprlib',
    'rlcompleter', 'runpy', 'sched', 'select', 'shelve', 'shlex', 'shutil',
    'signal', 'site', 'smtpd', 'smtplib', 'sndhdr', 'socket',
    'socketserver', 'sqlite3', 'ssl', 'stat', 'string', 'struct',
    'subprocess', 'sunau', 'symbol', 'symtable', 'sys', 'sysconfig',
    'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'test', 'textwrap',
    'threading', 'time', 'timeit', 'tkinter', 'token', 'tokenize', 'trace',
    'traceback', 'turtle', 'types', 'unicodedata', 'unittest', 'urllib',
    'uu', 'uuid', 'warnings', 'wave', 'weakref', 'webbrowser', 'wsgiref',
    'xdrlib', 'xml', 'xmlrpc', 'zipfile', 'zipimport', 'zlib',
)


def test_installed_packages(data):
    installed = data.copy_installed()
    assert len(installed)

    for pkg in installed:
        assert isinstance(pkg, PyModule), 'Item in installed packages is not a PyModule instance'
        assert len(pkg.import_names), 'Installed package has no import path names'

        pkg2 = PyModule(pkg.name, pkg.version, pkg.location, pkg.missing)