Esempio n. 1
0
def test_project_seeks_project_path():
    fake_project_sub_directory = fixture_path('sample_project/lev1/lev2')
    base_parser = create_base_parser()
    base_options = base_parser.parse_args(args=[])
    with in_directory(fake_project_sub_directory):
        project = Project.load(base_options)
        assert project.path() == fixture_path('sample_project')
        assert project.name == 'sample_project'
Esempio n. 2
0
def test_project_seeks_project_path():
    fake_project_sub_directory = fixture_path('sample_project/lev1/lev2')
    base_parser = create_base_parser()
    base_options = base_parser.parse_args(args=[])
    with in_directory(fake_project_sub_directory):
        project = Project.load(base_options)
        assert project.path() == fixture_path('sample_project')
        assert project.name == 'sample_project'
Esempio n. 3
0
    def setup(self):
        self._logger_spy = LoggerSpy()
        self._current_version = "0.0.1"
        self._bumped_version = "0.1.0"

        self._tmp_folder = tmp_folder()
        copy_tree(fixture_path("executors/before"), self._tmp_folder)
Esempio n. 4
0
def test_test_environment_context():
    templates_path = fixture_path('templates')
    with temp_template_environment(templates_path):
        env = environment()
        env.get_template('tests/test_template.sh.tmpl')
    env = environment()
    template = env.get_template('init/activate.sh.tmpl')
Esempio n. 5
0
def test_test_environment_context():
    templates_path = fixture_path('templates')
    with temp_template_environment(templates_path):
        env = environment()
        env.get_template('tests/test_template.sh.tmpl')
    env = environment()
    template = env.get_template('init/activate.sh.tmpl')
Esempio n. 6
0
    def test_get_trade_latest_returns_expected(self):
        xls_io = fixture_path(ba_name=self.c.__module__, filename='data1.xls')
        self.c.fetch_xls = MagicMock(return_value=ExcelFile(xls_io))

        results = self.c.get_trade(latest=True)
        self.assertTrue(len(results), 1)
        self.assertEqual(results[0]['timestamp'], Timestamp('2017-10-16T12:40:00Z'))
        self.assertAlmostEqual(results[0]['net_exp_MW'], 964.22479248)
def test_test_environment_context():
    from jinja2 import FileSystemLoader
    templates_path = fixture_path('templates')
    with temp_template_environment(templates_path):
        env = environment()
        env.get_template('tests/test_template.sh.jinja')
    env = environment()
    template = env.get_template('init/activate.sh.jinja')
Esempio n. 8
0
    def test_get_trade_yesterday_returns_expected(self):
        xls_io = fixture_path(ba_name=self.c.__module__, filename='data1.xls')
        self.c.fetch_xls = MagicMock(return_value=ExcelFile(xls_io))

        results = self.c.get_trade(yesterday=True)
        self.assertTrue(len(results), 288)  # 24 hours * 12 observations per hour
        self.assertEqual(results[0]['timestamp'], Timestamp('2017-10-15T07:00:00Z'))
        self.assertAlmostEqual(results[0]['net_exp_MW'], 662.693040848)
        self.assertEqual(results[287]['timestamp'], Timestamp('2017-10-16T06:55:00Z'))
        self.assertAlmostEqual(results[287]['net_exp_MW'], 700.70085144)
Esempio n. 9
0
def test_in_directory_raises_error():
    raised_error = False
    original_working_dir = os.getcwd()
    basic_project_dir = fixture_path('sample_project')
    try:
        with in_directory(basic_project_dir):
            raise TestException()
    except TestException:
        raised_error = True
    assert raised_error
    assert os.getcwd() == original_working_dir
Esempio n. 10
0
def test_in_directory_raises_error():
    raised_error = False
    original_working_dir = os.getcwd()
    basic_project_dir = fixture_path('sample_project')
    try:
        with in_directory(basic_project_dir):
            raise TestException()
    except TestException:
        raised_error = True
    assert raised_error
    assert os.getcwd() == original_working_dir
Esempio n. 11
0
    def test_config_semver(self):
        config_file = fixture_path("config/.bumpit-semver.yaml")
        config = Configuration.parse(file=config_file)

        assert config.config_file == config_file
        assert config.current_version == "0.0.1"
        assert config.strategy.name == "semver"
        assert config.strategy.part == "minor"
        assert config.tag.apply
        assert config.tag.format == "{version}"
        assert config.auto_remote_push is False
        assert config.tracked_files == ["setup.py", "sample/VERSION"]
