Skip to content

Commit

Permalink
Allow dash and underscore in project name.
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Nottale <matthieu.nottale@docker.com>
  • Loading branch information
Matthieu Nottale committed Mar 15, 2018
1 parent 4e0fdd7 commit 5fe3aff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion compose/cli/command.py
Expand Up @@ -127,7 +127,7 @@ def get_project(project_dir, config_path=None, project_name=None, verbose=False,

def get_project_name(working_dir, project_name=None, environment=None):
def normalize_name(name):
return re.sub(r'[^a-z0-9]', '', name.lower())
return re.sub(r'[^-_a-z0-9]', '', name.lower())

if not environment:
environment = Environment.from_env_file(working_dir)
Expand Down
66 changes: 33 additions & 33 deletions tests/acceptance/cli_test.py
Expand Up @@ -491,16 +491,16 @@ def test_config_compatibility_mode(self):
def test_ps(self):
self.project.get_service('simple').create_container()
result = self.dispatch(['ps'])
assert 'simplecomposefile_simple_1' in result.stdout
assert 'simple-composefile_simple_1' in result.stdout

def test_ps_default_composefile(self):
self.base_dir = 'tests/fixtures/multiple-composefiles'
self.dispatch(['up', '-d'])
result = self.dispatch(['ps'])

assert 'multiplecomposefiles_simple_1' in result.stdout
assert 'multiplecomposefiles_another_1' in result.stdout
assert 'multiplecomposefiles_yetanother_1' not in result.stdout
assert 'multiple-composefiles_simple_1' in result.stdout
assert 'multiple-composefiles_another_1' in result.stdout
assert 'multiple-composefiles_yetanother_1' not in result.stdout

def test_ps_alternate_composefile(self):
config_path = os.path.abspath(
Expand All @@ -511,9 +511,9 @@ def test_ps_alternate_composefile(self):
self.dispatch(['-f', 'compose2.yml', 'up', '-d'])
result = self.dispatch(['-f', 'compose2.yml', 'ps'])

assert 'multiplecomposefiles_simple_1' not in result.stdout
assert 'multiplecomposefiles_another_1' not in result.stdout
assert 'multiplecomposefiles_yetanother_1' in result.stdout
assert 'multiple-composefiles_simple_1' not in result.stdout
assert 'multiple-composefiles_another_1' not in result.stdout
assert 'multiple-composefiles_yetanother_1' in result.stdout

def test_ps_services_filter_option(self):
self.base_dir = 'tests/fixtures/ps-services-filter'
Expand Down Expand Up @@ -902,18 +902,18 @@ def test_down(self):
assert len(self.project.containers(one_off=OneOffFilter.only, stopped=True)) == 2

result = self.dispatch(['down', '--rmi=local', '--volumes'])
assert 'Stopping v2full_web_1' in result.stderr
assert 'Stopping v2full_other_1' in result.stderr
assert 'Stopping v2full_web_run_2' in result.stderr
assert 'Removing v2full_web_1' in result.stderr
assert 'Removing v2full_other_1' in result.stderr
assert 'Removing v2full_web_run_1' in result.stderr
assert 'Removing v2full_web_run_2' in result.stderr
assert 'Removing volume v2full_data' in result.stderr
assert 'Removing image v2full_web' in result.stderr
assert 'Stopping v2-full_web_1' in result.stderr
assert 'Stopping v2-full_other_1' in result.stderr
assert 'Stopping v2-full_web_run_2' in result.stderr
assert 'Removing v2-full_web_1' in result.stderr
assert 'Removing v2-full_other_1' in result.stderr
assert 'Removing v2-full_web_run_1' in result.stderr
assert 'Removing v2-full_web_run_2' in result.stderr
assert 'Removing volume v2-full_data' in result.stderr
assert 'Removing image v2-full_web' in result.stderr
assert 'Removing image busybox' not in result.stderr
assert 'Removing network v2full_default' in result.stderr
assert 'Removing network v2full_front' in result.stderr
assert 'Removing network v2-full_default' in result.stderr
assert 'Removing network v2-full_front' in result.stderr

def test_down_timeout(self):
self.dispatch(['up', '-d'], None)
Expand Down Expand Up @@ -2000,39 +2000,39 @@ def test_run_handles_sigint(self):
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
'simple-composefile_simple_run_1',
'running'))

os.kill(proc.pid, signal.SIGINT)
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
'simple-composefile_simple_run_1',
'exited'))

def test_run_handles_sigterm(self):
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
'simple-composefile_simple_run_1',
'running'))

os.kill(proc.pid, signal.SIGTERM)
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
'simple-composefile_simple_run_1',
'exited'))

def test_run_handles_sighup(self):
proc = start_process(self.base_dir, ['run', '-T', 'simple', 'top'])
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
'simple-composefile_simple_run_1',
'running'))

os.kill(proc.pid, signal.SIGHUP)
wait_on_condition(ContainerStateCondition(
self.project.client,
'simplecomposefile_simple_run_1',
'simple-composefile_simple_run_1',
'exited'))

