Skip to content

Commit

Permalink
switch to py.test style asserts, cleanup param order
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed May 21, 2016
1 parent bebbd88 commit 120106c
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 373 deletions.
12 changes: 6 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def setUp(self):
def test_creates_config_dir_not_exists(self):
"""cli.startup() creates config dir if not exists."""

self.assertFalse(os.path.exists(self.tmp_dir))
assert not os.path.exists(self.tmp_dir)
cli.startup(self.tmp_dir)

self.assertTrue(os.path.exists(self.tmp_dir))
assert os.path.exists(self.tmp_dir)

def tearDown(self):
if os.path.isdir(self.tmp_dir):
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_in_dir_from_config_dir(self):
):
configs_found = config.in_dir(self.tmp_dir)

self.assertEqual(len(configs_found), 2)
assert len(configs_found) == 2

def test_in_dir_from_current_dir(self):
"""config.in_dir() find configs current dir."""
Expand All @@ -85,7 +85,7 @@ def test_ignore_non_configs_from_current_dir(self):
suffix='.json'
):
configs_found = config.in_dir(self.tmp_dir)
self.assertEqual(len(configs_found), 1)
assert len(configs_found) == 1

def test_get_configs_cwd(self):
"""config.in_cwd() find config in shell current working directory."""
Expand All @@ -106,8 +106,8 @@ def test_get_configs_cwd(self):
finally:
os.remove(config1.name)

self.assertEqual(len(configs_found), 1)
self.assertIn('.tmuxp.json', configs_found)
assert len(configs_found) == 1
assert '.tmuxp.json' in configs_found

# clean up
os.chdir(current_dir)
Expand Down
69 changes: 28 additions & 41 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import unittest

import kaptan
import pytest

from tmuxp import config, exc

Expand Down Expand Up @@ -77,7 +78,7 @@ def test_export_json(self):

new_config = kaptan.Kaptan()
new_config_data = new_config.import_config(json_config_file).get()
self.assertDictEqual(sampleconfigdict, new_config_data)
assert sampleconfigdict == new_config_data

def test_export_yaml(self):
yaml_config_file = os.path.join(self.tmp_dir, 'config.yaml')
Expand All @@ -94,7 +95,7 @@ def test_export_yaml(self):

new_config = kaptan.Kaptan()
new_config_data = new_config.import_config(yaml_config_file).get()
self.assertDictEqual(sampleconfigdict, new_config_data)
sampleconfigdict == new_config_data

def test_scan_config(self):
configs = []
Expand All @@ -114,19 +115,17 @@ def test_scan_config(self):
files = 0
if os.path.exists(os.path.join(self.tmp_dir, 'config.json')):
files += 1
self.assertIn(os.path.join(
self.tmp_dir, 'config.json'), configs)
assert os.path.join(self.tmp_dir, 'config.json') in configs

if os.path.exists(os.path.join(self.tmp_dir, 'config.yaml')):
files += 1
self.assertIn(os.path.join(
self.tmp_dir, 'config.yaml'), configs)
assert os.path.join(self.tmp_dir, 'config.yaml') in configs

if os.path.exists(os.path.join(self.tmp_dir, 'config.ini')):
files += 1
self.assertIn(os.path.join(self.tmp_dir, 'config.ini'), configs)
assert os.path.join(self.tmp_dir, 'config.ini') in configs

self.assertEqual(len(configs), files)
assert len(configs) == files


class ExpandTest(TestCase):
Expand Down Expand Up @@ -271,7 +270,7 @@ def test_config(self):
"""Expand shell commands from string to list."""
self.maxDiff = None
test_config = config.expand(self.before_config)
self.assertDictEqual(test_config, self.after_config)
assert test_config == self.after_config

def test_no_window_name(self):
"""Expand shell commands from string to list."""
Expand Down Expand Up @@ -355,10 +354,7 @@ def test_no_window_name(self):
expanded_dict = kaptan.Kaptan(handler='yaml'). \
import_config(expanded_yaml).get()

self.assertDictEqual(
config.expand(unexpanded_dict),
expanded_dict
)
assert config.expand(unexpanded_dict) == expanded_dict


class InlineTest(TestCase):
Expand Down Expand Up @@ -435,7 +431,7 @@ def test_config(self):

self.maxDiff = None
test_config = config.inline(self.before_config)
self.assertDictEqual(test_config, self.after_config)
assert test_config == self.after_config