Esempio n. 12
0
    def test_get_trade_valid_range_returns_expected(self):
        xls_io = fixture_path(ba_name=self.c.__module__, filename='data1.xls')
        self.c.fetch_xls = MagicMock(return_value=ExcelFile(xls_io))
        start_at = self.tzaware_utcnow - timedelta(days=3)
        end_at = self.tzaware_utcnow - timedelta(days=1)

        results = self.c.get_trade(start_at=start_at, end_at=end_at)
        self.assertTrue(len(results), 576)  # 48 hours * 12 observations per hour
        self.assertEqual(results[0]['timestamp'], Timestamp('2017-10-13T12:45:00Z'))
        self.assertAlmostEqual(results[0]['net_exp_MW'], 1072.920944214)
        self.assertEqual(results[575]['timestamp'], Timestamp('2017-10-15T12:40:00Z'))
        self.assertAlmostEqual(results[575]['net_exp_MW'], 506.151199341)
Esempio n. 13
0
def test_project_command_renders_template(FakeProject):
    """Test that a project command adds current project to the context"""
    (FakeProject.expects('load')
            .with_args('options').returns('proj'))
    with temp_template_environment(fixture_path('templates')):
        class FakeCommand(NoEventProjectCommand):
            name = 'test'
            def run(self, project, options, **kwargs):
                assert self.render_template_string('{{project}}') == 'proj'
                assert self.render_template(
                        'tests/test_project_template.sh.tmpl').strip() == 'proj'
        command = FakeCommand()
        assert command.execute(None, 'options', test='test') == 0
Esempio n. 14
0
    def test_config_calver(self):
        config_file = fixture_path("config/.bumpit-calver.yaml")
        config = Configuration.parse(file=config_file)

        assert config.config_file == config_file
        assert config.current_version == "201910.1.0"
        assert config.strategy.name == "calver"
        assert config.strategy.part == "auto"
        assert config.strategy.version_format == "YYYYMM.MINOR.MICRO"
        assert config.tag.apply
        assert config.tag.format == "{version}"
        assert config.auto_remote_push is False
        assert config.tracked_files == ["setup.py", "sample/VERSION"]
Esempio n. 15
0
    def test_config_custom_base_branch(self):
        config_file = fixture_path("config/.bumpit-custom-base.yaml")
        config = Configuration.parse(file=config_file)

        assert config.base_branch == "main"
        assert config.config_file == config_file
        assert config.current_version == "0.0.1"
        assert config.strategy.name == "semver"
        assert config.strategy.part == "minor"
        assert config.tag.apply
        assert config.tag.format == "{version}"
        assert config.auto_remote_push is False
        assert config.tracked_files == ["setup.py"]
Esempio n. 16
0
def test_project_command_runs_with_project_not_faked():
    """Test NoEventProjectCommand in a sandbox"""
    class FakeProjectCommand(NoEventProjectCommand):
        name = 'test'
        def run(self, project, options, **kwargs):
            self.called = True
            assert project.name == 'sample_project'
            assert project.env_path().endswith('sample_project/.vs.env')
    from virtstrap.options import create_base_parser
    base_parser = create_base_parser()
    base_options = base_parser.parse_args(args=[])
    fake_project_sub_directory = fixture_path('sample_project/lev1/lev2')
    with in_directory(fake_project_sub_directory):
        command = FakeProjectCommand()
        return_code = command.execute(None, base_options)
        assert return_code == 0
        assert_called_flag(command)
Esempio n. 17
0
def test_command_renders_template_string():
    """Test that command renders a template string"""
    with temp_template_environment(fixture_path('templates')):
        class FakeCommand(NoEventCommand):
            name = 'test'
            def run(self, *args, **kwargs):
                self.called = True
                assert self.render_template_string(
                        '{{command.name}}') == 'test'
                assert self.render_template_string(
                        '{{options}}') == 'options'
                # Test with a user defined context
                assert self.render_template_string(
                        '{{testvalue}}', testvalue='foo') == 'foo'
        command = FakeCommand()
        return_code = command.execute(None, 'options')
        assert return_code == 0
        assert_called_flag(command)
