Skip to content

Commit 7559cfa

Browse files
committed
Updated tests to work with new GMT path finding mechanism
1 parent 57b8c52 commit 7559cfa

File tree

3 files changed

+18
-38
lines changed

3 files changed

+18
-38
lines changed

drupal/usage_scenario.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
name: Drupal Data Puppeteer Scenario
33
author: Marco Villegas <marco.villegas@adaptagency.com>
4-
version: 2
54
description: Drupal sample with pre-populated DB (pages and plugins) where a simple Puppeteer flow is executed
65

76
compose-file: !include compose.yml
@@ -24,7 +23,7 @@ services:
2423
gcb-puppeteer:
2524
image: greencoding/puppeteer-chrome
2625
setup-commands:
27-
- cp /tmp/repo/puppeteer-flow.js /var/www/puppeteer-flow.js
26+
- cp /tmp/repo/drupal/puppeteer-flow.js /var/www/puppeteer-flow.js
2827
networks:
2928
- drupal-mariadb-network
3029

test/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
GlobalConfig().override_config(config_name='test-config.yml')
1010

1111
def pytest_addoption(parser):
12-
parser.addoption("--name", action="store", default="stress")
12+
parser.addoption("--name", action="store")
1313

1414
def pytest_generate_tests(metafunc):
1515
# This is called for every test. Only get/set command line arguments

test/smoke_test.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import yaml
55

66
# These tests assumes the green-metrics-tool directory lives side by side with the examples-repository
7-
current_dir = os.path.dirname(os.path.abspath(__file__))
8-
sys.path.append(f"{current_dir}/../../green-metrics-tool")
9-
sys.path.append(f"{current_dir}/../../green-metrics-tool/tools")
10-
sys.path.append(f"{current_dir}/../../green-metrics-tool/lib")
7+
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
8+
ROOT_DIR = os.path.abspath(f"{CURRENT_DIR}/../")
9+
sys.path.append(f"{CURRENT_DIR}/../../green-metrics-tool")
10+
sys.path.append(f"{CURRENT_DIR}/../../green-metrics-tool/tools")
11+
sys.path.append(f"{CURRENT_DIR}/../../green-metrics-tool/lib")
1112

1213
from runner import Runner
1314
from global_config import GlobalConfig
@@ -20,25 +21,25 @@
2021

2122
def example_directories():
2223
example_dirs = []
23-
root = f"{current_dir}/../"
24-
25-
for path, directories, files in os.walk(root):
24+
for path, directories, files in os.walk(ROOT_DIR):
2625
dirname = path.split(os.path.sep)[-1]
27-
if path == root or '.scantest' in files:
26+
if path == ROOT_DIR or '.scantest' in files:
2827
continue
2928
if '.skiptest' in files or dirname.startswith("."):
3029
directories.clear()
3130
continue
32-
example_dirs.append(os.path.abspath(path))
31+
print(os.path.abspath(path))
32+
repo_path = os.path.abspath(path)
33+
repo_path_rel = repo_path[len(ROOT_DIR)+1:]
34+
example_dirs.append(repo_path_rel)
3335
directories.clear()
34-
3536
return example_dirs
3637

37-
def run_test_on_directory(directory, capsys, skip_unsafe=False):
38+
def run_test_on_directory(directory, capsys):
3839
name = f"test_{utils.randomword(12)}"
3940

4041
# Run the application
41-
runner = Runner(name=name, uri=directory, uri_type="folder", dev_no_build=True, skip_unsafe=skip_unsafe, skip_system_checks=True)
42+
runner = Runner(name=name, uri=ROOT_DIR, filename=f"{directory}/usage_scenario.yml", uri_type="folder", dev_no_build=True, dev_no_sleeps=True, skip_unsafe=True, skip_system_checks=True)
4243
runner.run()
4344

4445
# Capture Std.Out and Std.Err and make Assertions
@@ -99,31 +100,11 @@ def recursive_lookup(k, d):
99100

100101
Loader.add_constructor('!include', Loader.include)
101102

102-
def check_for_ports(directory):
103-
if os.path.exists(f"{directory}/usage_scenario.yml"):
104-
with open(f"{directory}/usage_scenario.yml", encoding='utf8') as f:
105-
usage_scenario = yaml.load(f, Loader=Loader)
106-
if 'services' in usage_scenario:
107-
for service in usage_scenario['services']:
108-
if 'ports' in usage_scenario['services'][service]:
109-
return True
110-
111-
if os.path.exists(f"{directory}/compose.yml"):
112-
with open(f"{directory}/compose.yml", encoding='utf8') as f:
113-
compose_yml = yaml.load(f, Loader=Loader)
114-
if 'services' in compose_yml:
115-
for service in compose_yml['services']:
116-
if 'ports' in compose_yml['services'][service]:
117-
return True
118-
return False
119-
120103
@pytest.mark.parametrize("example_directory", example_directories())
121104
def test_all_directories(example_directory, capsys):
122-
skip_unsafe = check_for_ports(example_directory)
123-
run_test_on_directory(example_directory, capsys, skip_unsafe=skip_unsafe)
105+
run_test_on_directory(example_directory, capsys)
124106

107+
# Trigger a single test by supplying --name "my_directory" for this one
125108
def test_a_directory(name, capsys):
126-
uri = os.path.abspath(f"{current_dir}/../{name}")
127-
skip_unsafe = check_for_ports(uri)
128-
run_test_on_directory(uri, capsys, skip_unsafe=skip_unsafe)
109+
run_test_on_directory(name, capsys)
129110

0 commit comments

Comments
 (0)