class InheritanceTest(TestCase):
Expand Down Expand Up @@ -557,7 +553,7 @@ def test_start_directory(self):
# paneconfitem['start_directory'] = session_start_directory

self.maxDiff = None
self.assertDictEqual(config, self.config_after)
assert config == self.config_after


class ShellCommandBeforeTest(TestCase):
Expand Down Expand Up @@ -742,11 +738,11 @@ def test_shell_command_before(self):
test_config = self.config_unexpanded
test_config = config.expand(test_config)

self.assertDictEqual(test_config, self.config_expanded)
assert test_config == self.config_expanded

test_config = config.trickle(test_config)
self.maxDiff = None
self.assertDictEqual(test_config, self.config_after)
assert test_config == self.config_after


class ShellCommandBeforeSession(TestCase):
Expand Down Expand Up @@ -807,12 +803,9 @@ def test_in_session_scope(self):

config.validate_schema(sconfig)

self.assertDictEqual(config.expand(sconfig), sconfig)

self.assertDictEqual(
config.expand(config.trickle(sconfig)),
assert config.expand(sconfig) == sconfig
assert config.expand(config.trickle(sconfig)) == \
self.yaml_to_dict(yaml_final_config)
)

def yaml_to_dict(self, yaml):
return kaptan.Kaptan(handler='yaml').import_config(yaml).get()
Expand Down Expand Up @@ -889,7 +882,7 @@ class TrickleRelativeStartDirectory(TestCase):
def test_shell_command_before(self):

test_config = config.trickle(self.config_expanded)
self.assertDictEqual(test_config, self.config_after)
assert test_config == self.config_after


class ConfigBlankPanes(TestCase):
Expand Down Expand Up @@ -996,10 +989,7 @@ def test_expands_blank(self):
test_config = kaptan.Kaptan().import_config(
self.yaml_config_file).get()

self.assertDictEqual(
config.expand(test_config),
self.expanded_config
)
assert config.expand(test_config) == self.expanded_config


class ConfigConsistency(TestCase):
Expand All @@ -1021,10 +1011,9 @@ def test_no_session_name(self):
sconfig = kaptan.Kaptan(handler='yaml')
sconfig = sconfig.import_config(yaml_config).get()

with self.assertRaisesRegexp(
exc.ConfigError, 'requires "session_name"'
):
with pytest.raises(exc.ConfigError) as excinfo:
config.validate_schema(sconfig)
assert excinfo.matches(r'requires "session_name"')

def test_no_windows(self):
yaml_config = """
Expand All @@ -1034,8 +1023,9 @@ def test_no_windows(self):
sconfig = kaptan.Kaptan(handler='yaml')
sconfig = sconfig.import_config(yaml_config).get()

with self.assertRaisesRegexp(exc.ConfigError, 'list of "windows"'):
with pytest.raises(exc.ConfigError) as excinfo:
config.validate_schema(sconfig)
assert excinfo.match(r'list of "windows"')

def test_no_window_name(self):
yaml_config = """
Expand All @@ -1055,8 +1045,9 @@ def test_no_window_name(self):
sconfig = kaptan.Kaptan(handler='yaml')
sconfig = sconfig.import_config(yaml_config).get()

with self.assertRaisesRegexp(exc.ConfigError, 'missing "window_name"'):
with pytest.raises(exc.ConfigError) as excinfo:
config.validate_schema(sconfig)
assert excinfo.matches('missing "window_name"')


class ConfigExpandEnvironmentVariables(TestCase, unittest.TestCase):
Expand Down Expand Up @@ -1089,13 +1080,9 @@ def test_replaces_start_directory(self):
with EnvironmentVarGuard() as env:
env.set(env_key, env_value)
sconfig = config.expand(sconfig)
self.assertEqual("%s/test" % env_value, sconfig['start_directory'])
self.assertIn(
"%s/test2" % env_value, sconfig['shell_command_before']
)
self.assertEqual("%s/test3" % env_value, sconfig['before_script'])
self.assertEqual("hi - %s" % env_value, sconfig['session_name'])
self.assertEqual(
"logging @ %s" % env_value,
assert "%s/test" % env_value == sconfig['start_directory']
assert "%s/test2" % env_value in sconfig['shell_command_before']
assert "%s/test3" % env_value == sconfig['before_script']
assert "hi - %s" % env_value == sconfig['session_name']
assert "logging @ %s" % env_value == \
sconfig['windows'][1]['window_name']
)
70 changes: 22 additions & 48 deletions tests/test_config_teamocil.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ def test_config_to_dict(self):
configparser = kaptan.Kaptan(handler='yaml')
test_config = configparser.import_config(self.teamocil_yaml)
yaml_to_dict = test_config.get()
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)

