Browse Source

Remove or document code duplicated between play2-java and scala

Rich Dougherty 11 years ago
parent
commit
b3ad9429d8

+ 4 - 4
frameworks/Java/play2-java/README.md

@@ -1,5 +1,5 @@
-# play2 framework tests
+# play2-java framework tests
 
-1. Add new test applications in subdirectories named either `play2-language` or `play2-language-orm`.
-2. Edit `generate_config.py` and add configuration for the new test applications.
-3. Run `python generate_config.py` to generate a new `benchmark_config` file and to generate a `setup_play2_*.py` file for your test application.
+1. Add new test applications in subdirectories named either `play2-java` or `play2-java-orm`.
+2. Edit `frameworks/Java/play2-java/generate_config.py` and add configuration for the new test applications.
+3. Run `python frameworks/Java/play2-java/generate_config.py` to generate a new `benchmark_config` file and to generate a `setup_*.py` file for your test application.

+ 43 - 25
frameworks/Java/play2-java/generate_config.py

@@ -1,17 +1,17 @@
 #!/usr/bin/env python
 
-import collections, json, textwrap
+import collections, json, os, textwrap
 
 # This script generates the benchmark_config and setup_*.py files.
 # To add new tests, modify the `configurations` and `test_urls` tables.
 
 # Each line corresponds to a test application.
-# Format is: (language, orm, (os, ...), (test, ...))
+# Format is: (language, orm, (opsys, ...), (test, ...))
 # See the dir_name logic below to see the directory name for each test application.
 configurations = [
   ('Java',  None,    ['Linux'],            ['json']),
-  ('Scala', None,    ['Linux'],            ['json']),
   ('Java',  'Ebean', ['Linux'],            ['db', 'query']),
+  ('Scala', None,    ['Linux'],            ['json']),
   ('Scala', 'Anorm', ['Linux', 'Windows'], ['db', 'query', 'fortune', 'update']),
 ]
 
@@ -24,24 +24,47 @@ test_urls = {
   'update': '/update?queries=',
 }
 
-tests_config_json = collections.OrderedDict()
+langs = {
+  'Java': ['Java', 'play2-java'],
+  'Scala': ['Scala', 'play2-scala']
+}
+def pathForLang(lang):
+  return os.path.join(frameworksPath(), *langs[lang])
+def frameworksPath():
+  'Get the absolute path of ROOT/frameworks'
+  return os.path.abspath(os.path.join(__file__, '..', '..', '..'))
+
+lang_test_configs = {}
+for lang, _ in langs.iteritems():
+  lang_test_configs[lang] = collections.OrderedDict()
 
-for lang, orm, oses, tests in configurations:
+for lang, orm, opsyses, tests in configurations:
   dir_name = 'play2-' + lang.lower() + (('-'+orm.lower()) if orm else '')
-  print 'Generating tests for test application '+dir_name
   setup_name = 'setup_' + lang.lower() + (('_'+orm.lower()) if orm else '')
-  for os in oses:
-    if len(oses) == 1:
+
+  setup_path = os.path.join(pathForLang(lang), setup_name+'.py')
+  print 'Generating', setup_path
+  with open(setup_path, 'w') as f:
+    f.write(textwrap.dedent("""
+      # This file was generated by frameworks/Java/play2-java/generate_config.py.
+      # Do not edit this file directly, use the script to regenerate.
+      from .setup_common import make_setup_for_dir
+
+      make_setup_for_dir(globals(), '"""+dir_name+"""')
+    """))
+
+  for opsys in opsyses:
+    if len(opsyses) == 1:
       test_name = lang.lower() + (('-'+orm.lower()) if orm else '')
     else:
-      test_name = lang.lower() + (('-'+orm.lower()) if orm else '') + '-'+os.lower()
+      test_name = lang.lower() + (('-'+orm.lower()) if orm else '') + '-'+opsys.lower()
     test_config_json = collections.OrderedDict([
       ('display_name', 'play2-'+test_name),
       ('setup_file', setup_name),
       ('framework', 'play2'),
       ('language', lang),
       ('orm', orm if orm else 'Raw'),
-      ('os', os),
+      ('os', opsys),
       ('database', 'MySQL' if orm else 'None'),
       ('approach', 'Realistic'),
       ('classification', 'Fullstack'),
@@ -54,19 +77,14 @@ for lang, orm, oses, tests in configurations:
     ])
     for test in tests:
       test_config_json[test+'_url'] = test_urls[test]
-      tests_config_json[test_name] = test_config_json
-    with open(setup_name+'.py', 'w') as f:
-      f.write(textwrap.dedent("""
-        # This file was generated by generate_config.py.
-        # Do not edit this file directly.
-        from .setup_common import make_setup_for_dir
-
-        make_setup_for_dir(globals(), '"""+dir_name+"""')
-      """))
+      lang_test_configs[lang][test_name] = test_config_json
 
-with open('benchmark_config', 'w') as f:
-  json_str = json.dumps({
-    'framework': 'play2',
-    'tests': [tests_config_json]
-  }, indent=2)
-  f.write(json_str)
+for lang, _ in langs.iteritems():
+  benchmark_config_path = os.path.join(pathForLang(lang), 'benchmark_config')
+  print 'Generating', benchmark_config_path
+  with open(benchmark_config_path, 'w') as f:
+    json_str = json.dumps({
+      'framework': 'play2',
+      'tests': [lang_test_configs[lang]]
+    }, indent=2)
+    f.write(json_str)

+ 3 - 0
frameworks/Java/play2-java/setup_common.py

@@ -1,3 +1,6 @@
+# This file and frameworks/Scala/play2-java/setup_common.py are
+# duplicates and should be kept in sync.
+
 import os, setup_util, signal, subprocess
 
 # Create start and stop functions for the Play project with the given dir

+ 2 - 2
frameworks/Java/play2-java/setup_java.py

@@ -1,6 +1,6 @@
 
-# This file was generated by generate_config.py.
-# Do not edit this file directly.
+# This file was generated by frameworks/Java/play2-java/generate_config.py.
+# Do not edit this file directly, use the script to regenerate.
 from .setup_common import make_setup_for_dir
 
 make_setup_for_dir(globals(), 'play2-java')

+ 2 - 2
frameworks/Java/play2-java/setup_java_ebean.py

@@ -1,6 +1,6 @@
 
-# This file was generated by generate_config.py.
-# Do not edit this file directly.
+# This file was generated by frameworks/Java/play2-java/generate_config.py.
+# Do not edit this file directly, use the script to regenerate.
 from .setup_common import make_setup_for_dir
 
 make_setup_for_dir(globals(), 'play2-java-ebean')

+ 4 - 4
frameworks/Scala/play2-scala/README.md

@@ -1,5 +1,5 @@
-# play2 framework tests
+# play2-scala framework tests
 
-1. Add new test applications in subdirectories named either `play2-language` or `play2-language-orm`.
-2. Edit `generate_config.py` and add configuration for the new test applications.
-3. Run `python generate_config.py` to generate a new `benchmark_config` file and to generate a `setup_play2_*.py` file for your test application.
+1. Add new test applications in subdirectories named either `play2-scala` or `play2-scala-orm`.
+2. Edit `frameworks/Java/play2-java/generate_config.py` and add configuration for the new test applications.
+3. Run `python frameworks/Java/play2-java/generate_config.py` to generate a new `benchmark_config` file and to generate a `setup_*.py` file for your test application.

+ 0 - 72
frameworks/Scala/play2-scala/generate_config.py

