Skip to content

Commit

Permalink
Auto merge of #10855 - servo:unit, r=nox
Browse files Browse the repository at this point in the history
Make css-properties.json checking a proper unit test.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10855)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Apr 28, 2016
2 parents 224bcd7 + a3b2712 commit 55d14ff
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
1 change: 1 addition & 0 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions python/servo/testing_commands.py
Expand Up @@ -14,8 +14,6 @@
import sys
import os
import os.path as path
import subprocess
import json
from collections import OrderedDict
from time import time

Expand Down Expand Up @@ -141,8 +139,6 @@ def test(self, params, render_mode=DEFAULT_RENDER_MODE, release=False, faster=Fa
@CommandArgument('test_name', nargs=argparse.REMAINDER,
help="Only run tests that match this pattern or file path")
def test_unit(self, test_name=None, package=None):
check_css_properties_json(self.context.topdir)

if test_name is None:
test_name = []

Expand Down Expand Up @@ -657,23 +653,3 @@ def run_create(self, **kwargs):

if editor:
proc.wait()


def check_css_properties_json(topdir):
print("Testing generation of css-properties.json...")
filename = path.join(topdir, "target", "doc", "servo", "css-properties.json")

if path.exists(filename):
os.remove(filename)
subprocess.check_call([
sys.executable,
path.join(topdir, "components", "style", "properties", "build.py"),
"servo",
"html",
])
properties = json.load(open(filename))

assert len(properties) >= 100
assert "margin-top" in properties
assert "margin" in properties
print("OK")
1 change: 1 addition & 0 deletions tests/unit/style/Cargo.toml
Expand Up @@ -20,3 +20,4 @@ euclid = {version = "0.6.4", features = ["plugins"]}
selectors = {version = "0.5", features = ["heap_size"]}
string_cache = {version = "0.2.12", features = ["heap_size"]}
url = {version = "1.0.0", features = ["heap_size"]}
rustc-serialize = "0.3"
2 changes: 2 additions & 0 deletions tests/unit/style/lib.rs
Expand Up @@ -10,6 +10,7 @@ extern crate app_units;
extern crate cssparser;
extern crate euclid;
extern crate msg;
extern crate rustc_serialize;
extern crate selectors;
#[macro_use(atom, ns)] extern crate string_cache;
extern crate style;
Expand All @@ -20,6 +21,7 @@ extern crate util;
#[cfg(test)] mod attr;
#[cfg(test)] mod logical_geometry;
#[cfg(test)] mod media_queries;
#[cfg(test)] mod properties;
#[cfg(test)] mod stylesheets;
#[cfg(test)] mod viewport;

Expand Down
53 changes: 53 additions & 0 deletions tests/unit/style/properties.rs
@@ -0,0 +1,53 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use rustc_serialize::json::Json;
use std::env;
use std::fs::{File, remove_file};
use std::path::Path;
use std::process::Command;

#[test]
fn properties_list_json() {
let top = Path::new(file!()).parent().unwrap().join("..").join("..").join("..");
let json = top.join("target").join("doc").join("servo").join("css-properties.json");
if json.exists() {
remove_file(&json).unwrap()
}
let python = env::var("PYTHON").ok().unwrap_or_else(find_python);
let script = top.join("components").join("style").join("properties").join("build.py");
let status = Command::new(python)
.arg(&script)
.arg("servo")
.arg("html")
.status()
.unwrap();
assert!(status.success());
let properties = Json::from_reader(&mut File::open(json).unwrap()).unwrap();
assert!(properties.as_object().unwrap().len() > 100);
assert!(properties.find("margin").is_some());
assert!(properties.find("margin-top").is_some());
}

#[cfg(windows)]
fn find_python() -> String {
if Command::new("python27.exe").arg("--version").output().is_ok() {
return "python27.exe".to_owned();
}

if Command::new("python.exe").arg("--version").output().is_ok() {
return "python.exe".to_owned();
}

panic!("Can't find python (tried python27.exe and python.exe)! Try fixing PATH or setting the PYTHON env var");
}

#[cfg(not(windows))]
fn find_python() -> String {
if Command::new("python2.7").arg("--version").output().unwrap().status.success() {
"python2.7"
} else {
"python"
}.to_owned()
}

0 comments on commit 55d14ff

Please sign in to comment.