Esempio n. 18
0
def test_command_renders_template():
    """Test that command renders a template file"""
    with temp_template_environment(fixture_path('templates')):
        class FakeCommand(NoEventCommand):
            name = 'test'
            def run(self, *args, **kwargs):
                self.called = True
                # Test with the default context
                assert self.render_template(
                        'tests/test_template.sh.tmpl').strip() == 'test::options'
                # Test with a user defined context
                assert self.render_template(
                        'tests/test_with_context.sh.tmpl', 
                        testvalue='bar').strip() == 'bar'
        command = FakeCommand()
        return_code = command.execute(None, 'options')
        assert return_code == 0
        assert_called_flag(command)
Esempio n. 19
0
    def test_update(self):
        files = self._tracked_files()
        executor = FolderManager(folder=self._tmp_folder,
                                 logger=self._logger_spy,
                                 dry_run=False)
        executor.update(
            current_version=self._current_version,
            bumped_version=self._bumped_version,
            files=files,
        )

        assert [
            (f"Could not find version {self._current_version} in file '{files[0]}'. "
             f"Skipping..."),
            (f"--- before: {files[1]}\n"
             f"+++ after: {files[1]}\n"
             f"@@ -1 +1 @@\n"
             f"-{self._current_version}\n"
             f"+{self._bumped_version}"),
            f"Updated file '{files[1]}'.",
            (f"--- before: {files[2]}\n"
             f"+++ after: {files[2]}\n"
             f"@@ -1,4 +1,4 @@\n"
             f" 14.04.6-LTS\n"
             f"-            {self._current_version}...\n"
             f"+            {self._bumped_version}...\n"
             f" and another one\n"
             f"-{self._current_version}\n"
             f"+{self._bumped_version}"),
            f"Updated file '{files[2]}'.",
            (f"Could not find version {self._current_version} in file '{files[3]}'. "
             f"Skipping..."),
        ] == self._logger_spy.messages

        for index in range(0, 4):
            expected = self._file_contents(
                fixture_path(f"executors/after/file{index}"))
            actual = self._file_contents(files[index])
            assert expected == actual
Esempio n. 20
0
def test_find_project_directory_from_sample_project():
    fake_project_sub_directory = fixture_path('sample_project')
    with in_directory(fake_project_sub_directory):
        project_dir = find_project_dir()
        assert project_dir == fixture_path('sample_project')
Esempio n. 21
0
 def test_config_invalid_tag(self):
     with pytest.raises(ValueError):
         Configuration.parse(
             file=fixture_path("config/.bumpit-invalid-tag.yaml"))
Esempio n. 22
0
from tests import fixture_path


def fake_req(name, lock_string=None):
    lock_string = lock_string or name
    fake = fudge.Fake()
    fake.has_attr(name=name, req=name)
    fake.provides("to_pip_str").returns(lock_string)
    return fake


def test_initialize_locker():
    locker = RequirementsLocker()


PACKAGES_DIR = fixture_path("packages")


def test_initialize_locked_requirement_set():
    fake_graph = fudge.Fake()
    top_level_requirements = []
    locked_req_set = LockedRequirementSet(fake_graph, top_level_requirements)


