# Path: project_generator/commands/generate.py
# def _setup_logging(args):
# def _generate_project(project, args):
# def run(args):
# def _get_default_jobs():
# def setup(subparser):
# 
# Path: project_generator/commands/clean.py
# def run(args):
# def setup(subparser):
# 
# Path: tests/test_commands/simple_project.py



import argparse
import os
import yaml
import shutil
from unittest import TestCase
from project_generator.commands import generate, clean
from .simple_project import project_1_yaml, projects_yaml, project_2_yaml
        # write projects file
        with open(os.path.join(os.getcwd(), 'test_workspace/projects.yaml'), 'wt') as f:
            f.write(yaml.dump(projects_yaml, default_flow_style=False))

        self.parser = argparse.ArgumentParser()
        subparsers = self.parser.add_subparsers(help='commands')
        self.export_subparser = subparsers.add_parser('generate', help=generate.help)
        self.clean_subparser = subparsers.add_parser('clean', help=clean.help)

    def tearDown(self):
        # remove created directory
        shutil.rmtree('test_workspace', ignore_errors=True)
        shutil.rmtree('generated_projects', ignore_errors=True)


    def test_clean_one_project(self):
        # We first generate project, then clean it
        generate.setup(self.export_subparser)
        args = self.parser.parse_args(['generate','-f','test_workspace/projects.yaml','-p','project_2',
            '-t', 'uvision'])
        result = generate.run(args)

        # this should generate a project to generated_projects/uvision_project_2/project_2.uvproj
        assert os.path.isfile('generated_projects/uvision_project_2/project_2.uvproj')
        assert result == 0

        # now clean
        clean.setup(self.clean_subparser)
        args = self.parser.parse_args(['clean','-f','test_workspace/projects.yaml','-p','project_2',
            '-t', 'uvision'])

# Path: project_generator/commands/generate.py
# def _setup_logging(args):
# def _generate_project(project, args):
# def run(args):
# def _get_default_jobs():
# def setup(subparser):
# 
# Path: project_generator/commands/clean.py
# def run(args):
# def setup(subparser):
# 
# Path: tests/test_commands/simple_project.py



# Path: tests/test_commands/test_clean.py
import argparse
import os
import yaml
import shutil
from unittest import TestCase
from project_generator.commands import generate, clean
from .simple_project import project_1_yaml, projects_yaml, project_2_yaml

        # write projects file
        with open(os.path.join(os.getcwd(), 'test_workspace/projects.yaml'), 'wt') as f:
            f.write(yaml.dump(projects_yaml, default_flow_style=False))

        self.parser = argparse.ArgumentParser()
        subparsers = self.parser.add_subparsers(help='commands')
        self.export_subparser = subparsers.add_parser('generate', help=generate.help)
        self.clean_subparser = subparsers.add_parser('clean', help=clean.help)

    def tearDown(self):
        # remove created directory
        shutil.rmtree('test_workspace', ignore_errors=True)
        shutil.rmtree('generated_projects', ignore_errors=True)


    def test_clean_one_project(self):
        # We first generate project, then clean it
        generate.setup(self.export_subparser)
        args = self.parser.parse_args(['generate','-f','test_workspace/projects.yaml','-p','project_2',
            '-t', 'uvision'])
        result = generate.run(args)

        # this should generate a project to generated_projects/uvision_project_2/project_2.uvproj
        assert os.path.isfile('generated_projects/uvision_project_2/project_2.uvproj')
        assert result == 0

        # now clean
        clean.setup(self.clean_subparser)
        args = self.parser.parse_args(['clean','-f','test_workspace/projects.yaml','-p','project_2',
            '-t', 'uvision'])

        result = clean.run(args)