self.assertDictEqual(
config.import_teamocil(self.teamocil_dict),
self.tmuxp_dict
)
assert yaml_to_dict == self.teamocil_dict
assert config.import_teamocil(self.teamocil_dict) == self.tmuxp_dict

config.validate_schema(
config.import_teamocil(
Expand Down Expand Up @@ -145,12 +141,9 @@ def test_config_to_dict(self):
configparser = kaptan.Kaptan(handler='yaml')
test_config = configparser.import_config(self.teamocil_yaml)
yaml_to_dict = test_config.get()
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
assert yaml_to_dict == self.teamocil_dict

self.assertDictEqual(
config.import_teamocil(self.teamocil_dict),
self.tmuxp_dict
)
assert config.import_teamocil(self.teamocil_dict) == self.tmuxp_dict

config.validate_schema(
config.import_teamocil(
Expand Down Expand Up @@ -236,12 +229,9 @@ def test_config_to_dict(self):
configparser = kaptan.Kaptan(handler='yaml')
test_config = configparser.import_config(self.teamocil_yaml)
yaml_to_dict = test_config.get()
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
assert yaml_to_dict == self.teamocil_dict

self.assertDictEqual(
config.import_teamocil(self.teamocil_dict),
self.tmuxp_dict
)
assert config.import_teamocil(self.teamocil_dict) == self.tmuxp_dict

config.validate_schema(
config.import_teamocil(
Expand Down Expand Up @@ -290,12 +280,9 @@ def test_config_to_dict(self):
configparser = kaptan.Kaptan(handler='yaml')
test_config = configparser.import_config(self.teamocil_yaml)
yaml_to_dict = test_config.get()
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
assert yaml_to_dict == self.teamocil_dict

self.assertDictEqual(
config.import_teamocil(self.teamocil_dict),
self.tmuxp_dict
)
assert config.import_teamocil(self.teamocil_dict) == self.tmuxp_dict

config.validate_schema(
config.import_teamocil(
Expand Down Expand Up @@ -669,59 +656,46 @@ def test_config_to_dict(self):
configparser = kaptan.Kaptan(handler='yaml')
test_config = configparser.import_config(self.teamocil_yaml)
yaml_to_dict = test_config.get()
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
assert yaml_to_dict == self.teamocil_dict

self.assertDictEqual(
config.import_teamocil(
self.teamocil_dict['two-windows'],
),
assert config.import_teamocil(self.teamocil_dict['two-windows']) == \
self.two_windows
)

config.validate_schema(
config.import_teamocil(
self.teamocil_dict['two-windows']
)
)

self.assertDictEqual(
config.import_teamocil(
self.teamocil_dict['two-windows-with-filters'],
),
self.two_windows_with_filters
)
assert config.import_teamocil(
self.teamocil_dict['two-windows-with-filters'],
) == self.two_windows_with_filters

config.validate_schema(
config.import_teamocil(
self.teamocil_dict['two-windows-with-filters']
)
)

self.assertDictEqual(
config.import_teamocil(
self.teamocil_dict['two-windows-with-custom-command-options'],
),
self.two_windows_with_custom_command_options
)
assert config.import_teamocil(
self.teamocil_dict['two-windows-with-custom-command-options'],
) == self.two_windows_with_custom_command_options

config.validate_schema(
config.import_teamocil(
self.teamocil_dict['two-windows-with-custom-command-options']
)
)

self.assertDictEqual(
config.import_teamocil(
self.teamocil_dict['three-windows-within-a-session'],
),
self.three_windows_within_a_session
)
assert config.import_teamocil(
self.teamocil_dict['three-windows-within-a-session'],
) == self.three_windows_within_a_session

config.validate_schema(
config.import_teamocil(
self.teamocil_dict['three-windows-within-a-session']
)
)

""" this configuration contains multiple sessions in a single file.
tmuxp can split them into files, proceed?
"""
# this configuration contains multiple sessions in a single file.
# tmuxp can split them into files, proceed?
Loading

0 comments on commit 120106c

Please sign in to comment.