@@ -1,72 +0,0 @@
-#!/usr/bin/env python
-
-import collections, json, textwrap
-
-# This script generates the benchmark_config and setup_*.py files.
-# To add new tests, modify the `configurations` and `test_urls` tables.
-
-# Each line corresponds to a test application.
-# Format is: (language, orm, (os, ...), (test, ...))
-# See the dir_name logic below to see the directory name for each test application.
-configurations = [
-  ('Java',  None,    ['Linux'],            ['json']),
-  ('Scala', None,    ['Linux'],            ['json']),
-  ('Java',  'Ebean', ['Linux'],            ['db', 'query']),
-  ('Scala', 'Anorm', ['Linux', 'Windows'], ['db', 'query', 'fortune', 'update']),
-]
-
-# All play2 test applications must use the same URLs.
-test_urls = {
-  'json': '/json',
-  'db': '/db',
-  'query': '/queries?queries=',
-  'fortune': '/fortunes',
-  'update': '/update?queries=',
-}
-
-tests_config_json = collections.OrderedDict()
-
-for lang, orm, oses, tests in configurations:
-  dir_name = 'play2-' + lang.lower() + (('-'+orm.lower()) if orm else '')
-  print 'Generating tests for test application '+dir_name
-  setup_name = 'setup_' + lang.lower() + (('_'+orm.lower()) if orm else '')
-  for os in oses:
-    if len(oses) == 1:
-      test_name = lang.lower() + (('-'+orm.lower()) if orm else '')
-    else:
-      test_name = lang.lower() + (('-'+orm.lower()) if orm else '') + '-'+os.lower()
-    test_config_json = collections.OrderedDict([
-      ('display_name', 'play2-'+test_name),
-      ('setup_file', setup_name),
-      ('framework', 'play2'),
-      ('language', lang),
-      ('orm', orm if orm else 'Raw'),
-      ('os', os),
-      ('database', 'MySQL' if orm else 'None'),
-      ('approach', 'Realistic'),
-      ('classification', 'Fullstack'),
-      ('platform', 'Netty'),
-      ('webserver', 'None'),
-      ('database_os', 'Linux'),
-      ('notes', ''),
-      ('versus', 'netty'),
-      ('port', '9000'),
-    ])
-    for test in tests:
-      test_config_json[test+'_url'] = test_urls[test]
-      tests_config_json[test_name] = test_config_json
-    with open(setup_name+'.py', 'w') as f:
-      f.write(textwrap.dedent("""
-        # This file was generated by generate_config.py.
-        # Do not edit this file directly.
-        from .setup_common import make_setup_for_dir
-
-        make_setup_for_dir(globals(), '"""+dir_name+"""')
-      """))
-
-with open('benchmark_config', 'w') as f:
-  json_str = json.dumps({
-    'framework': 'play2',
-    'tests': [tests_config_json]
-  }, indent=2)
-  f.write(json_str)

+ 3 - 0
frameworks/Scala/play2-scala/setup_common.py

@@ -1,3 +1,6 @@
+# This file and frameworks/Java/play2-java/setup_common.py are
+# duplicates and should be kept in sync.
+
 import os, setup_util, signal, subprocess
 
 # Create start and stop functions for the Play project with the given dir

+ 2 - 2
frameworks/Scala/play2-scala/setup_scala.py

@@ -1,6 +1,6 @@
 
-# This file was generated by generate_config.py.
-# Do not edit this file directly.
+# This file was generated by frameworks/Java/play2-java/generate_config.py.
+# Do not edit this file directly, use the script to regenerate.
 from .setup_common import make_setup_for_dir
 
 make_setup_for_dir(globals(), 'play2-scala')

+ 2 - 2
frameworks/Scala/play2-scala/setup_scala_anorm.py

@@ -1,6 +1,6 @@
 
-# This file was generated by generate_config.py.
-# Do not edit this file directly.
+# This file was generated by frameworks/Java/play2-java/generate_config.py.
+# Do not edit this file directly, use the script to regenerate.
 from .setup_common import make_setup_for_dir
 
 make_setup_for_dir(globals(), 'play2-scala-anorm')