@mock.patch.dict(os.environ)
Expand Down Expand Up @@ -2234,7 +2234,7 @@ def test_logs_follow_logs_from_new_containers(self):
self.dispatch(['up', '-d', 'another'])
wait_on_condition(ContainerStateCondition(
self.project.client,
'logscomposefile_another_1',
'logs-composefile_another_1',
'exited'))

self.dispatch(['kill', 'simple'])
Expand All @@ -2243,8 +2243,8 @@ def test_logs_follow_logs_from_new_containers(self):

assert 'hello' in result.stdout
assert 'test' in result.stdout
assert 'logscomposefile_another_1 exited with code 0' in result.stdout
assert 'logscomposefile_simple_1 exited with code 137' in result.stdout
assert 'logs-composefile_another_1 exited with code 0' in result.stdout
assert 'logs-composefile_simple_1 exited with code 137' in result.stdout

def test_logs_default(self):
self.base_dir = 'tests/fixtures/logs-composefile'
Expand Down Expand Up @@ -2491,7 +2491,7 @@ def has_timestamp(string):

container, = self.project.containers()
expected_template = ' container {} {}'
expected_meta_info = ['image=busybox:latest', 'name=simplecomposefile_simple_1']
expected_meta_info = ['image=busybox:latest', 'name=simple-composefile_simple_1']

assert expected_template.format('create', container.id) in lines[0]
assert expected_template.format('start', container.id) in lines[1]
Expand Down Expand Up @@ -2611,22 +2611,22 @@ def test_forward_exitval(self):

result = wait_on_process(proc, returncode=1)

assert 'exitcodefrom_another_1 exited with code 1' in result.stdout
assert 'exit-code-from_another_1 exited with code 1' in result.stdout

def test_images(self):
self.project.get_service('simple').create_container()
result = self.dispatch(['images'])
assert 'busybox' in result.stdout
assert 'simplecomposefile_simple_1' in result.stdout
assert 'simple-composefile_simple_1' in result.stdout

def test_images_default_composefile(self):
self.base_dir = 'tests/fixtures/multiple-composefiles'
self.dispatch(['up', '-d'])
result = self.dispatch(['images'])

assert 'busybox' in result.stdout
assert 'multiplecomposefiles_another_1' in result.stdout
assert 'multiplecomposefiles_simple_1' in result.stdout
assert 'multiple-composefiles_another_1' in result.stdout
assert 'multiple-composefiles_simple_1' in result.stdout

@mock.patch.dict(os.environ)
def test_images_tagless_image(self):
Expand All @@ -2646,7 +2646,7 @@ def test_images_tagless_image(self):
self.project.get_service('foo').create_container()
result = self.dispatch(['images'])
assert '<none>' in result.stdout
assert 'taglessimage_foo_1' in result.stdout
assert 'tagless-image_foo_1' in result.stdout

def test_up_with_override_yaml(self):
self.base_dir = 'tests/fixtures/override-yaml-files'
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/cli_test.py
Expand Up @@ -30,12 +30,12 @@ def test_default_project_name(self):
test_dir = py._path.local.LocalPath('tests/fixtures/simple-composefile')
with test_dir.as_cwd():
project_name = get_project_name('.')
assert 'simplecomposefile' == project_name
assert 'simple-composefile' == project_name

def test_project_name_with_explicit_base_dir(self):
base_dir = 'tests/fixtures/simple-composefile'
project_name = get_project_name(base_dir)
assert 'simplecomposefile' == project_name
assert 'simple-composefile' == project_name

def test_project_name_with_explicit_uppercase_base_dir(self):
base_dir = 'tests/fixtures/UpperCaseDir'
Expand All @@ -45,7 +45,7 @@ def test_project_name_with_explicit_uppercase_base_dir(self):
def test_project_name_with_explicit_project_name(self):
name = 'explicit-project-name'
project_name = get_project_name(None, project_name=name)
assert 'explicitprojectname' == project_name
assert 'explicit-project-name' == project_name

@mock.patch.dict(os.environ)
def test_project_name_from_environment_new_var(self):
Expand All @@ -59,7 +59,7 @@ def test_project_name_with_empty_environment_var(self):
with mock.patch.dict(os.environ):
os.environ['COMPOSE_PROJECT_NAME'] = ''
project_name = get_project_name(base_dir)
assert 'simplecomposefile' == project_name
assert 'simple-composefile' == project_name

@mock.patch.dict(os.environ)
def test_project_name_with_environment_file(self):
Expand All @@ -80,7 +80,7 @@ def test_project_name_with_environment_file(self):
def test_get_project(self):
base_dir = 'tests/fixtures/longer-filename-composefile'
project = get_project(base_dir)
assert project.name == 'longerfilenamecomposefile'
assert project.name == 'longer-filename-composefile'
assert project.client
assert project.services

Expand Down

0 comments on commit 5fe3aff

Please sign in to comment.