@fudge.patch("virtstrap.locker.RequirementsGraphDisplay")
def test_display_locked_requirement_set(fake_display):
    fake_graph = fudge.Fake("RequirementsGraph")
    top_level_requirements = []
    fake_display_func = fudge.Fake()
    locked_req_set = LockedRequirementSet(fake_graph, top_level_requirements)
    fake_display.expects("graph_to_str").with_args(
Esempio n. 23
0
def test_load_from_file():
    """Load configuration from a file"""
    config = VirtstrapConfig.from_file(fixture_path('test.yml'))
    assert isinstance(config, VirtstrapConfig)
Esempio n. 24
0
 def test_config_missing_fields(self):
     with pytest.raises(ValueError):
         Configuration.parse(
             file=fixture_path("config/.bumpit-missing-fields.yaml"))
Esempio n. 25
0
from virtstrap.locker import *
from tests import fixture_path


def fake_req(name, lock_string=None):
    lock_string = lock_string or name
    fake = fudge.Fake()
    fake.has_attr(name=name, req=name)
    fake.provides('to_pip_str').returns(lock_string)
    return fake


def test_initialize_locker():
    locker = RequirementsLocker()

PACKAGES_DIR = fixture_path('packages')


def test_initialize_locked_requirement_set():
    fake_graph = fudge.Fake()
    top_level_requirements = []
    locked_req_set = LockedRequirementSet(fake_graph, top_level_requirements)


@fudge.patch('virtstrap.locker.RequirementsGraphDisplay')
def test_display_locked_requirement_set(fake_display):
    fake_graph = fudge.Fake('RequirementsGraph')
    top_level_requirements = []
    fake_display_func = fudge.Fake()
    locked_req_set = LockedRequirementSet(fake_graph, top_level_requirements)
    fake_display.expects('graph_to_str').with_args(fake_graph, top_level_requirements,
Esempio n. 26
0
def test_in_directory():
    """Test change CWD to a specific directory"""
    basic_project_dir = fixture_path('sample_project')
    with in_directory(basic_project_dir):
        assert basic_project_dir == os.path.abspath('.')
    assert basic_project_dir != os.path.abspath('.')
Esempio n. 27
0
def test_file_system_loader():
    loader = FileSystemLoader(fixture_path('templates'))
    fake_env = fake_environment()
    template = loader.get_template('tests/test_template.tmpl', fake_env)
    assert template is not None
Esempio n. 28
0
 def setup(self):
     template_path = fixture_path('templates')
     loaders = [FileSystemLoader(template_path)]
     self.env = TempitaEnvironment(loaders=loaders)
Esempio n. 29
0
def test_load_from_file_does_not_exist():
    """Load a configuration file even if it doesn't exist"""
    config = VirtstrapConfig.from_file(fixture_path('i_do_not_exist____.yml'))
    assert isinstance(config, VirtstrapConfig)
import sys
import os
import fudge
from fudge.patcher import patch_object
from nose.plugins.attrib import attr
from tests import fixture_path
from virtstrap import constants
from virtstrap.testing import *
from virtstrap_local.commands.install import InstallCommand

PACKAGES_DIR = fixture_path('packages')

def test_initialize_command():
    command = InstallCommand()

class SpecialFake(fudge.Fake):
    def __iter__(self):
        return iter(self.__iter_patch__())

def fake_requirements(names):
    requirements = []
    for name in names:
        fake = fudge.Fake(name)
        fake.has_attr(name=name)
        requirements.append(fake)
    return requirements

def test_special_fake_works():
    fake = SpecialFake()
    fake.expects('__iter_patch__').returns(fake_requirements(['test1']))
    looped = False
Esempio n. 31
0
def test_in_directory():
    """Test change CWD to a specific directory"""
    basic_project_dir = fixture_path('sample_project')
    with in_directory(basic_project_dir):
        assert basic_project_dir == os.path.abspath('.')
    assert basic_project_dir != os.path.abspath('.')
Esempio n. 32
0
 def test_run(self):
     run(
         config=fixture_path("config/.bumpit-lite.yaml"),
         logger=LoggerSpy(),
         run_settings=RunSettings(dry_run=True, target_part=None, force_value=None),
     )
Esempio n. 33
0
def test_find_project_directory_from_sample_project():
    fake_project_sub_directory = fixture_path('sample_project')
    with in_directory(fake_project_sub_directory):
        project_dir = find_project_dir()
        assert project_dir == fixture_path('sample_project')
Esempio n. 34
0
def test_load_from_file_does_not_exist():
    """Load a configuration file even if it doesn't exist"""
    config = VirtstrapConfig.from_file(fixture_path('i_do_not_exist____.yml'))
    assert isinstance(config, VirtstrapConfig)
Esempio n. 35
0
def test_load_from_file():
    """Load configuration from a file"""
    config = VirtstrapConfig.from_file(fixture_path('test.yml'))
    assert isinstance(config, VirtstrapConfig)
Esempio n. 36
0
 def setup(self):
     template_path = fixture_path('templates')
     loaders = [FileSystemLoader(template_path)]
     self.env = TempitaEnvironment(loaders=loaders)
Esempio n. 37
0
def test_file_system_loader():
    loader = FileSystemLoader(fixture_path('templates'))
    fake_env = fake_environment()
    template = loader.get_template('tests/test_template.tmpl', fake_env)
    assert template is not None